Plumb reward cache through reward calc

This commit is contained in:
Michael Sproul
2022-07-18 16:02:42 +10:00
parent 830f8032f0
commit 092d228078
7 changed files with 28 additions and 13 deletions

View File

@@ -52,6 +52,7 @@ pub fn get_block_rewards<T: BeaconChainTypes>(
.build_all_caches(&chain.spec)
.map_err(beacon_state_error)?;
let mut reward_cache = Default::default();
let mut block_rewards = Vec::with_capacity(blocks.len());
let block_replayer = BlockReplayer::new(state, &chain.spec)
@@ -63,6 +64,7 @@ pub fn get_block_rewards<T: BeaconChainTypes>(
block.message(),
block.canonical_root(),
state,
&mut reward_cache,
query.include_attestations,
)?;
block_rewards.push(block_reward);
@@ -100,6 +102,7 @@ pub fn compute_block_rewards<T: BeaconChainTypes>(
) -> Result<Vec<BlockReward>, warp::Rejection> {
let mut block_rewards = Vec::with_capacity(blocks.len());
let mut state_cache = LruCache::new(STATE_CACHE_SIZE);
let mut reward_cache = Default::default();
for block in blocks {
let parent_root = block.parent_root();
@@ -170,7 +173,13 @@ pub fn compute_block_rewards<T: BeaconChainTypes>(
// Compute block reward.
let block_reward = chain
.compute_block_reward(block.to_ref(), block.canonical_root(), state, true)
.compute_block_reward(
block.to_ref(),
block.canonical_root(),
state,
&mut reward_cache,
true,
)
.map_err(beacon_chain_error)?;
block_rewards.push(block_reward);
}