Skip to content

Merge all block unblinding code into a single unblinder struct#12240

Merged
rkapka merged 25 commits intodevelopfrom
unblinder
May 23, 2023
Merged

Merge all block unblinding code into a single unblinder struct#12240
rkapka merged 25 commits intodevelopfrom
unblinder

Conversation

@rkapka
Copy link
Contributor

@rkapka rkapka commented Apr 5, 2023

What type of PR is this?

Other

What does this PR do? Why is it needed?

This PR creates a new unblinder type responsible for (wait for it...) unblinding blocks. The main purpose of the type is to reduce code duplication and keep unblinding logic in one place. It can easily be extended for Deneb blocks.

This was already merged to 4844 in #12232

)

# Conflicts:
#	beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go
#	beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go
#	beacon-chain/rpc/prysm/v1alpha1/validator/proposer_capella.go
#	beacon-chain/rpc/prysm/v1alpha1/validator/proposer_capella_test.go
@rkapka rkapka requested a review from a team as a code owner April 5, 2023 15:25
@rkapka rkapka requested review from potuz, saolyn and terencechain April 5, 2023 15:25
return nil, errors.Wrap(err, "could not set execution")
}

payload, err := u.builder.SubmitBlindedBlock(ctx, sb)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't forget to set SetBLSToExecutionChanges before SubmitBlindedBlock
Also, please add a unit test for this field
See #12263 for detail

rkapka added 3 commits April 13, 2023 13:03
# Conflicts:
#	beacon-chain/rpc/prysm/v1alpha1/validator/proposer_capella.go
#	beacon-chain/rpc/prysm/v1alpha1/validator/proposer_capella_test.go
return nil, errors.Wrap(err, "could not set sync aggregate")
}
sb.SetSignature(sig[:])
if err = sb.SetBLSToExecutionChanges(blsToExecChanges); err != nil && !errors.Is(err, consensusblocks.ErrUnsupportedGetter) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't the error be unsupported Setter here instead of Getter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This requires some more refactoring, but I can add it.

StateRoot: make([]byte, fieldparams.RootLength),
ReceiptsRoot: make([]byte, fieldparams.RootLength),
LogsBloom: make([]byte, fieldparams.LogsBloomLength),
PrevRandao: make([]byte, fieldparams.RootLength),
Copy link
Collaborator

@kasey kasey Apr 13, 2023

Choose a reason for hiding this comment

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

presumably this omits BlockNumber, GasLimit, GasUsed, Timestamp because they are uint64s so they receive zero values, but we may want to always include all fields in functions like this as a matter of course to help verify completeness.

BlockHash: make([]byte, fieldparams.RootLength),
Transactions: make([][]byte, 0),
Withdrawals: make([]*enginev1.Withdrawal, 0),
ExtraData: make([]byte, 0),
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we put these fields in the same order as the consensus types? That would make this code a little easier to compare to generated protobuf code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean exactly? In consensus types we have an ExecutionData interface and a type that wraps a proto object.

return nil, errors.Wrap(err, "could not set execution")
}

payload, err := u.builder.SubmitBlindedBlock(ctx, sb)
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be a good time to add a defensive check for SubmitBlindedBlock and do a version check on the response for the payload. right now the version isn't getting checked on the response and is not part of the executiondata interface which could result in a bad payload.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

payload is of type ExecutionData, which doesn't have a version. If we want to change this, it should be in a new PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah we need a new PR for checking inside I'm not sure if ExecutionData needs it to get the version or not, but at least it should be checked inside

Copy link
Contributor

Choose a reason for hiding this comment

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

my PR merged in with the check here

if err != nil {
return nil, errors.Wrap(err, "could not create signed block")
}
wb.SetSlot(sb.Block().Slot())
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any pattern we can follow so we don't miss/forget doing these sets? also might be worth breaking into its own function to make this more readable.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the same comment applies to line 66and onwards.
do the settings in sb and wb need to be the same? maybe there can be a check on that too somehow?

Copy link
Contributor

Choose a reason for hiding this comment

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

or better yet a utility function where wb/sb are passed so it's at least 1 spot ( not sure if it's completed replicated logic however.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I extracted common code

return nil, errors.New("builder not configured")
}

agg, err := u.b.Block().Body().SyncAggregate()
Copy link
Contributor

Choose a reason for hiding this comment

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

might need nil checks in case of panics

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is already checked at the beginning of newUnblinder

@rkapka rkapka added the blocked label May 5, 2023
@rkapka
Copy link
Contributor Author

rkapka commented May 5, 2023

Marking as blocked until we have the test builder ready.

rkapka added 2 commits May 17, 2023 19:16
# Conflicts:
#	beacon-chain/blockchain/log.go
#	beacon-chain/core/blocks/payload.go
#	beacon-chain/rpc/eth/beacon/BUILD.bazel
#	beacon-chain/rpc/eth/beacon/blinded_blocks.go
#	beacon-chain/rpc/eth/beacon/blinded_blocks_test.go
#	beacon-chain/rpc/eth/beacon/blocks.go
#	beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go
#	cmd/prysmctl/p2p/request_blocks.go
#	consensus-types/blocks/execution.go
#	consensus-types/blocks/execution_test.go
#	consensus-types/blocks/types.go
@rkapka rkapka removed the blocked label May 18, 2023
return nil, err
}
return &unblinder{
b: b,
Copy link
Contributor

@james-prysm james-prysm May 18, 2023

Choose a reason for hiding this comment

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

should there be a nil check on builder here?

if !u.b.IsBlinded() || u.b.Version() < version.Bellatrix {
return u.b, nil
}
if u.b.IsBlinded() && !u.builder.Configured() {
Copy link
Contributor

Choose a reason for hiding this comment

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

builder nil check could also be here I guess.

@terencechain terencechain dismissed their stale review May 22, 2023 15:41

Dismissing my review. I haven't looked at it closely for approve but feel free to merge if others have

return wb, nil
}

func copyBlockData(src interfaces.SignedBeaconBlock, dst interfaces.SignedBeaconBlock) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be the scariest function in all of this if we forget to add something/populate something.

return errors.Wrap(err, "could not set sync aggregate")
}
dst.SetSignature(sig[:])
if err = dst.SetBLSToExecutionChanges(blsToExecChanges); err != nil && !errors.Is(err, consensus_types.ErrUnsupportedField) {
Copy link
Contributor

Choose a reason for hiding this comment

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

worth adding capella fork marking here in comments?

graffiti := src.Block().Body().Graffiti()
sig := src.Signature()
blsToExecChanges, err := src.Block().Body().BLSToExecutionChanges()
if err != nil && !errors.Is(err, consensus_types.ErrUnsupportedField) {
Copy link
Contributor

Choose a reason for hiding this comment

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

so copy Block will throw an error here if it's an old block that doesn't have this support?

Copy link
Contributor

Choose a reason for hiding this comment

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

totally missed the !

@rkapka rkapka merged commit abc81e6 into develop May 23, 2023
@rkapka rkapka deleted the unblinder branch May 23, 2023 09:38
james-prysm added a commit that referenced this pull request May 23, 2023
)

Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants