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

New prysm get block RPC #11834

Merged
merged 43 commits into from
Jan 13, 2023
Merged

New prysm get block RPC #11834

merged 43 commits into from
Jan 13, 2023

Conversation

terencechain
Copy link
Member

What type of PR is this?

Rewrite of GetBlock Prysm RPC

What does this PR do? Why is it needed?

This PR rewrites GetBlock Prysm RPC to be better, cleaner, and more extensive. In the end, we were able to delete much of the "spaghetti" code. This piece of the code is already live in capella branch and utilized in all the Capella and eip-4844 testnets. This is the original PR which documents the workflow: #11721

I'm still working on more unit tests so please hold off on the detailed reviews

@terencechain terencechain self-assigned this Dec 30, 2022
@terencechain terencechain requested a review from a team as a code owner December 30, 2022 22:48
@terencechain terencechain added Ready For Review A pull request ready for code review Withdrawals Priority: High High priority item Blocked Blocked by research or external factors and removed Ready For Review A pull request ready for code review labels Jan 4, 2023
@terencechain
Copy link
Member Author

I am marking it as blocked. I want to test this with mev-boost

if err != nil {
return nil, status.Errorf(codes.Internal, "Could not prepare blind beacon block: %v", err)
}
if !ok {
return nil, status.Error(codes.Unavailable, "Builder is not available due to miss-config or circuit breaker")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this error right now?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a beacon API for retrieving blind blocks (only). By the beacon API definition, you must return a valid blind block or fail. Very different than our current implementation used by Prysm API

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean are you sure that the only failures are miss-config or circuit breaker in this path?

Copy link
Member Author

Choose a reason for hiding this comment

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

The error msg is wrong. I'll update

if err != nil {
return nil, status.Errorf(codes.Internal, "Could not fetch Altair beacon block: %v", err)
log.WithError(err).Error("Could not pack deposits and attestations")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, do we need to set the empty deposits and attestations here or the marshaller takes care of it automatically?

Copy link
Member Author

@terencechain terencechain Jan 6, 2023

Choose a reason for hiding this comment

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

I think this one is fine since those are not vectors but I added anyway

return vs.getBellatrixBeaconBlock(ctx, req)
// Set bls to execution change. New in Capella.
if err := vs.setBlsToExecData(blk, head); err != nil {
return nil, status.Errorf(codes.Internal, "Could not set bls to execution data: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a non-blocking error, a block is valid with an empty bls-to-exec-changes slice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch!

return nil, fmt.Errorf("could not build block data: %v", err)
func (vs *Server) setSyncAggregate(ctx context.Context, blk interfaces.BeaconBlock) {
slot := blk.Slot()
if slot == 0 || slots.ToEpoch(slot) < params.BeaconConfig().AltairForkEpoch {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel there's something wrong here. For networks that start with AltairForkEpoch == 0 this should not fail. The problem is the slot - 1 statement below. In any case, we should never reach this point as there's no proposing on slot 0.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, maybe a cleaner check should be based on block version

Comment on lines 30 to 32
if err := blk.Body().SetSyncAggregate(&ethpb.SyncAggregate{
SyncCommitteeBits: make([]byte, params.BeaconConfig().SyncCommitteeSize),
SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength),
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is a valid empty sync committee signature. Take a look a my helper functions on testing/util for an example on how to sign with the point at infinity in the BLS curve.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch!

)

// Sets the bls to exec data for a block.
func (vs *Server) setBlsToExecData(blk interfaces.BeaconBlock, headState state.BeaconState) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to deal with the error case withing this function. That is this function does not return an error, and if the call to SetBLSToExecutionChanges errors out, we set the empty slice here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree

Comment on lines 93 to 94
blk.Body().SetDeposits([]*ethpb.Deposit{})
blk.Body().SetAttestations([]*ethpb.Attestation{})
Copy link
Contributor

Choose a reason for hiding this comment

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

These need to go outside of the if/else block and remove the else block

log.WithError(err).Error("Could not get bls to execution changes")
} else {
if err := blk.Body().SetBLSToExecutionChanges(changes); err != nil {
if err := blk.Body().SetBLSToExecutionChanges([]*ethpb.SignedBLSToExecutionChange{}); err != nil {
log.WithError(err).Error("Could not set bls to execution data in block")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think part of the requests in my feedback was to remove the error return in this function, so that we don't need to be doing this if/else in multiple places.

@terencechain terencechain merged commit 1b2d917 into develop Jan 13, 2023
@delete-merged-branch delete-merged-branch bot deleted the new-proposer-rpc branch January 13, 2023 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocked Blocked by research or external factors Priority: High High priority item
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants