mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 17:26:04 +00:00
More tree fields, fix bugs
This commit is contained in:
@@ -67,9 +67,9 @@ where
|
|||||||
|
|
||||||
// Participation (Altair and later)
|
// Participation (Altair and later)
|
||||||
#[superstruct(only(Altair, Merge))]
|
#[superstruct(only(Altair, Merge))]
|
||||||
pub previous_epoch_participation: VariableList<ParticipationFlags, T::ValidatorRegistryLimit>,
|
pub previous_epoch_participation: VList<ParticipationFlags, T::ValidatorRegistryLimit>,
|
||||||
#[superstruct(only(Altair, Merge))]
|
#[superstruct(only(Altair, Merge))]
|
||||||
pub current_epoch_participation: VariableList<ParticipationFlags, T::ValidatorRegistryLimit>,
|
pub current_epoch_participation: VList<ParticipationFlags, T::ValidatorRegistryLimit>,
|
||||||
|
|
||||||
// Finality
|
// Finality
|
||||||
pub justification_bits: BitVector<T::JustificationBitsLength>,
|
pub justification_bits: BitVector<T::JustificationBitsLength>,
|
||||||
|
|||||||
@@ -23,4 +23,11 @@ lazy_static! {
|
|||||||
"beacon_participation_prev_epoch_active_gwei_total",
|
"beacon_participation_prev_epoch_active_gwei_total",
|
||||||
"Total effective balance (gwei) of validators active in the previous epoch"
|
"Total effective balance (gwei) of validators active in the previous epoch"
|
||||||
);
|
);
|
||||||
|
/*
|
||||||
|
* Processing metrics
|
||||||
|
*/
|
||||||
|
pub static ref PROCESS_EPOCH_TIME: Result<Histogram> = try_create_histogram(
|
||||||
|
"beacon_state_processing_process_epoch",
|
||||||
|
"Time required for process_epoch",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#![deny(clippy::wildcard_imports)]
|
#![deny(clippy::wildcard_imports)]
|
||||||
|
|
||||||
|
use crate::metrics;
|
||||||
pub use epoch_processing_summary::EpochProcessingSummary;
|
pub use epoch_processing_summary::EpochProcessingSummary;
|
||||||
use errors::EpochProcessingError as Error;
|
use errors::EpochProcessingError as Error;
|
||||||
pub use registry_updates::process_registry_updates;
|
pub use registry_updates::process_registry_updates;
|
||||||
@@ -28,6 +29,8 @@ pub fn process_epoch<T: EthSpec>(
|
|||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<EpochProcessingSummary<T>, Error> {
|
) -> Result<EpochProcessingSummary<T>, Error> {
|
||||||
|
let _timer = metrics::start_timer(&metrics::PROCESS_EPOCH_TIME);
|
||||||
|
|
||||||
// Verify that the `BeaconState` instantiation matches the fork at `state.slot()`.
|
// Verify that the `BeaconState` instantiation matches the fork at `state.slot()`.
|
||||||
state
|
state
|
||||||
.fork_name(spec)
|
.fork_name(spec)
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
use crate::EpochProcessingError;
|
use crate::EpochProcessingError;
|
||||||
use core::result::Result;
|
|
||||||
use core::result::Result::Ok;
|
|
||||||
use types::beacon_state::BeaconState;
|
use types::beacon_state::BeaconState;
|
||||||
use types::eth_spec::EthSpec;
|
use types::eth_spec::EthSpec;
|
||||||
use types::participation_flags::ParticipationFlags;
|
use types::participation_flags::ParticipationFlags;
|
||||||
use types::VariableList;
|
use types::VList;
|
||||||
|
|
||||||
pub fn process_participation_flag_updates<T: EthSpec>(
|
pub fn process_participation_flag_updates<T: EthSpec>(
|
||||||
state: &mut BeaconState<T>,
|
state: &mut BeaconState<T>,
|
||||||
) -> Result<(), EpochProcessingError> {
|
) -> Result<(), EpochProcessingError> {
|
||||||
*state.previous_epoch_participation_mut()? =
|
*state.previous_epoch_participation_mut()? =
|
||||||
std::mem::take(state.current_epoch_participation_mut()?);
|
std::mem::take(state.current_epoch_participation_mut()?);
|
||||||
*state.current_epoch_participation_mut()? = VariableList::new(vec![
|
*state.current_epoch_participation_mut()? = VList::new(vec![
|
||||||
ParticipationFlags::default(
|
ParticipationFlags::default();
|
||||||
);
|
|
||||||
state.validators().len()
|
state.validators().len()
|
||||||
])?;
|
])?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pub fn process_historical_roots_update<T: EthSpec>(
|
|||||||
.safe_rem(T::SlotsPerHistoricalRoot::to_u64().safe_div(T::slots_per_epoch())?)?
|
.safe_rem(T::SlotsPerHistoricalRoot::to_u64().safe_div(T::slots_per_epoch())?)?
|
||||||
== 0
|
== 0
|
||||||
{
|
{
|
||||||
let historical_batch = state.historical_batch();
|
let historical_batch = state.historical_batch()?;
|
||||||
state
|
state
|
||||||
.historical_roots_mut()
|
.historical_roots_mut()
|
||||||
.push(historical_batch.tree_hash_root())?;
|
.push(historical_batch.tree_hash_root())?;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::mem;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{
|
use types::{
|
||||||
BeaconState, BeaconStateAltair, BeaconStateError as Error, ChainSpec, EthSpec, Fork,
|
BeaconState, BeaconStateAltair, BeaconStateError as Error, ChainSpec, EthSpec, Fork,
|
||||||
ParticipationFlags, PendingAttestation, RelativeEpoch, SyncCommittee, VList, VariableList,
|
ParticipationFlags, PendingAttestation, RelativeEpoch, SyncCommittee, VList,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Translate the participation information from the epoch prior to the fork into Altair's format.
|
/// Translate the participation information from the epoch prior to the fork into Altair's format.
|
||||||
@@ -50,7 +50,7 @@ pub fn upgrade_to_altair<E: EthSpec>(
|
|||||||
let pre = pre_state.as_base_mut()?;
|
let pre = pre_state.as_base_mut()?;
|
||||||
|
|
||||||
let default_epoch_participation =
|
let default_epoch_participation =
|
||||||
VariableList::new(vec![ParticipationFlags::default(); pre.validators.len()])?;
|
VList::new(vec![ParticipationFlags::default(); pre.validators.len()])?;
|
||||||
let inactivity_scores = VList::new(vec![0; pre.validators.len()])?;
|
let inactivity_scores = VList::new(vec![0; pre.validators.len()])?;
|
||||||
|
|
||||||
let temp_sync_committee = Arc::new(SyncCommittee::temporary()?);
|
let temp_sync_committee = Arc::new(SyncCommittee::temporary()?);
|
||||||
|
|||||||
@@ -269,9 +269,11 @@ where
|
|||||||
|
|
||||||
// Participation (Altair and later)
|
// Participation (Altair and later)
|
||||||
#[superstruct(only(Altair, Merge))]
|
#[superstruct(only(Altair, Merge))]
|
||||||
pub previous_epoch_participation: VariableList<ParticipationFlags, T::ValidatorRegistryLimit>,
|
#[test_random(default)]
|
||||||
|
pub previous_epoch_participation: VList<ParticipationFlags, T::ValidatorRegistryLimit>,
|
||||||
#[superstruct(only(Altair, Merge))]
|
#[superstruct(only(Altair, Merge))]
|
||||||
pub current_epoch_participation: VariableList<ParticipationFlags, T::ValidatorRegistryLimit>,
|
#[test_random(default)]
|
||||||
|
pub current_epoch_participation: VList<ParticipationFlags, T::ValidatorRegistryLimit>,
|
||||||
|
|
||||||
// Finality
|
// Finality
|
||||||
#[test_random(default)]
|
#[test_random(default)]
|
||||||
@@ -454,11 +456,15 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
Hash256::from_slice(&self.tree_hash_root()[..])
|
Hash256::from_slice(&self.tree_hash_root()[..])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn historical_batch(&self) -> HistoricalBatch<T> {
|
pub fn historical_batch(&mut self) -> Result<HistoricalBatch<T>, Error> {
|
||||||
HistoricalBatch {
|
// FIXME(sproul): work out how to clean this up (internal mutability?)
|
||||||
|
self.block_roots_mut().apply_updates()?;
|
||||||
|
self.state_roots_mut().apply_updates()?;
|
||||||
|
|
||||||
|
Ok(HistoricalBatch {
|
||||||
block_roots: self.block_roots().clone(),
|
block_roots: self.block_roots().clone(),
|
||||||
state_roots: self.state_roots().clone(),
|
state_roots: self.state_roots().clone(),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method ensures the state's pubkey cache is fully up-to-date before checking if the validator
|
/// This method ensures the state's pubkey cache is fully up-to-date before checking if the validator
|
||||||
@@ -1339,7 +1345,7 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
pub fn get_epoch_participation_mut(
|
pub fn get_epoch_participation_mut(
|
||||||
&mut self,
|
&mut self,
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
) -> Result<&mut VariableList<ParticipationFlags, T::ValidatorRegistryLimit>, Error> {
|
) -> Result<&mut VList<ParticipationFlags, T::ValidatorRegistryLimit>, Error> {
|
||||||
if epoch == self.current_epoch() {
|
if epoch == self.current_epoch() {
|
||||||
match self {
|
match self {
|
||||||
BeaconState::Base(_) => Err(BeaconStateError::IncorrectStateVariant),
|
BeaconState::Base(_) => Err(BeaconStateError::IncorrectStateVariant),
|
||||||
@@ -1576,22 +1582,7 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
*self.pubkey_cache_mut() = PubkeyCache::default()
|
*self.pubkey_cache_mut() = PubkeyCache::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if the `BeaconState` has any pending mutations.
|
// FIXME(sproul): automate this somehow
|
||||||
pub fn has_pending_mutations(&self) -> bool {
|
|
||||||
// FIXME(sproul): check this more thoroughly
|
|
||||||
self.block_roots().has_pending_updates()
|
|
||||||
|| self.state_roots().has_pending_updates()
|
|
||||||
|| self.historical_roots().has_pending_updates()
|
|
||||||
|| self.eth1_data_votes().has_pending_updates()
|
|
||||||
|| self.validators().has_pending_updates()
|
|
||||||
|| self.balances().has_pending_updates()
|
|
||||||
|| self.randao_mixes().has_pending_updates()
|
|
||||||
|| self.slashings().has_pending_updates()
|
|
||||||
|| self
|
|
||||||
.inactivity_scores()
|
|
||||||
.map_or(false, VList::has_pending_updates)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn apply_pending_mutations(&mut self) -> Result<(), Error> {
|
pub fn apply_pending_mutations(&mut self) -> Result<(), Error> {
|
||||||
self.block_roots_mut().apply_updates()?;
|
self.block_roots_mut().apply_updates()?;
|
||||||
self.state_roots_mut().apply_updates()?;
|
self.state_roots_mut().apply_updates()?;
|
||||||
@@ -1605,6 +1596,12 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
if let Ok(inactivity_scores) = self.inactivity_scores_mut() {
|
if let Ok(inactivity_scores) = self.inactivity_scores_mut() {
|
||||||
inactivity_scores.apply_updates()?;
|
inactivity_scores.apply_updates()?;
|
||||||
}
|
}
|
||||||
|
if let Ok(previous_epoch_participation) = self.previous_epoch_participation_mut() {
|
||||||
|
previous_epoch_participation.apply_updates()?;
|
||||||
|
}
|
||||||
|
if let Ok(current_epoch_participation) = self.current_epoch_participation_mut() {
|
||||||
|
current_epoch_participation.apply_updates()?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user