Fix cache initialization in block rewards API (#4960)

This commit is contained in:
Michael Sproul
2023-12-01 11:06:27 +11:00
committed by GitHub
parent 9cdc4b989a
commit e880d9db50
3 changed files with 7 additions and 11 deletions

View File

@@ -5,6 +5,7 @@ use safe_arith::SafeArith;
use slog::error; use slog::error;
use state_processing::{ use state_processing::{
common::{get_attestation_participation_flag_indices, get_attesting_indices_from_state}, common::{get_attestation_participation_flag_indices, get_attesting_indices_from_state},
epoch_cache::initialize_epoch_cache,
per_block_processing::{ per_block_processing::{
altair::sync_committee::compute_sync_aggregate_rewards, get_slashable_indices, altair::sync_committee::compute_sync_aggregate_rewards, get_slashable_indices,
}, },
@@ -30,6 +31,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
state.build_committee_cache(RelativeEpoch::Previous, &self.spec)?; state.build_committee_cache(RelativeEpoch::Previous, &self.spec)?;
state.build_committee_cache(RelativeEpoch::Current, &self.spec)?; state.build_committee_cache(RelativeEpoch::Current, &self.spec)?;
initialize_epoch_cache(state, &self.spec)?;
self.compute_beacon_block_reward_with_cache(block, block_root, state) self.compute_beacon_block_reward_with_cache(block, block_root, state)
} }
@@ -229,12 +231,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
&& !validator_participation.has_flag(flag_index)? && !validator_participation.has_flag(flag_index)?
{ {
validator_participation.add_flag(flag_index)?; validator_participation.add_flag(flag_index)?;
proposer_reward_numerator.safe_add_assign( proposer_reward_numerator
state .safe_add_assign(state.get_base_reward(index)?.safe_mul(weight)?)?;
.get_base_reward(index)
.map_err(|_| BeaconChainError::BlockRewardAttestationError)?
.safe_mul(weight)?,
)?;
} }
} }
} }

View File

@@ -672,10 +672,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// Regardless of where we got the state from, attempt to build all the // Regardless of where we got the state from, attempt to build all the
// caches except the tree hash cache. // caches except the tree hash cache.
new_snapshot new_snapshot.beacon_state.build_all_caches(&self.spec)?;
.beacon_state
.build_all_caches(&self.spec)
.map_err(Error::HeadCacheError)?;
let new_cached_head = CachedHead { let new_cached_head = CachedHead {
snapshot: Arc::new(new_snapshot), snapshot: Arc::new(new_snapshot),

View File

@@ -55,7 +55,7 @@ pub enum BeaconChainError {
SlotClockDidNotStart, SlotClockDidNotStart,
NoStateForSlot(Slot), NoStateForSlot(Slot),
BeaconStateError(BeaconStateError), BeaconStateError(BeaconStateError),
HeadCacheError(EpochCacheError), EpochCacheError(EpochCacheError),
DBInconsistent(String), DBInconsistent(String),
DBError(store::Error), DBError(store::Error),
ForkChoiceError(ForkChoiceError), ForkChoiceError(ForkChoiceError),
@@ -246,6 +246,7 @@ easy_from_to!(StateAdvanceError, BeaconChainError);
easy_from_to!(BlockReplayError, BeaconChainError); easy_from_to!(BlockReplayError, BeaconChainError);
easy_from_to!(InconsistentFork, BeaconChainError); easy_from_to!(InconsistentFork, BeaconChainError);
easy_from_to!(AvailabilityCheckError, BeaconChainError); easy_from_to!(AvailabilityCheckError, BeaconChainError);
easy_from_to!(EpochCacheError, BeaconChainError);
#[derive(Debug)] #[derive(Debug)]
pub enum BlockProductionError { pub enum BlockProductionError {