Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilize next slot cache in block rewards rpc #13684

Merged
merged 6 commits into from
Mar 25, 2024
Merged

Conversation

rkapka
Copy link
Contributor

@rkapka rkapka commented Mar 4, 2024

What type of PR is this?

Other

What does this PR do? Why is it needed?

Consider the following function call:

stategen.ReplayerBuilder.ReplayerForSlot(blk.Slot()-1).ReplayToSlot(ctx, blk.Slot())

This will replay blocks up to and including the block at slot blk.Slot()-1 and then call ReplayProcessSlots to process the slot, so that the state is at slot blk.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 the nextSlotCache and save the resulting state in the cache. Utilizing the cache results in reducing the time of slot 0 blocks to ~20ms.

Supersedes #13678

@rkapka rkapka added Ready For Review A pull request ready for code review API Api related tasks labels Mar 4, 2024
@rkapka rkapka requested a review from a team as a code owner March 4, 2024 15:10
Copy link
Contributor

@saolyn saolyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rkapka rkapka enabled auto-merge March 25, 2024 08:40
@rkapka rkapka added this pull request to the merge queue Mar 25, 2024
Merged via the queue into develop with commit 6782df9 Mar 25, 2024
16 of 17 checks passed
@rkapka rkapka deleted the nsc-block-rewards branch March 25, 2024 09:03
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Api related tasks Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants