mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-22 06:14:38 +00:00
Update state_processing
This commit is contained in:
@@ -47,7 +47,11 @@ mod tree_hash_cache;
|
||||
|
||||
#[cfg(feature = "milhouse")]
|
||||
pub type ListMut<'a, T, N> = Interface<T, &'a mut List<T, N>>;
|
||||
|
||||
#[cfg(feature = "milhouse")]
|
||||
pub type ValidatorsMut<'a, N> = ListMut<'a, Validator, N>;
|
||||
#[cfg(not(feature = "milhouse"))]
|
||||
pub type ValidatorsMut<'a, N> = &'a mut VList<Validator, N>;
|
||||
|
||||
pub const CACHED_EPOCHS: usize = 3;
|
||||
const MAX_RANDOM_BYTE: u64 = (1 << 8) - 1;
|
||||
@@ -240,6 +244,7 @@ where
|
||||
pub eth1_deposit_index: u64,
|
||||
|
||||
// Registry
|
||||
#[superstruct(getter(rename = "validators_raw"))]
|
||||
#[test_random(default)]
|
||||
pub validators: VList<Validator, T::ValidatorRegistryLimit>,
|
||||
#[compare_fields(as_slice)]
|
||||
@@ -1096,19 +1101,32 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn validators(&self) -> &VList<Validator, T::ValidatorRegistryLimit> {
|
||||
self.validators_raw()
|
||||
}
|
||||
|
||||
pub fn validators_mut(&mut self) -> ValidatorsMut<T::ValidatorRegistryLimit> {
|
||||
#[cfg(not(feature = "milhouse"))]
|
||||
{
|
||||
self.validators_raw_mut()
|
||||
}
|
||||
#[cfg(feature = "milhouse")]
|
||||
{
|
||||
self.validators_raw_mut().as_mut()
|
||||
}
|
||||
}
|
||||
|
||||
/// Convenience accessor for validators and balances simultaneously.
|
||||
#[cfg(not(feature = "milhouse"))]
|
||||
pub fn validators_and_balances_mut(&mut self) -> (&mut [Validator], &mut [u64]) {
|
||||
pub fn validators_and_balances_mut(
|
||||
&mut self,
|
||||
) -> (ValidatorsMut<T::ValidatorRegistryLimit>, &mut [u64]) {
|
||||
#[cfg(not(feature = "milhouse"))]
|
||||
match self {
|
||||
BeaconState::Base(state) => (&mut state.validators, &mut state.balances),
|
||||
BeaconState::Altair(state) => (&mut state.validators, &mut state.balances),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "milhouse")]
|
||||
pub fn validators_and_balances_mut(
|
||||
&mut self,
|
||||
) -> (ValidatorsMut<T::ValidatorRegistryLimit>, &mut [u64]) {
|
||||
#[cfg(feature = "milhouse")]
|
||||
match self {
|
||||
BeaconState::Base(state) => (state.validators.as_mut(), &mut state.balances),
|
||||
BeaconState::Altair(state) => (state.validators.as_mut(), &mut state.balances),
|
||||
|
||||
@@ -64,6 +64,7 @@ pub mod voluntary_exit;
|
||||
pub mod slot_epoch_macros;
|
||||
pub mod config_and_preset;
|
||||
pub mod fork_context;
|
||||
pub mod mixin;
|
||||
pub mod participation_flags;
|
||||
pub mod participation_list;
|
||||
pub mod preset;
|
||||
@@ -117,6 +118,7 @@ pub use crate::free_attestation::FreeAttestation;
|
||||
pub use crate::graffiti::{Graffiti, GRAFFITI_BYTES_LEN};
|
||||
pub use crate::historical_batch::HistoricalBatch;
|
||||
pub use crate::indexed_attestation::IndexedAttestation;
|
||||
pub use crate::mixin::GetValidatorMut;
|
||||
pub use crate::participation_flags::ParticipationFlags;
|
||||
pub use crate::participation_list::ParticipationList;
|
||||
pub use crate::pending_attestation::PendingAttestation;
|
||||
@@ -159,3 +161,6 @@ pub use bls::{
|
||||
};
|
||||
pub use ssz_types::{typenum, typenum::Unsigned, BitList, BitVector, FixedVector, VariableList};
|
||||
pub use superstruct::superstruct;
|
||||
|
||||
#[cfg(feature = "milhouse")]
|
||||
pub use milhouse::{self, prelude::*};
|
||||
|
||||
18
consensus/types/src/mixin.rs
Normal file
18
consensus/types/src/mixin.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use crate::beacon_state::{Error, ValidatorsMut};
|
||||
use crate::{Unsigned, Validator};
|
||||
|
||||
pub trait GetValidatorMut {
|
||||
fn get_validator(&self, index: usize) -> Result<&Validator, Error>;
|
||||
|
||||
fn get_validator_mut(&mut self, index: usize) -> Result<&mut Validator, Error>;
|
||||
}
|
||||
|
||||
impl<'a, N: Unsigned> GetValidatorMut for ValidatorsMut<'a, N> {
|
||||
fn get_validator(&self, index: usize) -> Result<&Validator, Error> {
|
||||
self.get(index).ok_or(Error::UnknownValidator(index))
|
||||
}
|
||||
|
||||
fn get_validator_mut(&mut self, index: usize) -> Result<&mut Validator, Error> {
|
||||
self.get_mut(index).ok_or(Error::UnknownValidator(index))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user