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

Batch Reconstruction Of Bellatrix Blocks #11210

Merged
merged 15 commits into from
Aug 15, 2022
Merged

Conversation

nisdas
Copy link
Member

@nisdas nisdas commented Aug 12, 2022

What type of PR is this?

Feature Improvement

What does this PR do? Why is it needed?

For nodes running with blinded blocks enabled, they have to request the payloads from the execution client before
being able to respond to the remote peer who requested the block range.

However currently prysm does sequential json-rpc requests for each block requested from the execution node. This is an extremely inefficient method as we have to wait for geth to marshal and prysm to unmarshal the payload before we can proceed to the next block. With addition to network latency between the consensus and execution client, timeouts can frequently occur due to how we request payloads from the execution client.

This PR instead decides to batch all json-rpc requests into a single call, thereby making it much more efficient for prysm to retrieve all the desired execution payloads from the execution client.

Which issues(s) does this PR fix?

N.A

Other notes for review

@nisdas nisdas marked this pull request as ready for review August 12, 2022 12:09
@nisdas nisdas requested a review from a team as a code owner August 12, 2022 12:09
@nisdas nisdas added Ready For Review A pull request ready for code review V3 Merge PRs related to the great milestone the merge labels Aug 12, 2022
@@ -315,6 +319,43 @@ func (s *Service) ExecutionBlockByHash(ctx context.Context, hash common.Hash, wi
return result, handleRPCError(err)
}

// ExecutionBlockByHashes fetches a batch of execution engine blocks by hash by calling
// eth_blockByHash via JSON-RPC.
func (s *Service) ExecutionBlockByHashes(ctx context.Context, hashes []common.Hash, withTxs bool) ([]*pb.ExecutionBlock, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func (s *Service) ExecutionBlockByHashes(ctx context.Context, hashes []common.Hash, withTxs bool) ([]*pb.ExecutionBlock, error) {
func (s *Service) ExecutionBlocksByHashes(ctx context.Context, hashes []common.Hash, withTxs bool) ([]*pb.ExecutionBlock, error) {

for _, h := range hashes {
blk := &pb.ExecutionBlock{}
err := error(nil)
newH := h
Copy link
Member

Choose a reason for hiding this comment

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

Is newH := h necessary? We worry about mutation?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you dont create a new hash value, the hash value referenced will change with each iteration in the loop.

}
for _, e := range errs {
if e != nil {
return nil, handleRPCError(e)
Copy link
Member

Choose a reason for hiding this comment

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

If one of the requests fail, do we fail the whole thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeap, we do as the whole batch now becomes inconsistent.

}
// Determine if the block is pre-merge or post-merge. Depending on the result,
// we will ask the execution engine for the full payload.
executionBlockHash := common.BytesToHash(header.BlockHash())
Copy link
Member

Choose a reason for hiding this comment

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

We can move this to within the else right?

@rauljordan rauljordan merged commit 9565ee1 into develop Aug 15, 2022
@rauljordan rauljordan deleted the batchReconstruction branch August 15, 2022 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merge PRs related to the great milestone the merge Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants