Satisfy Clippy, remove non-tree-states code

This commit is contained in:
Michael Sproul
2022-03-28 11:42:55 +11:00
parent 705cba6443
commit c5212d0f98
45 changed files with 129 additions and 1153 deletions

View File

@@ -84,7 +84,6 @@ use std::time::{Duration, Instant};
use store::iter::{BlockRootsIterator, ParentRootBlockIterator, StateRootsIterator};
use store::{Error as DBError, HotColdDB, KeyValueStore, KeyValueStoreOp, StoreItem, StoreOp};
use task_executor::ShutdownReason;
use types::beacon_state::CloneConfig;
use types::*;
pub type ForkChoiceError = fork_choice::Error<crate::ForkChoiceStoreError>;
@@ -545,12 +544,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let iter = self.store.forwards_block_roots_iterator_until(
start_slot,
end_slot,
|| {
(
head.beacon_state.clone_with_only_committee_caches(),
head.beacon_block_root,
)
},
|| (head.beacon_state.clone(), head.beacon_block_root),
&self.spec,
)?;
Ok(iter
@@ -713,12 +707,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let iter = self.store.forwards_state_roots_iterator_until(
start_slot,
end_slot,
|| {
(
head.beacon_state.clone_with_only_committee_caches(),
head.beacon_state_root(),
)
},
|| (head.beacon_state.clone(), head.beacon_state_root()),
&self.spec,
)?;
Ok(iter
@@ -993,7 +982,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// is the state as it was when the head block was received, which could be some slots prior to
/// now.
pub fn head(&self) -> Result<BeaconSnapshot<T::EthSpec>, Error> {
self.with_head(|head| Ok(head.clone_with(CloneConfig::committee_caches_only())))
self.with_head(|head| Ok(head.clone()))
}
/// Apply a function to the canonical head without cloning it.
@@ -1029,10 +1018,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
///
/// See `Self::head` for more information.
pub fn head_beacon_state(&self) -> Result<BeaconState<T::EthSpec>, Error> {
self.with_head(|s| {
Ok(s.beacon_state
.clone_with(CloneConfig::committee_caches_only()))
})
self.with_head(|s| Ok(s.beacon_state.clone()))
}
/// Return the sync committee at `slot + 1` from the canonical chain.
@@ -4209,11 +4195,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// to copy the head is liable to race-conditions.
let head_state_opt = self.with_head(|head| {
if head.beacon_block_root == head_block_root {
Ok(Some((
head.beacon_state
.clone_with(CloneConfig::committee_caches_only()),
head.beacon_state_root(),
)))
Ok(Some((head.beacon_state.clone(), head.beacon_state_root())))
} else {
Ok::<_, Error>(None)
}

View File

@@ -1,5 +1,5 @@
use serde_derive::Serialize;
use types::{beacon_state::CloneConfig, BeaconState, EthSpec, Hash256, SignedBeaconBlock};
use types::{BeaconState, EthSpec, Hash256, SignedBeaconBlock};
/// Represents some block and its associated state. Generally, this will be used for tracking the
/// head, justified head and finalized head.
@@ -57,12 +57,4 @@ impl<E: EthSpec> BeaconSnapshot<E> {
self.beacon_block_root = beacon_block_root;
self.beacon_state = beacon_state;
}
pub fn clone_with(&self, clone_config: CloneConfig) -> Self {
Self {
beacon_block: self.beacon_block.clone(),
beacon_block_root: self.beacon_block_root,
beacon_state: self.beacon_state.clone_with(clone_config),
}
}
}

View File

@@ -73,9 +73,9 @@ use std::io::Write;
use store::{Error as DBError, HotColdDB, KeyValueStore, StoreOp};
use tree_hash::TreeHash;
use types::{
BeaconBlockRef, BeaconState, BeaconStateError, ChainSpec, CloneConfig, Epoch, EthSpec,
ExecutionBlockHash, Hash256, InconsistentFork, PublicKey, PublicKeyBytes, RelativeEpoch,
SignedBeaconBlock, SignedBeaconBlockHeader, Slot,
BeaconBlockRef, BeaconState, BeaconStateError, ChainSpec, Epoch, EthSpec, ExecutionBlockHash,
Hash256, InconsistentFork, PublicKey, PublicKeyBytes, RelativeEpoch, SignedBeaconBlock,
SignedBeaconBlockHeader, Slot,
};
const POS_PANDA_BANNER: &str = r#"
@@ -1604,7 +1604,7 @@ fn cheap_state_advance_to_obtain_committees<'a, E: EthSpec>(
parent_slot: state.slot(),
})
} else {
let mut state = state.clone_with(CloneConfig::committee_caches_only());
let mut state = state.clone();
let target_slot = block_epoch.start_slot(E::slots_per_epoch());
// Advance the state into the same epoch as the block. Use the "partial" method since state

View File

@@ -18,7 +18,7 @@ fn get_summary_v1<T: BeaconChainTypes>(
state_root: Hash256,
) -> Result<HotStateSummaryV1, Error> {
db.get_item(&state_root)?
.ok_or(HotColdDBError::MissingHotStateSummary(state_root).into())
.ok_or_else(|| HotColdDBError::MissingHotStateSummary(state_root).into())
}
fn get_state_by_replay<T: BeaconChainTypes>(
@@ -30,7 +30,7 @@ fn get_state_by_replay<T: BeaconChainTypes>(
slot,
latest_block_root,
epoch_boundary_state_root,
} = get_summary_v1::<T>(&db, state_root)?;
} = get_summary_v1::<T>(db, state_root)?;
// Load full state from the epoch boundary.
let (epoch_boundary_state, _) = db.load_hot_state_full(&epoch_boundary_state_root)?;