-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Reconstruct full Capella block #11732
Merged
Merged
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a464cf5
Merge branch 'reconstruct-capella-block' into capella
rkapka dcdd9af
remove unneeded test
rkapka 8c56dfd
rename methods
rkapka a08baf4
add doc to interface
rkapka 849457d
deepsource
rkapka 1583e93
bzl
rkapka d230084
fix failing tests
rkapka 9ba32c9
single ExecutionBlockByHash function
rkapka f31f7be
fix engine mock
rkapka da04839
Merge branch 'develop' into recontruct-capella-blinded
rkapka a5c6518
deepsource
rkapka b05b67b
reorder checks
rkapka f67d35d
single execution block type
rkapka bfd43e7
update tests
rkapka c6a7c93
Merge branch '__develop' into recontruct-capella-blinded
rkapka b5da7e5
update doc
rkapka e792f72
bytes test
rkapka 9046730
Merge branch '__develop' into recontruct-capella-blinded
rkapka 0b50e11
remove toWithdrawalJSON
rkapka c3f3b95
Merge branch '__develop' into recontruct-capella-blinded
rkapka 9fcda71
Merge refs/heads/develop into recontruct-capella-blinded
prylabs-bulldozer[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ type ForkchoiceUpdatedResponse struct { | |
// block with an execution payload from a signed beacon block and a connection | ||
// to an execution client's engine API. | ||
type ExecutionPayloadReconstructor interface { | ||
ReconstructFullBellatrixBlock( | ||
ReconstructFullBlock( | ||
ctx context.Context, blindedBlock interfaces.SignedBeaconBlock, | ||
) (interfaces.SignedBeaconBlock, error) | ||
ReconstructFullBellatrixBlockBatch( | ||
|
@@ -403,9 +403,9 @@ func (s *Service) HeaderByNumber(ctx context.Context, number *big.Int) (*types.H | |
return hdr, err | ||
} | ||
|
||
// ReconstructFullBellatrixBlock takes in a blinded beacon block and reconstructs | ||
// ReconstructFullBlock takes in a blinded beacon block and reconstructs | ||
// a beacon block with a full execution payload via the engine API. | ||
func (s *Service) ReconstructFullBellatrixBlock( | ||
func (s *Service) ReconstructFullBlock( | ||
ctx context.Context, blindedBlock interfaces.SignedBeaconBlock, | ||
) (interfaces.SignedBeaconBlock, error) { | ||
if err := blocks.BeaconBlockIsNil(blindedBlock); err != nil { | ||
|
@@ -437,11 +437,12 @@ func (s *Service) ReconstructFullBellatrixBlock( | |
if executionBlock == nil { | ||
return nil, fmt.Errorf("received nil execution block for request by hash %#x", executionBlockHash) | ||
} | ||
executionBlock.Version = blindedBlock.Version() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here |
||
payload, err := fullPayloadFromExecutionBlock(header, executionBlock) | ||
if err != nil { | ||
return nil, err | ||
} | ||
fullBlock, err := blocks.BuildSignedBeaconBlockFromExecutionPayload(blindedBlock, payload) | ||
fullBlock, err := blocks.BuildSignedBeaconBlockFromExecutionPayload(blindedBlock, payload.Proto()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -504,7 +505,7 @@ func (s *Service) ReconstructFullBellatrixBlockBatch( | |
if err != nil { | ||
return nil, err | ||
} | ||
fullBlock, err := blocks.BuildSignedBeaconBlockFromExecutionPayload(blindedBlocks[realIdx], payload) | ||
fullBlock, err := blocks.BuildSignedBeaconBlockFromExecutionPayload(blindedBlocks[realIdx], payload.Proto()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -526,26 +527,47 @@ func (s *Service) ReconstructFullBellatrixBlockBatch( | |
|
||
func fullPayloadFromExecutionBlock( | ||
header interfaces.ExecutionData, block *pb.ExecutionBlock, | ||
) (*pb.ExecutionPayload, error) { | ||
) (interfaces.ExecutionData, error) { | ||
if header.IsNil() || block == nil { | ||
return nil, errors.New("execution block and header cannot be nil") | ||
} | ||
if !bytes.Equal(header.BlockHash(), block.Hash[:]) { | ||
blockHash := block.Hash | ||
if !bytes.Equal(header.BlockHash(), blockHash[:]) { | ||
return nil, fmt.Errorf( | ||
"block hash field in execution header %#x does not match execution block hash %#x", | ||
header.BlockHash(), | ||
block.Hash, | ||
blockHash, | ||
) | ||
} | ||
txs := make([][]byte, len(block.Transactions)) | ||
for i, tx := range block.Transactions { | ||
blockTransactions := block.Transactions | ||
txs := make([][]byte, len(blockTransactions)) | ||
for i, tx := range blockTransactions { | ||
txBin, err := tx.MarshalBinary() | ||
if err != nil { | ||
return nil, err | ||
} | ||
txs[i] = txBin | ||
} | ||
return &pb.ExecutionPayload{ | ||
|
||
if block.Version == version.Bellatrix { | ||
return blocks.WrappedExecutionPayload(&pb.ExecutionPayload{ | ||
ParentHash: header.ParentHash(), | ||
FeeRecipient: header.FeeRecipient(), | ||
StateRoot: header.StateRoot(), | ||
ReceiptsRoot: header.ReceiptsRoot(), | ||
LogsBloom: header.LogsBloom(), | ||
PrevRandao: header.PrevRandao(), | ||
BlockNumber: header.BlockNumber(), | ||
GasLimit: header.GasLimit(), | ||
GasUsed: header.GasUsed(), | ||
Timestamp: header.Timestamp(), | ||
ExtraData: header.ExtraData(), | ||
BaseFeePerGas: header.BaseFeePerGas(), | ||
BlockHash: blockHash[:], | ||
Transactions: txs, | ||
}) | ||
} | ||
return blocks.WrappedExecutionPayloadCapella(&pb.ExecutionPayloadCapella{ | ||
ParentHash: header.ParentHash(), | ||
FeeRecipient: header.FeeRecipient(), | ||
StateRoot: header.StateRoot(), | ||
|
@@ -558,9 +580,10 @@ func fullPayloadFromExecutionBlock( | |
Timestamp: header.Timestamp(), | ||
ExtraData: header.ExtraData(), | ||
BaseFeePerGas: header.BaseFeePerGas(), | ||
BlockHash: block.Hash[:], | ||
BlockHash: blockHash[:], | ||
Transactions: txs, | ||
}, nil | ||
Withdrawals: block.Withdrawals, | ||
}) | ||
} | ||
|
||
// Handles errors received from the RPC server according to the specification. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,15 @@ func ToBytes4(x []byte) [4]byte { | |
return y | ||
} | ||
|
||
// ToBytes20 is a convenience method for converting a byte slice to a fix | ||
// sized 20 byte array. This method will truncate the input if it is larger | ||
// than 20 bytes. | ||
func ToBytes20(x []byte) [20]byte { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add some unit tests for this ? |
||
var y [20]byte | ||
copy(y[:], x) | ||
return y | ||
} | ||
|
||
// ToBytes32 is a convenience method for converting a byte slice to a fix | ||
// sized 32 byte array. This method will truncate the input if it is larger | ||
// than 32 bytes. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why set this ? Shouldn't it already have its version set in the
ExecutionBlockByHash
method ? Or are you not able to infer thatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not able to infer from how
ExecutionBlockByHash
is implemented. I can add aversion
argument, but this seems cleaner to me.