mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-30 19:34:37 +00:00
Fix new clippy lints (#2036)
## Issue Addressed NA ## Proposed Changes Fixes new clippy lints in the whole project (mainly [manual_strip](https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip) and [unnecessary_lazy_evaluations](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations)). Furthermore, removes `to_string()` calls on literals when used with the `?`-operator.
This commit is contained in:
@@ -648,7 +648,7 @@ impl<T: BeaconChainTypes> VerifiedUnaggregatedAttestation<T> {
|
||||
let validator_index = *indexed_attestation
|
||||
.attesting_indices
|
||||
.first()
|
||||
.ok_or_else(|| Error::NotExactlyOneAggregationBitSet(0))?;
|
||||
.ok_or(Error::NotExactlyOneAggregationBitSet(0))?;
|
||||
|
||||
/*
|
||||
* The attestation is the first valid attestation received for the participating validator
|
||||
@@ -838,7 +838,7 @@ pub fn verify_propagation_slot_range<T: BeaconChainTypes>(
|
||||
let latest_permissible_slot = chain
|
||||
.slot_clock
|
||||
.now_with_future_tolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY)
|
||||
.ok_or_else(|| BeaconChainError::UnableToReadSlot)?;
|
||||
.ok_or(BeaconChainError::UnableToReadSlot)?;
|
||||
if attestation_slot > latest_permissible_slot {
|
||||
return Err(Error::FutureSlot {
|
||||
attestation_slot,
|
||||
@@ -850,7 +850,7 @@ pub fn verify_propagation_slot_range<T: BeaconChainTypes>(
|
||||
let earliest_permissible_slot = chain
|
||||
.slot_clock
|
||||
.now_with_past_tolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY)
|
||||
.ok_or_else(|| BeaconChainError::UnableToReadSlot)?
|
||||
.ok_or(BeaconChainError::UnableToReadSlot)?
|
||||
- T::EthSpec::slots_per_epoch();
|
||||
if attestation_slot < earliest_permissible_slot {
|
||||
return Err(Error::PastSlot {
|
||||
@@ -873,12 +873,12 @@ pub fn verify_attestation_signature<T: BeaconChainTypes>(
|
||||
let pubkey_cache = chain
|
||||
.validator_pubkey_cache
|
||||
.try_read_for(VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| BeaconChainError::ValidatorPubkeyCacheLockTimeout)?;
|
||||
.ok_or(BeaconChainError::ValidatorPubkeyCacheLockTimeout)?;
|
||||
|
||||
let fork = chain
|
||||
.canonical_head
|
||||
.try_read_for(HEAD_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| BeaconChainError::CanonicalHeadLockTimeout)
|
||||
.ok_or(BeaconChainError::CanonicalHeadLockTimeout)
|
||||
.map(|head| head.beacon_state.fork)?;
|
||||
|
||||
let signature_set = indexed_attestation_signature_set_from_pubkeys(
|
||||
@@ -974,7 +974,7 @@ pub fn verify_signed_aggregate_signatures<T: BeaconChainTypes>(
|
||||
let pubkey_cache = chain
|
||||
.validator_pubkey_cache
|
||||
.try_read_for(VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| BeaconChainError::ValidatorPubkeyCacheLockTimeout)?;
|
||||
.ok_or(BeaconChainError::ValidatorPubkeyCacheLockTimeout)?;
|
||||
|
||||
let aggregator_index = signed_aggregate.message.aggregator_index;
|
||||
if aggregator_index >= pubkey_cache.len() as u64 {
|
||||
@@ -984,7 +984,7 @@ pub fn verify_signed_aggregate_signatures<T: BeaconChainTypes>(
|
||||
let fork = chain
|
||||
.canonical_head
|
||||
.try_read_for(HEAD_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| BeaconChainError::CanonicalHeadLockTimeout)
|
||||
.ok_or(BeaconChainError::CanonicalHeadLockTimeout)
|
||||
.map(|head| head.beacon_state.fork)?;
|
||||
|
||||
let signature_sets = vec![
|
||||
|
||||
@@ -318,7 +318,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
/// The slot might be unavailable due to an error with the system clock, or if the present time
|
||||
/// is before genesis (i.e., a negative slot).
|
||||
pub fn slot(&self) -> Result<Slot, Error> {
|
||||
self.slot_clock.now().ok_or_else(|| Error::UnableToReadSlot)
|
||||
self.slot_clock.now().ok_or(Error::UnableToReadSlot)
|
||||
}
|
||||
|
||||
/// Returns the epoch _right now_ according to `self.slot_clock`. Returns `Err` if the epoch is
|
||||
@@ -386,7 +386,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
) -> Result<impl Iterator<Item = Result<(Hash256, Slot), Error>>, Error> {
|
||||
let block = self
|
||||
.get_block(&block_root)?
|
||||
.ok_or_else(|| Error::MissingBeaconBlock(block_root))?;
|
||||
.ok_or(Error::MissingBeaconBlock(block_root))?;
|
||||
let state = self
|
||||
.get_state(&block.state_root(), Some(block.slot()))?
|
||||
.ok_or_else(|| Error::MissingBeaconState(block.state_root()))?;
|
||||
@@ -531,7 +531,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
let head_lock = self
|
||||
.canonical_head
|
||||
.try_read_for(HEAD_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| Error::CanonicalHeadLockTimeout)?;
|
||||
.ok_or(Error::CanonicalHeadLockTimeout)?;
|
||||
f(&head_lock)
|
||||
}
|
||||
|
||||
@@ -660,11 +660,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
.find(|(_, current_slot)| *current_slot == slot)
|
||||
.map(|(root, _slot)| root)
|
||||
})?
|
||||
.ok_or_else(|| Error::NoStateForSlot(slot))?;
|
||||
.ok_or(Error::NoStateForSlot(slot))?;
|
||||
|
||||
Ok(self
|
||||
.get_state(&state_root, Some(slot))?
|
||||
.ok_or_else(|| Error::NoStateForSlot(slot))?)
|
||||
.ok_or(Error::NoStateForSlot(slot))?)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -686,7 +686,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
self.canonical_head
|
||||
.try_read_for(HEAD_LOCK_TIMEOUT)
|
||||
.map(|head| head.beacon_block.slot())
|
||||
.ok_or_else(|| Error::CanonicalHeadLockTimeout)
|
||||
.ok_or(Error::CanonicalHeadLockTimeout)
|
||||
}
|
||||
|
||||
/// Returns the validator index (if any) for the given public key.
|
||||
@@ -705,7 +705,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
let pubkey_cache = self
|
||||
.validator_pubkey_cache
|
||||
.try_read_for(VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| Error::ValidatorPubkeyCacheLockTimeout)?;
|
||||
.ok_or(Error::ValidatorPubkeyCacheLockTimeout)?;
|
||||
|
||||
Ok(pubkey_cache.get_index(pubkey))
|
||||
}
|
||||
@@ -726,7 +726,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
let pubkey_cache = self
|
||||
.validator_pubkey_cache
|
||||
.try_read_for(VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| Error::ValidatorPubkeyCacheLockTimeout)?;
|
||||
.ok_or(Error::ValidatorPubkeyCacheLockTimeout)?;
|
||||
|
||||
Ok(pubkey_cache.get(validator_index).cloned())
|
||||
}
|
||||
@@ -848,7 +848,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
let head = self
|
||||
.canonical_head
|
||||
.try_read_for(HEAD_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| Error::CanonicalHeadLockTimeout)?;
|
||||
.ok_or(Error::CanonicalHeadLockTimeout)?;
|
||||
|
||||
if slot >= head.beacon_block.slot() {
|
||||
self.produce_unaggregated_attestation_for_block(
|
||||
@@ -879,7 +879,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
|
||||
let mut state = self
|
||||
.get_state(&state_root, Some(slot))?
|
||||
.ok_or_else(|| Error::MissingBeaconState(state_root))?;
|
||||
.ok_or(Error::MissingBeaconState(state_root))?;
|
||||
|
||||
state.build_committee_cache(RelativeEpoch::Current, &self.spec)?;
|
||||
|
||||
@@ -1068,7 +1068,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
let fork = self
|
||||
.canonical_head
|
||||
.try_read_for(HEAD_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| Error::CanonicalHeadLockTimeout)?
|
||||
.ok_or(Error::CanonicalHeadLockTimeout)?
|
||||
.beacon_state
|
||||
.fork;
|
||||
|
||||
@@ -1607,7 +1607,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
// known to fork choice. This ordering ensure that the pubkey cache is always up-to-date.
|
||||
self.validator_pubkey_cache
|
||||
.try_write_for(VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| Error::ValidatorPubkeyCacheLockTimeout)?
|
||||
.ok_or(Error::ValidatorPubkeyCacheLockTimeout)?
|
||||
.import_new_pubkeys(&state)?;
|
||||
|
||||
// For the current and next epoch of this state, ensure we have the shuffling from this
|
||||
@@ -1618,7 +1618,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
let shuffling_is_cached = self
|
||||
.shuffling_cache
|
||||
.try_read_for(ATTESTATION_CACHE_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| Error::AttestationCacheLockTimeout)?
|
||||
.ok_or(Error::AttestationCacheLockTimeout)?
|
||||
.contains(&shuffling_id);
|
||||
|
||||
if !shuffling_is_cached {
|
||||
@@ -1626,7 +1626,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
let committee_cache = state.committee_cache(*relative_epoch)?;
|
||||
self.shuffling_cache
|
||||
.try_write_for(ATTESTATION_CACHE_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| Error::AttestationCacheLockTimeout)?
|
||||
.ok_or(Error::AttestationCacheLockTimeout)?
|
||||
.insert(shuffling_id, committee_cache);
|
||||
}
|
||||
}
|
||||
@@ -1790,7 +1790,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
let eth1_chain = self
|
||||
.eth1_chain
|
||||
.as_ref()
|
||||
.ok_or_else(|| BlockProductionError::NoEth1ChainConnection)?;
|
||||
.ok_or(BlockProductionError::NoEth1ChainConnection)?;
|
||||
|
||||
// If required, transition the new state to the present slot.
|
||||
//
|
||||
@@ -1947,12 +1947,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
.unwrap_or_else(|| {
|
||||
let beacon_block = self
|
||||
.get_block(&beacon_block_root)?
|
||||
.ok_or_else(|| Error::MissingBeaconBlock(beacon_block_root))?;
|
||||
.ok_or(Error::MissingBeaconBlock(beacon_block_root))?;
|
||||
|
||||
let beacon_state_root = beacon_block.state_root();
|
||||
let beacon_state: BeaconState<T::EthSpec> = self
|
||||
.get_state(&beacon_state_root, Some(beacon_block.slot()))?
|
||||
.ok_or_else(|| Error::MissingBeaconState(beacon_state_root))?;
|
||||
.ok_or(Error::MissingBeaconState(beacon_state_root))?;
|
||||
|
||||
Ok(BeaconSnapshot {
|
||||
beacon_block,
|
||||
@@ -2038,7 +2038,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
*self
|
||||
.canonical_head
|
||||
.try_write_for(HEAD_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| Error::CanonicalHeadLockTimeout)? = new_head;
|
||||
.ok_or(Error::CanonicalHeadLockTimeout)? = new_head;
|
||||
|
||||
metrics::stop_timer(update_head_timer);
|
||||
|
||||
@@ -2065,7 +2065,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
let head = self
|
||||
.canonical_head
|
||||
.try_read_for(HEAD_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| Error::CanonicalHeadLockTimeout)?;
|
||||
.ok_or(Error::CanonicalHeadLockTimeout)?;
|
||||
|
||||
// State root of the finalized state on the epoch boundary, NOT the state
|
||||
// of the finalized block. We need to use an iterator in case the state is beyond
|
||||
@@ -2087,7 +2087,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
})
|
||||
},
|
||||
)?
|
||||
.ok_or_else(|| Error::MissingFinalizedStateRoot(new_finalized_slot))?;
|
||||
.ok_or(Error::MissingFinalizedStateRoot(new_finalized_slot))?;
|
||||
|
||||
self.after_finalization(&head.beacon_state, new_finalized_state_root)?;
|
||||
}
|
||||
@@ -2250,7 +2250,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
.fork_choice
|
||||
.read()
|
||||
.get_block(&head_block_root)
|
||||
.ok_or_else(|| Error::MissingBeaconBlock(head_block_root))?;
|
||||
.ok_or(Error::MissingBeaconBlock(head_block_root))?;
|
||||
|
||||
let shuffling_id = BlockShufflingIds {
|
||||
current: head_block.current_epoch_shuffling_id.clone(),
|
||||
@@ -2270,7 +2270,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
let mut shuffling_cache = self
|
||||
.shuffling_cache
|
||||
.try_write_for(ATTESTATION_CACHE_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| Error::AttestationCacheLockTimeout)?;
|
||||
.ok_or(Error::AttestationCacheLockTimeout)?;
|
||||
|
||||
metrics::stop_timer(cache_wait_timer);
|
||||
|
||||
@@ -2297,7 +2297,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
&head_block.state_root,
|
||||
Some(head_block.slot),
|
||||
)?
|
||||
.ok_or_else(|| Error::MissingBeaconState(head_block.state_root))?;
|
||||
.ok_or(Error::MissingBeaconState(head_block.state_root))?;
|
||||
|
||||
metrics::stop_timer(state_read_timer);
|
||||
let state_skip_timer =
|
||||
@@ -2326,7 +2326,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
|
||||
self.shuffling_cache
|
||||
.try_write_for(ATTESTATION_CACHE_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| Error::AttestationCacheLockTimeout)?
|
||||
.ok_or(Error::AttestationCacheLockTimeout)?
|
||||
.insert(shuffling_id, committee_cache);
|
||||
|
||||
metrics::stop_timer(committee_building_timer);
|
||||
@@ -2396,7 +2396,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
pub fn enr_fork_id(&self) -> EnrForkId {
|
||||
// If we are unable to read the slot clock we assume that it is prior to genesis and
|
||||
// therefore use the genesis slot.
|
||||
let slot = self.slot().unwrap_or_else(|_| self.spec.genesis_slot);
|
||||
let slot = self.slot().unwrap_or(self.spec.genesis_slot);
|
||||
|
||||
self.spec.enr_fork_id(slot, self.genesis_validators_root)
|
||||
}
|
||||
@@ -2412,7 +2412,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
let canonical_head_hash = self
|
||||
.canonical_head
|
||||
.try_read_for(HEAD_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| Error::CanonicalHeadLockTimeout)
|
||||
.ok_or(Error::CanonicalHeadLockTimeout)
|
||||
.unwrap()
|
||||
.beacon_block_root;
|
||||
let mut visited: HashSet<Hash256> = HashSet::new();
|
||||
|
||||
@@ -320,14 +320,14 @@ where
|
||||
.store
|
||||
.get_item::<SignedBeaconBlock<E>>(&self.justified_checkpoint.root)
|
||||
.map_err(Error::FailedToReadBlock)?
|
||||
.ok_or_else(|| Error::MissingBlock(self.justified_checkpoint.root))?
|
||||
.ok_or(Error::MissingBlock(self.justified_checkpoint.root))?
|
||||
.message;
|
||||
|
||||
self.justified_balances = self
|
||||
.store
|
||||
.get_state(&justified_block.state_root, Some(justified_block.slot))
|
||||
.map_err(Error::FailedToReadState)?
|
||||
.ok_or_else(|| Error::MissingState(justified_block.state_root))?
|
||||
.ok_or(Error::MissingState(justified_block.state_root))?
|
||||
.balances
|
||||
.into();
|
||||
}
|
||||
|
||||
@@ -452,7 +452,7 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
|
||||
let present_slot_with_tolerance = chain
|
||||
.slot_clock
|
||||
.now_with_future_tolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY)
|
||||
.ok_or_else(|| BeaconChainError::UnableToReadSlot)?;
|
||||
.ok_or(BeaconChainError::UnableToReadSlot)?;
|
||||
if block.slot() > present_slot_with_tolerance {
|
||||
return Err(BlockError::FutureSlot {
|
||||
present_slot: present_slot_with_tolerance,
|
||||
@@ -513,7 +513,7 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
|
||||
let pubkey_cache = get_validator_pubkey_cache(chain)?;
|
||||
let pubkey = pubkey_cache
|
||||
.get(block.message.proposer_index as usize)
|
||||
.ok_or_else(|| BlockError::UnknownValidator(block.message.proposer_index))?;
|
||||
.ok_or(BlockError::UnknownValidator(block.message.proposer_index))?;
|
||||
block.verify_signature(
|
||||
Some(block_root),
|
||||
pubkey,
|
||||
@@ -1180,7 +1180,7 @@ fn get_validator_pubkey_cache<T: BeaconChainTypes>(
|
||||
chain
|
||||
.validator_pubkey_cache
|
||||
.try_read_for(VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT)
|
||||
.ok_or_else(|| BeaconChainError::ValidatorPubkeyCacheLockTimeout)
|
||||
.ok_or(BeaconChainError::ValidatorPubkeyCacheLockTimeout)
|
||||
.map_err(BlockError::BeaconChainError)
|
||||
}
|
||||
|
||||
@@ -1220,7 +1220,7 @@ fn verify_header_signature<T: BeaconChainTypes>(
|
||||
let proposer_pubkey = get_validator_pubkey_cache(chain)?
|
||||
.get(header.message.proposer_index as usize)
|
||||
.cloned()
|
||||
.ok_or_else(|| BlockError::UnknownValidator(header.message.proposer_index))?;
|
||||
.ok_or(BlockError::UnknownValidator(header.message.proposer_index))?;
|
||||
let (fork, genesis_validators_root) = chain
|
||||
.with_head(|head| {
|
||||
Ok((
|
||||
|
||||
@@ -211,7 +211,7 @@ where
|
||||
let store = self
|
||||
.store
|
||||
.clone()
|
||||
.ok_or_else(|| "get_persisted_eth1_backend requires a store.".to_string())?;
|
||||
.ok_or("get_persisted_eth1_backend requires a store.")?;
|
||||
|
||||
store
|
||||
.get_item::<SszEth1>(Ð1_CACHE_DB_KEY)
|
||||
@@ -223,7 +223,7 @@ where
|
||||
let store = self
|
||||
.store
|
||||
.clone()
|
||||
.ok_or_else(|| "store_contains_beacon_chain requires a store.".to_string())?;
|
||||
.ok_or("store_contains_beacon_chain requires a store.")?;
|
||||
|
||||
Ok(store
|
||||
.get_item::<PersistedBeaconChain>(&BEACON_CHAIN_DB_KEY)
|
||||
@@ -235,15 +235,12 @@ where
|
||||
///
|
||||
/// May initialize several components; including the op_pool and finalized checkpoints.
|
||||
pub fn resume_from_db(mut self) -> Result<Self, String> {
|
||||
let log = self
|
||||
.log
|
||||
.as_ref()
|
||||
.ok_or_else(|| "resume_from_db requires a log".to_string())?;
|
||||
let log = self.log.as_ref().ok_or("resume_from_db requires a log")?;
|
||||
|
||||
let pubkey_cache_path = self
|
||||
.pubkey_cache_path
|
||||
.as_ref()
|
||||
.ok_or_else(|| "resume_from_db requires a data_dir".to_string())?;
|
||||
.ok_or("resume_from_db requires a data_dir")?;
|
||||
|
||||
info!(
|
||||
log,
|
||||
@@ -254,7 +251,7 @@ where
|
||||
let store = self
|
||||
.store
|
||||
.clone()
|
||||
.ok_or_else(|| "resume_from_db requires a store.".to_string())?;
|
||||
.ok_or("resume_from_db requires a store.")?;
|
||||
|
||||
let chain = store
|
||||
.get_item::<PersistedBeaconChain>(&BEACON_CHAIN_DB_KEY)
|
||||
@@ -267,7 +264,7 @@ where
|
||||
let persisted_fork_choice = store
|
||||
.get_item::<PersistedForkChoice>(&FORK_CHOICE_DB_KEY)
|
||||
.map_err(|e| format!("DB error when reading persisted fork choice: {:?}", e))?
|
||||
.ok_or_else(|| "No persisted fork choice present in database.".to_string())?;
|
||||
.ok_or("No persisted fork choice present in database.")?;
|
||||
|
||||
let fc_store = BeaconForkChoiceStore::from_persisted(
|
||||
persisted_fork_choice.fork_choice_store,
|
||||
@@ -282,11 +279,11 @@ where
|
||||
let genesis_block = store
|
||||
.get_item::<SignedBeaconBlock<TEthSpec>>(&chain.genesis_block_root)
|
||||
.map_err(|e| format!("DB error when reading genesis block: {:?}", e))?
|
||||
.ok_or_else(|| "Genesis block not found in store".to_string())?;
|
||||
.ok_or("Genesis block not found in store")?;
|
||||
let genesis_state = store
|
||||
.get_state(&genesis_block.state_root(), Some(genesis_block.slot()))
|
||||
.map_err(|e| format!("DB error when reading genesis state: {:?}", e))?
|
||||
.ok_or_else(|| "Genesis block not found in store".to_string())?;
|
||||
.ok_or("Genesis block not found in store")?;
|
||||
|
||||
self.genesis_time = Some(genesis_state.genesis_time);
|
||||
|
||||
@@ -318,10 +315,7 @@ where
|
||||
mut self,
|
||||
mut beacon_state: BeaconState<TEthSpec>,
|
||||
) -> Result<Self, String> {
|
||||
let store = self
|
||||
.store
|
||||
.clone()
|
||||
.ok_or_else(|| "genesis_state requires a store")?;
|
||||
let store = self.store.clone().ok_or("genesis_state requires a store")?;
|
||||
|
||||
let beacon_block = genesis_block(&mut beacon_state, &self.spec)?;
|
||||
|
||||
@@ -436,35 +430,28 @@ where
|
||||
>,
|
||||
String,
|
||||
> {
|
||||
let log = self
|
||||
.log
|
||||
.ok_or_else(|| "Cannot build without a logger".to_string())?;
|
||||
let log = self.log.ok_or("Cannot build without a logger")?;
|
||||
let slot_clock = self
|
||||
.slot_clock
|
||||
.ok_or_else(|| "Cannot build without a slot_clock.".to_string())?;
|
||||
let store = self
|
||||
.store
|
||||
.clone()
|
||||
.ok_or_else(|| "Cannot build without a store.".to_string())?;
|
||||
.ok_or("Cannot build without a slot_clock.")?;
|
||||
let store = self.store.clone().ok_or("Cannot build without a store.")?;
|
||||
let mut fork_choice = self
|
||||
.fork_choice
|
||||
.ok_or_else(|| "Cannot build without fork choice.".to_string())?;
|
||||
.ok_or("Cannot build without fork choice.")?;
|
||||
let genesis_block_root = self
|
||||
.genesis_block_root
|
||||
.ok_or_else(|| "Cannot build without a genesis block root".to_string())?;
|
||||
.ok_or("Cannot build without a genesis block root")?;
|
||||
let genesis_state_root = self
|
||||
.genesis_state_root
|
||||
.ok_or_else(|| "Cannot build without a genesis state root".to_string())?;
|
||||
.ok_or("Cannot build without a genesis state root")?;
|
||||
|
||||
let current_slot = if slot_clock
|
||||
.is_prior_to_genesis()
|
||||
.ok_or_else(|| "Unable to read slot clock".to_string())?
|
||||
.ok_or("Unable to read slot clock")?
|
||||
{
|
||||
self.spec.genesis_slot
|
||||
} else {
|
||||
slot_clock
|
||||
.now()
|
||||
.ok_or_else(|| "Unable to read slot".to_string())?
|
||||
slot_clock.now().ok_or("Unable to read slot")?
|
||||
};
|
||||
|
||||
let head_block_root = fork_choice
|
||||
@@ -474,12 +461,12 @@ where
|
||||
let head_block = store
|
||||
.get_item::<SignedBeaconBlock<TEthSpec>>(&head_block_root)
|
||||
.map_err(|e| format!("DB error when reading head block: {:?}", e))?
|
||||
.ok_or_else(|| "Head block not found in store".to_string())?;
|
||||
.ok_or("Head block not found in store")?;
|
||||
let head_state_root = head_block.state_root();
|
||||
let head_state = store
|
||||
.get_state(&head_state_root, Some(head_block.slot()))
|
||||
.map_err(|e| format!("DB error when reading head state: {:?}", e))?
|
||||
.ok_or_else(|| "Head state not found in store".to_string())?;
|
||||
.ok_or("Head state not found in store")?;
|
||||
|
||||
let mut canonical_head = BeaconSnapshot {
|
||||
beacon_block_root: head_block_root,
|
||||
@@ -520,7 +507,7 @@ where
|
||||
|
||||
let pubkey_cache_path = self
|
||||
.pubkey_cache_path
|
||||
.ok_or_else(|| "Cannot build without a pubkey cache path".to_string())?;
|
||||
.ok_or("Cannot build without a pubkey cache path")?;
|
||||
|
||||
let validator_pubkey_cache = self.validator_pubkey_cache.map(Ok).unwrap_or_else(|| {
|
||||
ValidatorPubkeyCache::new(&canonical_head.beacon_state, pubkey_cache_path)
|
||||
@@ -541,9 +528,7 @@ where
|
||||
store,
|
||||
store_migrator,
|
||||
slot_clock,
|
||||
op_pool: self
|
||||
.op_pool
|
||||
.ok_or_else(|| "Cannot build without op pool".to_string())?,
|
||||
op_pool: self.op_pool.ok_or("Cannot build without op pool")?,
|
||||
// TODO: allow for persisting and loading the pool from disk.
|
||||
naive_aggregation_pool: <_>::default(),
|
||||
// TODO: allow for persisting and loading the pool from disk.
|
||||
@@ -566,7 +551,7 @@ where
|
||||
fork_choice: RwLock::new(fork_choice),
|
||||
event_handler: self
|
||||
.event_handler
|
||||
.ok_or_else(|| "Cannot build without an event handler".to_string())?,
|
||||
.ok_or("Cannot build without an event handler")?,
|
||||
head_tracker: Arc::new(self.head_tracker.unwrap_or_default()),
|
||||
snapshot_cache: TimeoutRwLock::new(SnapshotCache::new(
|
||||
DEFAULT_SNAPSHOT_CACHE_SIZE,
|
||||
@@ -577,7 +562,7 @@ where
|
||||
disabled_forks: self.disabled_forks,
|
||||
shutdown_sender: self
|
||||
.shutdown_sender
|
||||
.ok_or_else(|| "Cannot build without a shutdown sender.".to_string())?,
|
||||
.ok_or("Cannot build without a shutdown sender.")?,
|
||||
log: log.clone(),
|
||||
graffiti: self.graffiti,
|
||||
slasher: self.slasher.clone(),
|
||||
@@ -648,7 +633,7 @@ where
|
||||
let log = self
|
||||
.log
|
||||
.as_ref()
|
||||
.ok_or_else(|| "dummy_eth1_backend requires a log".to_string())?;
|
||||
.ok_or("dummy_eth1_backend requires a log")?;
|
||||
|
||||
let backend =
|
||||
CachingEth1Backend::new(Eth1Config::default(), log.clone(), self.spec.clone());
|
||||
@@ -676,7 +661,7 @@ where
|
||||
pub fn testing_slot_clock(self, slot_duration: Duration) -> Result<Self, String> {
|
||||
let genesis_time = self
|
||||
.genesis_time
|
||||
.ok_or_else(|| "testing_slot_clock requires an initialized state")?;
|
||||
.ok_or("testing_slot_clock requires an initialized state")?;
|
||||
|
||||
let slot_clock = TestingSlotClock::new(
|
||||
Slot::new(0),
|
||||
|
||||
@@ -83,7 +83,7 @@ impl<E: EthSpec> AggregatedAttestationMap<E> {
|
||||
let committee_index = set_bits
|
||||
.first()
|
||||
.copied()
|
||||
.ok_or_else(|| Error::NoAggregationBitsSet)?;
|
||||
.ok_or(Error::NoAggregationBitsSet)?;
|
||||
|
||||
if set_bits.len() > 1 {
|
||||
return Err(Error::MoreThanOneAggregationBitSet(set_bits.len()));
|
||||
|
||||
@@ -144,7 +144,7 @@ impl<E: EthSpec> ObservedAttestations<E> {
|
||||
|
||||
self.sets
|
||||
.get_mut(index)
|
||||
.ok_or_else(|| Error::InvalidSetIndex(index))
|
||||
.ok_or(Error::InvalidSetIndex(index))
|
||||
.and_then(|set| set.observe_attestation(a, root))
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ impl<E: EthSpec> ObservedAttestations<E> {
|
||||
|
||||
self.sets
|
||||
.get(index)
|
||||
.ok_or_else(|| Error::InvalidSetIndex(index))
|
||||
.ok_or(Error::InvalidSetIndex(index))
|
||||
.and_then(|set| set.is_known(a, root))
|
||||
}
|
||||
|
||||
|
||||
@@ -137,13 +137,11 @@ where
|
||||
let chain_config = config.chain.clone();
|
||||
let graffiti = config.graffiti;
|
||||
|
||||
let store =
|
||||
store.ok_or_else(|| "beacon_chain_start_method requires a store".to_string())?;
|
||||
let store = store.ok_or("beacon_chain_start_method requires a store")?;
|
||||
let context = runtime_context
|
||||
.ok_or_else(|| "beacon_chain_start_method requires a runtime context".to_string())?
|
||||
.ok_or("beacon_chain_start_method requires a runtime context")?
|
||||
.service_context("beacon".into());
|
||||
let spec = chain_spec
|
||||
.ok_or_else(|| "beacon_chain_start_method requires a chain spec".to_string())?;
|
||||
let spec = chain_spec.ok_or("beacon_chain_start_method requires a chain spec")?;
|
||||
|
||||
let builder = BeaconChainBuilder::new(eth_spec_instance)
|
||||
.logger(context.log().clone())
|
||||
@@ -160,9 +158,7 @@ where
|
||||
builder
|
||||
};
|
||||
|
||||
let chain_exists = builder
|
||||
.store_contains_beacon_chain()
|
||||
.unwrap_or_else(|_| false);
|
||||
let chain_exists = builder.store_contains_beacon_chain().unwrap_or(false);
|
||||
|
||||
// If the client is expect to resume but there's no beacon chain in the database,
|
||||
// use the `DepositContract` method. This scenario is quite common when the client
|
||||
@@ -310,11 +306,11 @@ where
|
||||
let beacon_chain = self
|
||||
.beacon_chain
|
||||
.clone()
|
||||
.ok_or_else(|| "network requires a beacon chain")?;
|
||||
.ok_or("network requires a beacon chain")?;
|
||||
let context = self
|
||||
.runtime_context
|
||||
.as_ref()
|
||||
.ok_or_else(|| "network requires a runtime_context")?
|
||||
.ok_or("network requires a runtime_context")?
|
||||
.clone();
|
||||
|
||||
let (network_globals, network_send) =
|
||||
@@ -333,16 +329,16 @@ where
|
||||
let context = self
|
||||
.runtime_context
|
||||
.as_ref()
|
||||
.ok_or_else(|| "node timer requires a runtime_context")?
|
||||
.ok_or("node timer requires a runtime_context")?
|
||||
.service_context("node_timer".into());
|
||||
let beacon_chain = self
|
||||
.beacon_chain
|
||||
.clone()
|
||||
.ok_or_else(|| "node timer requires a beacon chain")?;
|
||||
.ok_or("node timer requires a beacon chain")?;
|
||||
let milliseconds_per_slot = self
|
||||
.chain_spec
|
||||
.as_ref()
|
||||
.ok_or_else(|| "node timer requires a chain spec".to_string())?
|
||||
.ok_or("node timer requires a chain spec")?
|
||||
.milliseconds_per_slot;
|
||||
|
||||
spawn_timer(context.executor, beacon_chain, milliseconds_per_slot)
|
||||
@@ -370,16 +366,16 @@ where
|
||||
let context = self
|
||||
.runtime_context
|
||||
.as_ref()
|
||||
.ok_or_else(|| "slasher requires a runtime_context")?
|
||||
.ok_or("slasher requires a runtime_context")?
|
||||
.service_context("slasher_server_ctxt".into());
|
||||
let slasher = self
|
||||
.slasher
|
||||
.clone()
|
||||
.ok_or_else(|| "slasher server requires a slasher")?;
|
||||
.ok_or("slasher server requires a slasher")?;
|
||||
let slot_clock = self
|
||||
.slot_clock
|
||||
.clone()
|
||||
.ok_or_else(|| "slasher server requires a slot clock")?;
|
||||
.ok_or("slasher server requires a slot clock")?;
|
||||
SlasherServer::run(slasher, slot_clock, &context.executor);
|
||||
Ok(())
|
||||
}
|
||||
@@ -389,20 +385,20 @@ where
|
||||
let context = self
|
||||
.runtime_context
|
||||
.as_ref()
|
||||
.ok_or_else(|| "slot_notifier requires a runtime_context")?
|
||||
.ok_or("slot_notifier requires a runtime_context")?
|
||||
.service_context("slot_notifier".into());
|
||||
let beacon_chain = self
|
||||
.beacon_chain
|
||||
.clone()
|
||||
.ok_or_else(|| "slot_notifier requires a beacon chain")?;
|
||||
.ok_or("slot_notifier requires a beacon chain")?;
|
||||
let network_globals = self
|
||||
.network_globals
|
||||
.clone()
|
||||
.ok_or_else(|| "slot_notifier requires a libp2p network")?;
|
||||
.ok_or("slot_notifier requires a libp2p network")?;
|
||||
let milliseconds_per_slot = self
|
||||
.chain_spec
|
||||
.as_ref()
|
||||
.ok_or_else(|| "slot_notifier requires a chain spec".to_string())?
|
||||
.ok_or("slot_notifier requires a chain spec")?
|
||||
.milliseconds_per_slot;
|
||||
|
||||
spawn_notifier(
|
||||
@@ -430,7 +426,7 @@ where
|
||||
let runtime_context = self
|
||||
.runtime_context
|
||||
.as_ref()
|
||||
.ok_or_else(|| "build requires a runtime context".to_string())?;
|
||||
.ok_or("build requires a runtime context")?;
|
||||
let log = runtime_context.log().clone();
|
||||
|
||||
let http_api_listen_addr = if self.http_api_config.enabled {
|
||||
@@ -518,20 +514,20 @@ where
|
||||
let context = self
|
||||
.runtime_context
|
||||
.as_ref()
|
||||
.ok_or_else(|| "beacon_chain requires a runtime context")?
|
||||
.ok_or("beacon_chain requires a runtime context")?
|
||||
.clone();
|
||||
|
||||
let chain = self
|
||||
.beacon_chain_builder
|
||||
.ok_or_else(|| "beacon_chain requires a beacon_chain_builder")?
|
||||
.ok_or("beacon_chain requires a beacon_chain_builder")?
|
||||
.event_handler(
|
||||
self.event_handler
|
||||
.ok_or_else(|| "beacon_chain requires an event handler")?,
|
||||
.ok_or("beacon_chain requires an event handler")?,
|
||||
)
|
||||
.slot_clock(
|
||||
self.slot_clock
|
||||
.clone()
|
||||
.ok_or_else(|| "beacon_chain requires a slot clock")?,
|
||||
.ok_or("beacon_chain requires a slot clock")?,
|
||||
)
|
||||
.shutdown_sender(context.executor.shutdown_sender())
|
||||
.build()
|
||||
@@ -573,7 +569,7 @@ where
|
||||
let context = self
|
||||
.runtime_context
|
||||
.as_ref()
|
||||
.ok_or_else(|| "tee_event_handler requires a runtime_context")?
|
||||
.ok_or("tee_event_handler requires a runtime_context")?
|
||||
.service_context("ws".into());
|
||||
|
||||
let log = context.log().clone();
|
||||
@@ -619,12 +615,12 @@ where
|
||||
let context = self
|
||||
.runtime_context
|
||||
.as_ref()
|
||||
.ok_or_else(|| "disk_store requires a log".to_string())?
|
||||
.ok_or("disk_store requires a log")?
|
||||
.service_context("freezer_db".into());
|
||||
let spec = self
|
||||
.chain_spec
|
||||
.clone()
|
||||
.ok_or_else(|| "disk_store requires a chain spec".to_string())?;
|
||||
.ok_or("disk_store requires a chain spec")?;
|
||||
|
||||
self.db_path = Some(hot_path.into());
|
||||
self.freezer_db_path = Some(cold_path.into());
|
||||
@@ -661,15 +657,15 @@ where
|
||||
let context = self
|
||||
.runtime_context
|
||||
.as_ref()
|
||||
.ok_or_else(|| "caching_eth1_backend requires a runtime_context")?
|
||||
.ok_or("caching_eth1_backend requires a runtime_context")?
|
||||
.service_context("eth1_rpc".into());
|
||||
let beacon_chain_builder = self
|
||||
.beacon_chain_builder
|
||||
.ok_or_else(|| "caching_eth1_backend requires a beacon_chain_builder")?;
|
||||
.ok_or("caching_eth1_backend requires a beacon_chain_builder")?;
|
||||
let spec = self
|
||||
.chain_spec
|
||||
.clone()
|
||||
.ok_or_else(|| "caching_eth1_backend requires a chain spec".to_string())?;
|
||||
.ok_or("caching_eth1_backend requires a chain spec")?;
|
||||
|
||||
let backend = if let Some(eth1_service_from_genesis) = self.eth1_service {
|
||||
eth1_service_from_genesis.update_config(config)?;
|
||||
@@ -720,7 +716,7 @@ where
|
||||
pub fn no_eth1_backend(mut self) -> Result<Self, String> {
|
||||
let beacon_chain_builder = self
|
||||
.beacon_chain_builder
|
||||
.ok_or_else(|| "caching_eth1_backend requires a beacon_chain_builder")?;
|
||||
.ok_or("caching_eth1_backend requires a beacon_chain_builder")?;
|
||||
|
||||
self.beacon_chain_builder = Some(beacon_chain_builder.no_eth1_backend());
|
||||
|
||||
@@ -739,7 +735,7 @@ where
|
||||
pub fn dummy_eth1_backend(mut self) -> Result<Self, String> {
|
||||
let beacon_chain_builder = self
|
||||
.beacon_chain_builder
|
||||
.ok_or_else(|| "caching_eth1_backend requires a beacon_chain_builder")?;
|
||||
.ok_or("caching_eth1_backend requires a beacon_chain_builder")?;
|
||||
|
||||
self.beacon_chain_builder = Some(beacon_chain_builder.dummy_eth1_backend()?);
|
||||
|
||||
@@ -763,16 +759,16 @@ where
|
||||
let beacon_chain_builder = self
|
||||
.beacon_chain_builder
|
||||
.as_ref()
|
||||
.ok_or_else(|| "system_time_slot_clock requires a beacon_chain_builder")?;
|
||||
.ok_or("system_time_slot_clock requires a beacon_chain_builder")?;
|
||||
|
||||
let genesis_time = beacon_chain_builder
|
||||
.genesis_time
|
||||
.ok_or_else(|| "system_time_slot_clock requires an initialized beacon state")?;
|
||||
.ok_or("system_time_slot_clock requires an initialized beacon state")?;
|
||||
|
||||
let spec = self
|
||||
.chain_spec
|
||||
.clone()
|
||||
.ok_or_else(|| "system_time_slot_clock requires a chain spec".to_string())?;
|
||||
.ok_or("system_time_slot_clock requires a chain spec")?;
|
||||
|
||||
let slot_clock = SystemTimeSlotClock::new(
|
||||
spec.genesis_slot,
|
||||
|
||||
@@ -101,7 +101,7 @@ impl Config {
|
||||
pub fn create_db_path(&self) -> Result<PathBuf, String> {
|
||||
let db_path = self
|
||||
.get_db_path()
|
||||
.ok_or_else(|| "Unable to locate user home directory")?;
|
||||
.ok_or("Unable to locate user home directory")?;
|
||||
ensure_dir_exists(db_path)
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ impl Config {
|
||||
pub fn create_freezer_db_path(&self) -> Result<PathBuf, String> {
|
||||
let freezer_db_path = self
|
||||
.get_freezer_db_path()
|
||||
.ok_or_else(|| "Unable to locate user home directory")?;
|
||||
.ok_or("Unable to locate user home directory")?;
|
||||
ensure_dir_exists(freezer_db_path)
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ impl Config {
|
||||
pub fn create_data_dir(&self) -> Result<PathBuf, String> {
|
||||
let path = self
|
||||
.get_data_dir()
|
||||
.ok_or_else(|| "Unable to locate user home directory".to_string())?;
|
||||
.ok_or("Unable to locate user home directory")?;
|
||||
ensure_dir_exists(path)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
|
||||
let duration_to_next_slot = beacon_chain
|
||||
.slot_clock
|
||||
.duration_to_next_slot()
|
||||
.ok_or_else(|| "slot_notifier unable to determine time to next slot")?;
|
||||
.ok_or("slot_notifier unable to determine time to next slot")?;
|
||||
|
||||
// Run this half way through each slot.
|
||||
let start_instant = tokio::time::Instant::now() + duration_to_next_slot + (slot_duration / 2);
|
||||
@@ -94,7 +94,7 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
|
||||
|
||||
metrics::set_gauge(
|
||||
&metrics::SYNC_SLOTS_PER_SECOND,
|
||||
speedo.slots_per_second().unwrap_or_else(|| 0_f64) as i64,
|
||||
speedo.slots_per_second().unwrap_or(0_f64) as i64,
|
||||
);
|
||||
|
||||
// The next two lines take advantage of saturating subtraction on `Slot`.
|
||||
|
||||
@@ -25,19 +25,19 @@ impl Log {
|
||||
|
||||
let pubkey = bytes
|
||||
.get(PUBKEY_START..PUBKEY_START + PUBKEY_LEN)
|
||||
.ok_or_else(|| "Insufficient bytes for pubkey".to_string())?;
|
||||
.ok_or("Insufficient bytes for pubkey")?;
|
||||
let withdrawal_credentials = bytes
|
||||
.get(CREDS_START..CREDS_START + CREDS_LEN)
|
||||
.ok_or_else(|| "Insufficient bytes for withdrawal credential".to_string())?;
|
||||
.ok_or("Insufficient bytes for withdrawal credential")?;
|
||||
let amount = bytes
|
||||
.get(AMOUNT_START..AMOUNT_START + AMOUNT_LEN)
|
||||
.ok_or_else(|| "Insufficient bytes for amount".to_string())?;
|
||||
.ok_or("Insufficient bytes for amount")?;
|
||||
let signature = bytes
|
||||
.get(SIG_START..SIG_START + SIG_LEN)
|
||||
.ok_or_else(|| "Insufficient bytes for signature".to_string())?;
|
||||
.ok_or("Insufficient bytes for signature")?;
|
||||
let index = bytes
|
||||
.get(INDEX_START..INDEX_START + INDEX_LEN)
|
||||
.ok_or_else(|| "Insufficient bytes for index".to_string())?;
|
||||
.ok_or("Insufficient bytes for index")?;
|
||||
|
||||
let deposit_data = DepositData {
|
||||
pubkey: PublicKeyBytes::from_ssz_bytes(pubkey)
|
||||
|
||||
@@ -83,9 +83,9 @@ pub async fn get_network_id(endpoint: &str, timeout: Duration) -> Result<Eth1Id,
|
||||
let response_body = send_rpc_request(endpoint, "net_version", json!([]), timeout).await?;
|
||||
Eth1Id::from_str(
|
||||
response_result(&response_body)?
|
||||
.ok_or_else(|| "No result was returned for network id".to_string())?
|
||||
.ok_or("No result was returned for network id")?
|
||||
.as_str()
|
||||
.ok_or_else(|| "Data was not string")?,
|
||||
.ok_or("Data was not string")?,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -94,9 +94,9 @@ pub async fn get_chain_id(endpoint: &str, timeout: Duration) -> Result<Eth1Id, S
|
||||
let response_body = send_rpc_request(endpoint, "eth_chainId", json!([]), timeout).await?;
|
||||
hex_to_u64_be(
|
||||
response_result(&response_body)?
|
||||
.ok_or_else(|| "No result was returned for chain id".to_string())?
|
||||
.ok_or("No result was returned for chain id")?
|
||||
.as_str()
|
||||
.ok_or_else(|| "Data was not string")?,
|
||||
.ok_or("Data was not string")?,
|
||||
)
|
||||
.map(Into::into)
|
||||
}
|
||||
@@ -115,9 +115,9 @@ pub async fn get_block_number(endpoint: &str, timeout: Duration) -> Result<u64,
|
||||
let response_body = send_rpc_request(endpoint, "eth_blockNumber", json!([]), timeout).await?;
|
||||
hex_to_u64_be(
|
||||
response_result(&response_body)?
|
||||
.ok_or_else(|| "No result field was returned for block number".to_string())?
|
||||
.ok_or("No result field was returned for block number")?
|
||||
.as_str()
|
||||
.ok_or_else(|| "Data was not string")?,
|
||||
.ok_or("Data was not string")?,
|
||||
)
|
||||
.map_err(|e| format!("Failed to get block number: {}", e))
|
||||
}
|
||||
@@ -142,11 +142,11 @@ pub async fn get_block(
|
||||
let response_body = send_rpc_request(endpoint, "eth_getBlockByNumber", params, timeout).await?;
|
||||
let hash = hex_to_bytes(
|
||||
response_result(&response_body)?
|
||||
.ok_or_else(|| "No result field was returned for block".to_string())?
|
||||
.ok_or("No result field was returned for block")?
|
||||
.get("hash")
|
||||
.ok_or_else(|| "No hash for block")?
|
||||
.ok_or("No hash for block")?
|
||||
.as_str()
|
||||
.ok_or_else(|| "Block hash was not string")?,
|
||||
.ok_or("Block hash was not string")?,
|
||||
)?;
|
||||
let hash = if hash.len() == 32 {
|
||||
Ok(Hash256::from_slice(&hash))
|
||||
@@ -156,20 +156,20 @@ pub async fn get_block(
|
||||
|
||||
let timestamp = hex_to_u64_be(
|
||||
response_result(&response_body)?
|
||||
.ok_or_else(|| "No result field was returned for timestamp".to_string())?
|
||||
.ok_or("No result field was returned for timestamp")?
|
||||
.get("timestamp")
|
||||
.ok_or_else(|| "No timestamp for block")?
|
||||
.ok_or("No timestamp for block")?
|
||||
.as_str()
|
||||
.ok_or_else(|| "Block timestamp was not string")?,
|
||||
.ok_or("Block timestamp was not string")?,
|
||||
)?;
|
||||
|
||||
let number = hex_to_u64_be(
|
||||
response_result(&response_body)?
|
||||
.ok_or_else(|| "No result field was returned for number".to_string())?
|
||||
.ok_or("No result field was returned for number")?
|
||||
.get("number")
|
||||
.ok_or_else(|| "No number for block")?
|
||||
.ok_or("No number for block")?
|
||||
.as_str()
|
||||
.ok_or_else(|| "Block number was not string")?,
|
||||
.ok_or("Block number was not string")?,
|
||||
)?;
|
||||
|
||||
if number <= usize::max_value() as u64 {
|
||||
@@ -287,7 +287,7 @@ async fn call(
|
||||
let hex = result
|
||||
.as_str()
|
||||
.map(|s| s.to_string())
|
||||
.ok_or_else(|| "'result' value was not a string".to_string())?;
|
||||
.ok_or("'result' value was not a string")?;
|
||||
|
||||
Ok(Some(hex_to_bytes(&hex)?))
|
||||
}
|
||||
@@ -322,23 +322,23 @@ pub async fn get_deposit_logs_in_range(
|
||||
|
||||
let response_body = send_rpc_request(endpoint, "eth_getLogs", params, timeout).await?;
|
||||
response_result(&response_body)?
|
||||
.ok_or_else(|| "No result field was returned for deposit logs".to_string())?
|
||||
.ok_or("No result field was returned for deposit logs")?
|
||||
.as_array()
|
||||
.cloned()
|
||||
.ok_or_else(|| "'result' value was not an array".to_string())?
|
||||
.ok_or("'result' value was not an array")?
|
||||
.into_iter()
|
||||
.map(|value| {
|
||||
let block_number = value
|
||||
.get("blockNumber")
|
||||
.ok_or_else(|| "No block number field in log")?
|
||||
.ok_or("No block number field in log")?
|
||||
.as_str()
|
||||
.ok_or_else(|| "Block number was not string")?;
|
||||
.ok_or("Block number was not string")?;
|
||||
|
||||
let data = value
|
||||
.get("data")
|
||||
.ok_or_else(|| "No block number field in log")?
|
||||
.ok_or("No block number field in log")?
|
||||
.as_str()
|
||||
.ok_or_else(|| "Data was not string")?;
|
||||
.ok_or("Data was not string")?;
|
||||
|
||||
Ok(Log {
|
||||
block_number: hex_to_u64_be(&block_number)?,
|
||||
@@ -389,7 +389,7 @@ pub async fn send_rpc_request(
|
||||
let encoding = response
|
||||
.headers()
|
||||
.get(CONTENT_TYPE)
|
||||
.ok_or_else(|| "No content-type header in response".to_string())?
|
||||
.ok_or("No content-type header in response")?
|
||||
.to_str()
|
||||
.map(|s| s.to_string())
|
||||
.map_err(|e| format!("Failed to parse content-type header: {}", e))?;
|
||||
@@ -443,8 +443,8 @@ fn hex_to_bytes(hex: &str) -> Result<Vec<u8>, String> {
|
||||
|
||||
/// Removes the `0x` prefix from some bytes. Returns an error if the prefix is not present.
|
||||
fn strip_prefix(hex: &str) -> Result<&str, String> {
|
||||
if hex.starts_with("0x") {
|
||||
Ok(&hex[2..])
|
||||
if let Some(stripped) = hex.strip_prefix("0x") {
|
||||
Ok(stripped)
|
||||
} else {
|
||||
Err("Hex string did not start with `0x`".to_string())
|
||||
}
|
||||
|
||||
@@ -808,8 +808,8 @@ impl Service {
|
||||
.chunks(blocks_per_log_query)
|
||||
.take(max_log_requests_per_update)
|
||||
.map(|vec| {
|
||||
let first = vec.first().cloned().unwrap_or_else(|| 0);
|
||||
let last = vec.last().map(|n| n + 1).unwrap_or_else(|| 0);
|
||||
let first = vec.first().cloned().unwrap_or(0);
|
||||
let last = vec.last().map(|n| n + 1).unwrap_or(0);
|
||||
first..last
|
||||
})
|
||||
.collect::<Vec<Range<u64>>>()
|
||||
@@ -894,7 +894,7 @@ impl Service {
|
||||
metrics::set_gauge(&metrics::DEPOSIT_CACHE_LEN, cache.cache.len() as i64);
|
||||
metrics::set_gauge(
|
||||
&metrics::HIGHEST_PROCESSED_DEPOSIT_BLOCK,
|
||||
cache.last_processed_block.unwrap_or_else(|| 0) as i64,
|
||||
cache.last_processed_block.unwrap_or(0) as i64,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1035,7 +1035,7 @@ impl Service {
|
||||
.block_cache
|
||||
.read()
|
||||
.latest_block_timestamp()
|
||||
.unwrap_or_else(|| 0) as i64,
|
||||
.unwrap_or(0) as i64,
|
||||
);
|
||||
|
||||
blocks_imported += 1;
|
||||
|
||||
@@ -34,16 +34,14 @@ impl Eth2Enr for Enr {
|
||||
fn bitfield<TSpec: EthSpec>(&self) -> Result<EnrBitfield<TSpec>, &'static str> {
|
||||
let bitfield_bytes = self
|
||||
.get(BITFIELD_ENR_KEY)
|
||||
.ok_or_else(|| "ENR bitfield non-existent")?;
|
||||
.ok_or("ENR bitfield non-existent")?;
|
||||
|
||||
BitVector::<TSpec::SubnetBitfieldLength>::from_ssz_bytes(bitfield_bytes)
|
||||
.map_err(|_| "Could not decode the ENR SSZ bitfield")
|
||||
}
|
||||
|
||||
fn eth2(&self) -> Result<EnrForkId, &'static str> {
|
||||
let eth2_bytes = self
|
||||
.get(ETH2_ENR_KEY)
|
||||
.ok_or_else(|| "ENR has no eth2 field")?;
|
||||
let eth2_bytes = self.get(ETH2_ENR_KEY).ok_or("ENR has no eth2 field")?;
|
||||
|
||||
EnrForkId::from_ssz_bytes(eth2_bytes).map_err(|_| "Could not decode EnrForkId")
|
||||
}
|
||||
@@ -79,7 +77,7 @@ pub fn use_or_load_enr(
|
||||
// same node id, different configuration - update the sequence number
|
||||
// Note: local_enr is generated with default(0) attnets value,
|
||||
// so a non default value in persisted enr will also update sequence number.
|
||||
let new_seq_no = disk_enr.seq().checked_add(1).ok_or_else(|| "ENR sequence number on file is too large. Remove it to generate a new NodeId")?;
|
||||
let new_seq_no = disk_enr.seq().checked_add(1).ok_or("ENR sequence number on file is too large. Remove it to generate a new NodeId")?;
|
||||
local_enr.set_seq(new_seq_no, enr_key).map_err(|e| {
|
||||
format!("Could not update ENR sequence number: {:?}", e)
|
||||
})?;
|
||||
@@ -133,7 +131,7 @@ pub fn create_enr_builder_from_config<T: EnrKey>(
|
||||
}
|
||||
// we always give it our listening tcp port
|
||||
if enable_tcp {
|
||||
let tcp_port = config.enr_tcp_port.unwrap_or_else(|| config.libp2p_port);
|
||||
let tcp_port = config.enr_tcp_port.unwrap_or(config.libp2p_port);
|
||||
builder.tcp(tcp_port);
|
||||
}
|
||||
builder
|
||||
|
||||
@@ -83,10 +83,7 @@ impl<T: EthSpec> PeerInfo<T> {
|
||||
/// Returns if the peer is subscribed to a given `SubnetId`
|
||||
pub fn on_subnet(&self, subnet_id: SubnetId) -> bool {
|
||||
if let Some(meta_data) = &self.meta_data {
|
||||
return meta_data
|
||||
.attnets
|
||||
.get(*subnet_id as usize)
|
||||
.unwrap_or_else(|_| false);
|
||||
return meta_data.attnets.get(*subnet_id as usize).unwrap_or(false);
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
@@ -313,8 +313,7 @@ impl PartialOrd for Score {
|
||||
|
||||
impl Ord for Score {
|
||||
fn cmp(&self, other: &Score) -> std::cmp::Ordering {
|
||||
self.partial_cmp(other)
|
||||
.unwrap_or_else(|| std::cmp::Ordering::Equal)
|
||||
self.partial_cmp(other).unwrap_or(std::cmp::Ordering::Equal)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -375,8 +375,8 @@ fn build_transport(
|
||||
// Useful helper functions for debugging. Currently not used in the client.
|
||||
#[allow(dead_code)]
|
||||
fn keypair_from_hex(hex_bytes: &str) -> error::Result<Keypair> {
|
||||
let hex_bytes = if hex_bytes.starts_with("0x") {
|
||||
hex_bytes[2..].to_string()
|
||||
let hex_bytes = if let Some(stripped) = hex_bytes.strip_prefix("0x") {
|
||||
stripped.to_string()
|
||||
} else {
|
||||
hex_bytes.to_string()
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ impl BeaconProposerCache {
|
||||
.fork_choice
|
||||
.read()
|
||||
.get_block(&head_root)
|
||||
.ok_or_else(|| BeaconChainError::MissingBeaconBlock(head_root))?;
|
||||
.ok_or(BeaconChainError::MissingBeaconBlock(head_root))?;
|
||||
|
||||
// If the head epoch is more than `EPOCHS_TO_SKIP` in the future, just build the cache at
|
||||
// the epoch of the head. This prevents doing a massive amount of skip slots when starting
|
||||
@@ -63,7 +63,7 @@ impl BeaconProposerCache {
|
||||
|
||||
let mut head_state = chain
|
||||
.get_state(&head_block.state_root, Some(head_block.slot))?
|
||||
.ok_or_else(|| BeaconChainError::MissingBeaconState(head_block.state_root))?;
|
||||
.ok_or(BeaconChainError::MissingBeaconState(head_block.state_root))?;
|
||||
|
||||
let decision_block_root = Self::decision_block_root(current_epoch, head_root, &head_state)?;
|
||||
|
||||
@@ -85,7 +85,7 @@ impl BeaconProposerCache {
|
||||
.and_then(|i| {
|
||||
let pubkey = chain
|
||||
.validator_pubkey(i)?
|
||||
.ok_or_else(|| BeaconChainError::ValidatorPubkeyCacheIncomplete(i))?;
|
||||
.ok_or(BeaconChainError::ValidatorPubkeyCacheIncomplete(i))?;
|
||||
|
||||
Ok(ProposerData {
|
||||
pubkey: PublicKeyBytes::from(pubkey),
|
||||
@@ -168,7 +168,7 @@ impl BeaconProposerCache {
|
||||
.fork_choice
|
||||
.read()
|
||||
.get_block(&head_block_root)
|
||||
.ok_or_else(|| BeaconChainError::MissingBeaconBlock(head_block_root))
|
||||
.ok_or(BeaconChainError::MissingBeaconBlock(head_block_root))
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
|
||||
// Rebuild the cache if this call causes a cache-miss.
|
||||
|
||||
@@ -315,7 +315,7 @@ impl<T: BeaconChainTypes> AttestationService<T> {
|
||||
.beacon_chain
|
||||
.slot_clock
|
||||
.now()
|
||||
.ok_or_else(|| "Could not get the current slot")?;
|
||||
.ok_or("Could not get the current slot")?;
|
||||
|
||||
let discovery_subnets: Vec<SubnetDiscovery> = exact_subnets
|
||||
.filter_map(|exact_subnet| {
|
||||
@@ -363,7 +363,7 @@ impl<T: BeaconChainTypes> AttestationService<T> {
|
||||
.beacon_chain
|
||||
.slot_clock
|
||||
.now()
|
||||
.ok_or_else(|| "Could not get the current slot")?;
|
||||
.ok_or("Could not get the current slot")?;
|
||||
|
||||
// Calculate the duration to the unsubscription event.
|
||||
// There are two main cases. Attempting to subscribe to the current slot and all others.
|
||||
@@ -371,7 +371,7 @@ impl<T: BeaconChainTypes> AttestationService<T> {
|
||||
self.beacon_chain
|
||||
.slot_clock
|
||||
.duration_to_next_slot()
|
||||
.ok_or_else(|| "Unable to determine duration to next slot")?
|
||||
.ok_or("Unable to determine duration to next slot")?
|
||||
} else {
|
||||
let slot_duration = self.beacon_chain.slot_clock.slot_duration();
|
||||
|
||||
@@ -380,7 +380,7 @@ impl<T: BeaconChainTypes> AttestationService<T> {
|
||||
self.beacon_chain
|
||||
.slot_clock
|
||||
.duration_to_slot(exact_subnet.slot)
|
||||
.ok_or_else(|| "Unable to determine duration to subscription slot")?
|
||||
.ok_or("Unable to determine duration to subscription slot")?
|
||||
+ slot_duration
|
||||
};
|
||||
|
||||
|
||||
@@ -33,18 +33,14 @@ pub fn get_config<E: EthSpec>(
|
||||
// If necessary, remove any existing database and configuration
|
||||
if client_config.data_dir.exists() && cli_args.is_present("purge-db") {
|
||||
// Remove the chain_db.
|
||||
fs::remove_dir_all(
|
||||
client_config
|
||||
.get_db_path()
|
||||
.ok_or_else(|| "Failed to get db_path".to_string())?,
|
||||
)
|
||||
.map_err(|err| format!("Failed to remove chain_db: {}", err))?;
|
||||
fs::remove_dir_all(client_config.get_db_path().ok_or("Failed to get db_path")?)
|
||||
.map_err(|err| format!("Failed to remove chain_db: {}", err))?;
|
||||
|
||||
// Remove the freezer db.
|
||||
fs::remove_dir_all(
|
||||
client_config
|
||||
.get_freezer_db_path()
|
||||
.ok_or_else(|| "Failed to get freezer db path".to_string())?,
|
||||
.ok_or("Failed to get freezer db path")?,
|
||||
)
|
||||
.map_err(|err| format!("Failed to remove chain_db: {}", err))?;
|
||||
|
||||
@@ -319,10 +315,10 @@ pub fn get_config<E: EthSpec>(
|
||||
let mut split = wss_checkpoint.split(':');
|
||||
let root_str = split
|
||||
.next()
|
||||
.ok_or_else(|| "Improperly formatted weak subjectivity checkpoint".to_string())?;
|
||||
.ok_or("Improperly formatted weak subjectivity checkpoint")?;
|
||||
let epoch_str = split
|
||||
.next()
|
||||
.ok_or_else(|| "Improperly formatted weak subjectivity checkpoint".to_string())?;
|
||||
.ok_or("Improperly formatted weak subjectivity checkpoint")?;
|
||||
|
||||
if !root_str.starts_with("0x") {
|
||||
return Err(
|
||||
@@ -555,7 +551,7 @@ pub fn set_network_config(
|
||||
resolved_addrs
|
||||
.next()
|
||||
.map(|a| a.ip())
|
||||
.ok_or_else(|| "Resolved dns addr contains no entries".to_string())?
|
||||
.ok_or("Resolved dns addr contains no entries")?
|
||||
} else {
|
||||
return Err(format!("Failed to parse enr-address: {}", enr_address));
|
||||
};
|
||||
|
||||
@@ -394,9 +394,9 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
// boundary state in the hot DB.
|
||||
let state = self
|
||||
.load_hot_state(&epoch_boundary_state_root, BlockReplay::Accurate)?
|
||||
.ok_or_else(|| {
|
||||
HotColdDBError::MissingEpochBoundaryState(epoch_boundary_state_root)
|
||||
})?;
|
||||
.ok_or(HotColdDBError::MissingEpochBoundaryState(
|
||||
epoch_boundary_state_root,
|
||||
))?;
|
||||
Ok(Some(state))
|
||||
} else {
|
||||
// Try the cold DB
|
||||
@@ -553,10 +553,9 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
epoch_boundary_state_root,
|
||||
}) = self.load_hot_state_summary(state_root)?
|
||||
{
|
||||
let boundary_state = get_full_state(&self.hot_db, &epoch_boundary_state_root)?
|
||||
.ok_or_else(|| {
|
||||
HotColdDBError::MissingEpochBoundaryState(epoch_boundary_state_root)
|
||||
})?;
|
||||
let boundary_state = get_full_state(&self.hot_db, &epoch_boundary_state_root)?.ok_or(
|
||||
HotColdDBError::MissingEpochBoundaryState(epoch_boundary_state_root),
|
||||
)?;
|
||||
|
||||
// Optimization to avoid even *thinking* about replaying blocks if we're already
|
||||
// on an epoch boundary.
|
||||
@@ -682,8 +681,9 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
let high_restore_point = if high_restore_point_idx * self.config.slots_per_restore_point
|
||||
>= split.slot.as_u64()
|
||||
{
|
||||
self.get_state(&split.state_root, Some(split.slot))?
|
||||
.ok_or_else(|| HotColdDBError::MissingSplitState(split.state_root, split.slot))?
|
||||
self.get_state(&split.state_root, Some(split.slot))?.ok_or(
|
||||
HotColdDBError::MissingSplitState(split.state_root, split.slot),
|
||||
)?
|
||||
} else {
|
||||
self.load_restore_point_by_index(high_restore_point_idx)?
|
||||
};
|
||||
@@ -1019,7 +1019,7 @@ pub fn migrate_database<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>(
|
||||
|
||||
if slot % store.config.slots_per_restore_point == 0 {
|
||||
let state: BeaconState<E> = get_full_state(&store.hot_db, &state_root)?
|
||||
.ok_or_else(|| HotColdDBError::MissingStateToFreeze(state_root))?;
|
||||
.ok_or(HotColdDBError::MissingStateToFreeze(state_root))?;
|
||||
|
||||
store.store_cold_state(&state_root, &state, &mut cold_db_ops)?;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ pub fn spawn_timer<T: BeaconChainTypes>(
|
||||
+ beacon_chain
|
||||
.slot_clock
|
||||
.duration_to_next_slot()
|
||||
.ok_or_else(|| "slot_notifier unable to determine time to next slot")?;
|
||||
.ok_or("slot_notifier unable to determine time to next slot")?;
|
||||
|
||||
// Warning: `interval_at` panics if `milliseconds_per_slot` = 0.
|
||||
let mut interval = interval_at(start_instant, Duration::from_millis(milliseconds_per_slot));
|
||||
|
||||
Reference in New Issue
Block a user