mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 08:52:54 +00:00
Ensure caches are built for block_rewards POST API (#3305)
## Issue Addressed Follow up to https://github.com/sigp/lighthouse/pull/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.
This commit is contained in:
@@ -56,6 +56,8 @@ pub fn get_block_rewards<T: BeaconChainTypes>(
|
|||||||
|
|
||||||
let block_replayer = BlockReplayer::new(state, &chain.spec)
|
let block_replayer = BlockReplayer::new(state, &chain.spec)
|
||||||
.pre_block_hook(Box::new(|state, block| {
|
.pre_block_hook(Box::new(|state, block| {
|
||||||
|
state.build_all_committee_caches(&chain.spec)?;
|
||||||
|
|
||||||
// Compute block reward.
|
// Compute block reward.
|
||||||
let block_reward = chain.compute_block_reward(
|
let block_reward = chain.compute_block_reward(
|
||||||
block.message(),
|
block.message(),
|
||||||
@@ -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
|
state_cache
|
||||||
.get_or_insert((parent_root, block.slot()), || block_replayer.into_state())
|
.get_or_insert((parent_root, block.slot()), || state)
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
custom_server_error("LRU cache insert should always succeed".into())
|
custom_server_error("LRU cache insert should always succeed".into())
|
||||||
})?
|
})?
|
||||||
|
|||||||
Reference in New Issue
Block a user