Make BeaconState.balances a tree list!

This commit is contained in:
Michael Sproul
2021-12-01 14:14:47 +11:00
parent 4b808d3c72
commit fca92c37ad
11 changed files with 76 additions and 31 deletions

View File

@@ -217,12 +217,13 @@ where
};
let finalized_checkpoint = justified_checkpoint;
// FIXME(sproul): avoid `to_vec` perf penalty
Self {
store,
balances_cache: <_>::default(),
time: anchor_state.slot(),
justified_checkpoint,
justified_balances: anchor_state.balances().clone().into(),
justified_balances: anchor_state.balances().to_vec(),
finalized_checkpoint,
best_justified_checkpoint: justified_checkpoint,
_phantom: PhantomData,
@@ -327,8 +328,7 @@ where
.map_err(Error::FailedToReadState)?
.ok_or_else(|| Error::MissingState(justified_block.state_root()))?
.balances()
.clone()
.into();
.to_vec();
}
Ok(())

View File

@@ -25,6 +25,7 @@ lighthouse_metrics = { path = "../../common/lighthouse_metrics" }
lru = "0.6.0"
sloggers = "2.0.2"
directory = { path = "../../common/directory" }
tree_hash = "0.4.0"
[features]
milhouse = ["state_processing/milhouse"]

View File

@@ -17,6 +17,7 @@
use self::UpdatePattern::*;
use crate::*;
use ssz::{Decode, Encode};
use tree_hash::TreeHash;
use typenum::Unsigned;
use types::VList;
@@ -56,7 +57,7 @@ pub trait Field<E: EthSpec>: Copy {
/// The type of value stored in this field: the `T` from `FixedVector<T, N>`.
///
/// The `Default` impl will be used to fill extra vector entries.
type Value: Decode + Encode + Default + Clone + PartialEq + std::fmt::Debug;
type Value: TreeHash + Decode + Encode + Default + Clone + PartialEq + std::fmt::Debug;
/// The length of this field: the `N` from `FixedVector<T, N>`.
type Length: Unsigned;

View File

@@ -48,7 +48,7 @@ where
// Registry
pub validators: VList<Validator, T::ValidatorRegistryLimit>,
pub balances: VariableList<u64, T::ValidatorRegistryLimit>,
pub balances: VList<u64, T::ValidatorRegistryLimit>,
// Shuffling
/// Randao value from the current slot, for patching into the per-epoch randao vector.