Skip to content

Commit

Permalink
Ensure caches are built for block_rewards POST API (sigp#3305)
Browse files Browse the repository at this point in the history
## Issue Addressed

Follow up to sigp#3290 that fixes a caching bug

## Proposed Changes

Build the committee cache for the new `POST /lighthouse/analysis/block_rewards` API. Due to an unusual quirk of the total active balance cache the API endpoint would sometimes fail after loading a state from disk which had a current epoch cache _but not_  a total active balance cache. This PR adds calls to build the caches immediately before they're required, and has been running smoothly with `blockdreamer` the last few days.
  • Loading branch information
michaelsproul committed Jul 4, 2022
1 parent 1cc8a97 commit 748475b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion beacon_node/http_api/src/block_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub fn get_block_rewards<T: BeaconChainTypes>(

let block_replayer = BlockReplayer::new(state, &chain.spec)
.pre_block_hook(Box::new(|state, block| {
state.build_all_committee_caches(&chain.spec)?;

// Compute block reward.
let block_reward = chain.compute_block_reward(
block.message(),
Expand Down Expand Up @@ -154,8 +156,13 @@ pub fn compute_block_rewards<T: BeaconChainTypes>(
);
}

let mut state = block_replayer.into_state();
state
.build_all_committee_caches(&chain.spec)
.map_err(beacon_state_error)?;

state_cache
.get_or_insert((parent_root, block.slot()), || block_replayer.into_state())
.get_or_insert((parent_root, block.slot()), || state)
.ok_or_else(|| {
custom_server_error("LRU cache insert should always succeed".into())
})?
Expand Down

0 comments on commit 748475b

Please sign in to comment.