mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 02:12:33 +00:00
Single-pass epoch processing and optimised block processing (#5279)
* Single-pass epoch processing (#4483, #4573) Co-authored-by: Michael Sproul <michael@sigmaprime.io> * Delete unused epoch processing code (#5170) * Delete unused epoch processing code * Compare total deltas * Remove unnecessary apply_pending * cargo fmt * Remove newline * Use epoch cache in block packing (#5223) * Remove progressive balances mode (#5224) * inline inactivity_penalty_quotient_for_state * drop previous_epoch_total_active_balance * fc lint * spec compliant process_sync_aggregate (#15) * spec compliant process_sync_aggregate * Update consensus/state_processing/src/per_block_processing/altair/sync_committee.rs Co-authored-by: Michael Sproul <micsproul@gmail.com> --------- Co-authored-by: Michael Sproul <micsproul@gmail.com> * Delete the participation cache (#16) * update help * Fix op_pool tests * Fix fork choice tests * Merge remote-tracking branch 'sigp/unstable' into epoch-single-pass * Simplify exit cache (#5280) * Fix clippy on exit cache * Clean up single-pass a bit (#5282) * Address Mark's review of single-pass (#5386) * Merge remote-tracking branch 'origin/unstable' into epoch-single-pass * Address Sean's review comments (#5414) * Address most of Sean's review comments * Simplify total balance cache building * Clean up unused junk * Merge remote-tracking branch 'origin/unstable' into epoch-single-pass * More self-review * Merge remote-tracking branch 'origin/unstable' into epoch-single-pass * Merge branch 'unstable' into epoch-single-pass * Fix imports for beta compiler * Fix tests, probably
This commit is contained in:
52
consensus/state_processing/src/all_caches.rs
Normal file
52
consensus/state_processing/src/all_caches.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use crate::common::update_progressive_balances_cache::initialize_progressive_balances_cache;
|
||||
use crate::epoch_cache::initialize_epoch_cache;
|
||||
use types::{BeaconState, ChainSpec, EpochCacheError, EthSpec, Hash256, RelativeEpoch};
|
||||
|
||||
/// Mixin trait for the beacon state that provides operations on *all* caches.
|
||||
///
|
||||
/// The reason this trait exists here away from `BeaconState` itself is that some caches are
|
||||
/// computed by functions in `state_processing`.
|
||||
pub trait AllCaches {
|
||||
/// Build all caches.
|
||||
///
|
||||
/// Note that this excludes the tree-hash cache. That needs to be managed separately.
|
||||
fn build_all_caches(&mut self, spec: &ChainSpec) -> Result<(), EpochCacheError>;
|
||||
|
||||
/// Return true if all caches are built.
|
||||
///
|
||||
/// Note that this excludes the tree-hash cache. That needs to be managed separately.
|
||||
fn all_caches_built(&self) -> bool;
|
||||
}
|
||||
|
||||
impl<E: EthSpec> AllCaches for BeaconState<E> {
|
||||
fn build_all_caches(&mut self, spec: &ChainSpec) -> Result<(), EpochCacheError> {
|
||||
self.build_caches(spec)?;
|
||||
initialize_epoch_cache(self, spec)?;
|
||||
initialize_progressive_balances_cache(self, spec)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn all_caches_built(&self) -> bool {
|
||||
let current_epoch = self.current_epoch();
|
||||
let Ok(epoch_cache_decision_block_root) =
|
||||
self.proposer_shuffling_decision_root(Hash256::zero())
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
self.get_total_active_balance_at_epoch(current_epoch)
|
||||
.is_ok()
|
||||
&& self.committee_cache_is_initialized(RelativeEpoch::Previous)
|
||||
&& self.committee_cache_is_initialized(RelativeEpoch::Current)
|
||||
&& self.committee_cache_is_initialized(RelativeEpoch::Next)
|
||||
&& self
|
||||
.progressive_balances_cache()
|
||||
.is_initialized_at(current_epoch)
|
||||
&& self.pubkey_cache().len() == self.validators().len()
|
||||
&& self.exit_cache().check_initialized().is_ok()
|
||||
&& self.slashings_cache_is_initialized()
|
||||
&& self
|
||||
.epoch_cache()
|
||||
.check_validity(current_epoch, epoch_cache_decision_block_root)
|
||||
.is_ok()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user