From 748475be1ded2c9a29cbd8b985f6ae2980720a36 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Mon, 4 Jul 2022 02:56:15 +0000 Subject: [PATCH] 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. --- beacon_node/http_api/src/block_rewards.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/beacon_node/http_api/src/block_rewards.rs b/beacon_node/http_api/src/block_rewards.rs index 0555037210..682828aee4 100644 --- a/beacon_node/http_api/src/block_rewards.rs +++ b/beacon_node/http_api/src/block_rewards.rs @@ -56,6 +56,8 @@ pub fn get_block_rewards( 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(), @@ -154,8 +156,13 @@ pub fn compute_block_rewards( ); } + 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()) })?