Utilize next slot cache in block rewards rpc #13684
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Other
What does this PR do? Why is it needed?
Consider the following function call:
This will replay blocks up to and including the block at slot
blk.Slot()-1
and then callReplayProcessSlots
to process the slot, so that the state is at slotblk.Slot()
but before integrating the block at this slot. If this slot transition is at an epoch boundary, we will need to process the epoch which is time consuming. As an example, the above code is executed when calling the/eth/v3/validator/blocks/{slot}
Beacon API endpoint to obtain the state used for calculating the block's value. While normally obtaining the value takes around 20ms, it takes over 500ms when requesting a block for slot 0.Prysm has a cache that we can use to speed things up. After processing the block at slot
blk.Slot()-1
(or when the block is late), we transition to the next slot in thenextSlotCache
and save the resulting state in the cache. Utilizing the cache results in reducing the time of slot 0 blocks to ~20ms.Supersedes #13678