mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 04:01:51 +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:
@@ -4,12 +4,17 @@ use crate::case_result::compare_beacon_state_results_without_caches;
|
||||
use crate::decode::{ssz_decode_state, yaml_decode_file};
|
||||
use crate::type_name;
|
||||
use serde::Deserialize;
|
||||
use state_processing::common::update_progressive_balances_cache::initialize_progressive_balances_cache;
|
||||
use state_processing::epoch_cache::initialize_epoch_cache;
|
||||
use state_processing::per_epoch_processing::capella::process_historical_summaries_update;
|
||||
use state_processing::per_epoch_processing::effective_balance_updates::process_effective_balance_updates;
|
||||
use state_processing::per_epoch_processing::effective_balance_updates::{
|
||||
process_effective_balance_updates, process_effective_balance_updates_slow,
|
||||
};
|
||||
use state_processing::per_epoch_processing::{
|
||||
altair, base,
|
||||
historical_roots_update::process_historical_roots_update,
|
||||
process_registry_updates, process_slashings,
|
||||
process_registry_updates, process_registry_updates_slow, process_slashings,
|
||||
process_slashings_slow,
|
||||
resets::{process_eth1_data_reset, process_randao_mixes_reset, process_slashings_reset},
|
||||
};
|
||||
use state_processing::EpochProcessingError;
|
||||
@@ -104,11 +109,9 @@ impl<E: EthSpec> EpochTransition<E> for JustificationAndFinalization {
|
||||
| BeaconState::Capella(_)
|
||||
| BeaconState::Deneb(_)
|
||||
| BeaconState::Electra(_) => {
|
||||
initialize_progressive_balances_cache(state, spec)?;
|
||||
let justification_and_finalization_state =
|
||||
altair::process_justification_and_finalization(
|
||||
state,
|
||||
&altair::ParticipationCache::new(state, spec).unwrap(),
|
||||
)?;
|
||||
altair::process_justification_and_finalization(state)?;
|
||||
justification_and_finalization_state.apply_changes_to_state(state);
|
||||
Ok(())
|
||||
}
|
||||
@@ -128,18 +131,20 @@ impl<E: EthSpec> EpochTransition<E> for RewardsAndPenalties {
|
||||
| BeaconState::Merge(_)
|
||||
| BeaconState::Capella(_)
|
||||
| BeaconState::Deneb(_)
|
||||
| BeaconState::Electra(_) => altair::process_rewards_and_penalties(
|
||||
state,
|
||||
&altair::ParticipationCache::new(state, spec).unwrap(),
|
||||
spec,
|
||||
),
|
||||
| BeaconState::Electra(_) => altair::process_rewards_and_penalties_slow(state, spec),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> EpochTransition<E> for RegistryUpdates {
|
||||
fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> {
|
||||
process_registry_updates(state, spec)
|
||||
initialize_epoch_cache(state, spec)?;
|
||||
|
||||
if let BeaconState::Base(_) = state {
|
||||
process_registry_updates(state, spec)
|
||||
} else {
|
||||
process_registry_updates_slow(state, spec)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,13 +165,7 @@ impl<E: EthSpec> EpochTransition<E> for Slashings {
|
||||
| BeaconState::Capella(_)
|
||||
| BeaconState::Deneb(_)
|
||||
| BeaconState::Electra(_) => {
|
||||
process_slashings(
|
||||
state,
|
||||
altair::ParticipationCache::new(state, spec)
|
||||
.unwrap()
|
||||
.current_epoch_total_active_balance(),
|
||||
spec,
|
||||
)?;
|
||||
process_slashings_slow(state, spec)?;
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
@@ -181,7 +180,11 @@ impl<E: EthSpec> EpochTransition<E> for Eth1DataReset {
|
||||
|
||||
impl<E: EthSpec> EpochTransition<E> for EffectiveBalanceUpdates {
|
||||
fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> {
|
||||
process_effective_balance_updates(state, None, spec)
|
||||
if let BeaconState::Base(_) = state {
|
||||
process_effective_balance_updates(state, spec)
|
||||
} else {
|
||||
process_effective_balance_updates_slow(state, spec)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,11 +253,7 @@ impl<E: EthSpec> EpochTransition<E> for InactivityUpdates {
|
||||
| BeaconState::Merge(_)
|
||||
| BeaconState::Capella(_)
|
||||
| BeaconState::Deneb(_)
|
||||
| BeaconState::Electra(_) => altair::process_inactivity_updates(
|
||||
state,
|
||||
&altair::ParticipationCache::new(state, spec).unwrap(),
|
||||
spec,
|
||||
),
|
||||
| BeaconState::Electra(_) => altair::process_inactivity_updates_slow(state, spec),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -328,17 +327,20 @@ impl<E: EthSpec, T: EpochTransition<E>> Case for EpochProcessing<E, T> {
|
||||
fn result(&self, _case_index: usize, fork_name: ForkName) -> Result<(), Error> {
|
||||
self.metadata.bls_setting.unwrap_or_default().check()?;
|
||||
|
||||
let mut state = self.pre.clone();
|
||||
let spec = &testing_spec::<E>(fork_name);
|
||||
let mut pre_state = self.pre.clone();
|
||||
|
||||
// Processing requires the committee caches.
|
||||
pre_state.build_all_committee_caches(spec).unwrap();
|
||||
|
||||
let mut state = pre_state.clone();
|
||||
let mut expected = self.post.clone();
|
||||
|
||||
let spec = &testing_spec::<E>(fork_name);
|
||||
if let Some(post_state) = expected.as_mut() {
|
||||
post_state.build_all_committee_caches(spec).unwrap();
|
||||
}
|
||||
|
||||
let mut result = (|| {
|
||||
// Processing requires the committee caches.
|
||||
state.build_all_committee_caches(spec)?;
|
||||
|
||||
T::run(&mut state, spec).map(|_| state)
|
||||
})();
|
||||
let mut result = T::run(&mut state, spec).map(|_| state);
|
||||
|
||||
compare_beacon_state_results_without_caches(&mut result, &mut expected)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user