Single-pass epoch processing (#4483)

This commit is contained in:
Michael Sproul
2023-07-18 16:59:55 +10:00
committed by GitHub
parent 079cd67df2
commit 5d2063d262
42 changed files with 1558 additions and 730 deletions

View File

@@ -4299,6 +4299,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let attestation_packing_timer =
metrics::start_timer(&metrics::BLOCK_PRODUCTION_ATTESTATION_TIMES);
state.build_total_active_balance_cache_at(state.current_epoch(), &self.spec)?;
let mut prev_filter_cache = HashMap::new();
let prev_attestation_filter = |att: &AttestationRef<T::EthSpec>| {
self.filter_op_pool_attestation(&mut prev_filter_cache, att, &state)

View File

@@ -78,7 +78,7 @@ use state_processing::{
block_signature_verifier::{BlockSignatureVerifier, Error as BlockSignatureVerifierError},
per_block_processing, per_slot_processing,
state_advance::partial_state_advance,
BlockProcessingError, BlockSignatureStrategy, ConsensusContext, SlotProcessingError,
AllCaches, BlockProcessingError, BlockSignatureStrategy, ConsensusContext, SlotProcessingError,
StateProcessingStrategy, VerifyBlockRoot,
};
use std::borrow::Cow;
@@ -1712,6 +1712,15 @@ fn load_parent<T: BeaconChainTypes>(
BeaconChainError::DBInconsistent(format!("Missing state {:?}", parent_state_root))
})?;
if !state.all_caches_built() {
slog::warn!(
chain.log,
"Parent state lacks built caches";
"block_slot" => block.slot(),
"state_slot" => state.slot(),
);
}
if block.slot() != state.slot() {
slog::warn!(
chain.log,

View File

@@ -24,6 +24,7 @@ use proto_array::{DisallowedReOrgOffsets, ReOrgThreshold};
use slasher::Slasher;
use slog::{crit, error, info, Logger};
use slot_clock::{SlotClock, TestingSlotClock};
use state_processing::AllCaches;
use std::marker::PhantomData;
use std::sync::Arc;
use std::time::Duration;
@@ -447,7 +448,7 @@ where
// Prime all caches before storing the state in the database and computing the tree hash
// root.
weak_subj_state
.build_caches(&self.spec)
.build_all_caches(&self.spec)
.map_err(|e| format!("Error building caches on checkpoint state: {e:?}"))?;
let computed_state_root = weak_subj_state

View File

@@ -50,6 +50,7 @@ use itertools::process_results;
use parking_lot::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};
use slog::{crit, debug, error, warn, Logger};
use slot_clock::SlotClock;
use state_processing::AllCaches;
use std::sync::Arc;
use std::time::Duration;
use store::{iter::StateRootsIterator, KeyValueStoreOp, StoreItem};
@@ -666,7 +667,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// Regardless of where we got the state from, attempt to build all the
// caches except the tree hash cache.
new_snapshot.beacon_state.build_caches(&self.spec)?;
new_snapshot
.beacon_state
.build_all_caches(&self.spec)
.map_err(Error::HeadCacheError)?;
let new_cached_head = CachedHead {
snapshot: Arc::new(new_snapshot),

View File

@@ -53,6 +53,7 @@ pub enum BeaconChainError {
SlotClockDidNotStart,
NoStateForSlot(Slot),
BeaconStateError(BeaconStateError),
HeadCacheError(EpochCacheError),
DBInconsistent(String),
DBError(store::Error),
ForkChoiceError(ForkChoiceError),