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 state_processing::{
common::{get_attestation_participation_flag_indices, get_attesting_indices_from_state},
epoch_cache::initialize_epoch_cache,
per_block_processing::{
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::Current, &self.spec)?;
initialize_epoch_cache(state, &self.spec)?;
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.add_flag(flag_index)?;
proposer_reward_numerator.safe_add_assign(
state
.get_base_reward(index)
.map_err(|_| BeaconChainError::BlockRewardAttestationError)?
.safe_mul(weight)?,
)?;
proposer_reward_numerator
.safe_add_assign(state.get_base_reward(index)?.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
// caches except the tree hash cache.
new_snapshot
.beacon_state
.build_all_caches(&self.spec)
.map_err(Error::HeadCacheError)?;
new_snapshot.beacon_state.build_all_caches(&self.spec)?;
let new_cached_head = CachedHead {
snapshot: Arc::new(new_snapshot),

View File

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