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 the state replayer #13678

Closed
wants to merge 8 commits into from

Conversation

rkapka
Copy link
Contributor

@rkapka rkapka commented Feb 28, 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. This means that we don't have to process to the next slot in the replayer because the state is already available to us. Utilizing the cache results in reducing the time of slot 0 blocks to ~20ms.

@rkapka rkapka added the Ready For Review A pull request ready for code review label Feb 28, 2024
@rkapka rkapka changed the title Replayer next slot cache Utilize next slot cache in the state replayer Feb 28, 2024
@james-prysm james-prysm added Blocked Blocked by research or external factors and removed Blocked Blocked by research or external factors labels Feb 28, 2024
@@ -146,6 +148,16 @@ func (rs *stateReplayer) ReplayToSlot(ctx context.Context, replayTo primitives.S
return s, nil
}

r, err := rs.chainer.BlockRootForSlot(ctx, s.Slot())
if err != nil && !errors.Is(err, ErrNoCanonicalBlockForSlot) {
Copy link
Contributor

Choose a reason for hiding this comment

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

wait what happens if it is ErrNoCanonicalBlockForSlot? then it just keeps going fine without the next slot state?

@rkapka
Copy link
Contributor Author

rkapka commented Mar 4, 2024

Superseded by #13684

@rkapka rkapka closed this Mar 4, 2024
@rkapka rkapka deleted the replayer-next-slot-cache branch March 5, 2024 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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