Skip to content

Commit

Permalink
Fix cache initialization in block rewards API (sigp#4960)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul authored Dec 1, 2023
1 parent 9cdc4b9 commit e880d9d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
10 changes: 4 additions & 6 deletions beacon_node/beacon_chain/src/beacon_block_reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)?)?;
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions beacon_node/beacon_chain/src/canonical_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/beacon_chain/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub enum BeaconChainError {
SlotClockDidNotStart,
NoStateForSlot(Slot),
BeaconStateError(BeaconStateError),
HeadCacheError(EpochCacheError),
EpochCacheError(EpochCacheError),
DBInconsistent(String),
DBError(store::Error),
ForkChoiceError(ForkChoiceError),
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e880d9d

Please sign in to comment.