-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Electra: exclude empty requests in requests list #14580
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
Merged
james-prysm
merged 25 commits into
develop
from
execution-requests-serialization-changes
Oct 31, 2024
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
ace832c
implementing new decisions around exectuion requests
james-prysm 0884e0e
fixing test fixture
james-prysm bd26494
adding in more edge case checks and tests
james-prysm d932f6e
Merge branch 'develop' into execution-requests-serialization-changes
james-prysm e0ffd1a
changelog
james-prysm 3c7cbf7
fixing unsafe type cast
james-prysm 2852bcc
Update beacon-chain/execution/engine_client_test.go
james-prysm 3cdb4ad
Update proto/engine/v1/electra.go
james-prysm 9f7997b
Update proto/engine/v1/electra.go
james-prysm 14f5f0a
Update proto/engine/v1/electra.go
james-prysm 4b22e25
Update proto/engine/v1/electra.go
james-prysm e7ba3b1
Update proto/engine/v1/electra_test.go
james-prysm b077cfd
Update proto/engine/v1/electra_test.go
james-prysm b48d359
Merge branch 'develop' into execution-requests-serialization-changes
james-prysm 8f62720
updating based on preston's feedback and adding more tests for edge c…
james-prysm 44de042
adding more edgecases, and unit tests
james-prysm c879cfb
Merge branch 'develop' into execution-requests-serialization-changes
james-prysm ace1aa5
fixing tests
james-prysm dc7eebd
missed some export changes
james-prysm 8bf061b
Merge branch 'develop' into execution-requests-serialization-changes
james-prysm c69ac6c
adding more tests
james-prysm cbdc3ad
Update proto/engine/v1/electra.go
james-prysm b077638
reducing complexity of function based on feedback
james-prysm 14c629b
Merge branch 'develop' into execution-requests-serialization-changes
james-prysm 46b8205
Merge branch 'develop' into execution-requests-serialization-changes
james-prysm 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |
|
|
||
| "github.com/ethereum/go-ethereum/common/hexutil" | ||
| "github.com/pkg/errors" | ||
| "github.com/prysmaticlabs/prysm/v5/config/params" | ||
| ) | ||
|
|
||
| type ExecutionPayloadElectra = ExecutionPayloadDeneb | ||
|
|
@@ -19,59 +20,124 @@ var ( | |
| crSize = crExample.SizeSSZ() | ||
| ) | ||
|
|
||
| const LenExecutionRequestsElectra = 3 | ||
| const ( | ||
| DepositRequestType = iota | ||
| WithdrawalRequestType | ||
| ConsolidationRequestType | ||
| ) | ||
|
|
||
| func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests() (*ExecutionRequests, error) { | ||
| requests := &ExecutionRequests{} | ||
|
|
||
| if len(ebe.ExecutionRequests) != LenExecutionRequestsElectra /* types of requests */ { | ||
| return nil, errors.Errorf("invalid execution request size: %d", len(ebe.ExecutionRequests)) | ||
| var prevTypeNum uint8 | ||
| for i := range ebe.ExecutionRequests { | ||
| requestType, requestListInSSZBytes, err := decodeExecutionRequest(ebe.ExecutionRequests[i]) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if prevTypeNum > requestType { | ||
| return nil, errors.New("invalid execution request type order, requests should be in sorted order") | ||
| } | ||
| prevTypeNum = requestType | ||
| switch requestType { | ||
| case DepositRequestType: | ||
|
Contributor
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. As before can we remove the cases from here and treat them in separate functions? |
||
| drs, err := unmarshalDeposits(requestListInSSZBytes) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| requests.Deposits = drs | ||
| case WithdrawalRequestType: | ||
| wrs, err := unmarshalWithdrawals(requestListInSSZBytes) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| requests.Withdrawals = wrs | ||
| case ConsolidationRequestType: | ||
| crs, err := unmarshalConsolidations(requestListInSSZBytes) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| requests.Consolidations = crs | ||
| default: | ||
| return nil, errors.Errorf("unsupported request type %d", requestType) | ||
| } | ||
| } | ||
| return requests, nil | ||
| } | ||
|
|
||
| // deposit requests | ||
| drs, err := unmarshalItems(ebe.ExecutionRequests[0], drSize, func() *DepositRequest { return &DepositRequest{} }) | ||
| if err != nil { | ||
| return nil, err | ||
| func unmarshalDeposits(requestListInSSZBytes []byte) ([]*DepositRequest, error) { | ||
| if len(requestListInSSZBytes) < drSize { | ||
| return nil, errors.New("invalid deposit requests length, requests should be at least the size of 1 request") | ||
| } | ||
| if uint64(len(requestListInSSZBytes)) > uint64(drSize)*params.BeaconConfig().MaxDepositRequestsPerPayload { | ||
| return nil, fmt.Errorf("invalid deposit requests length, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), drSize) | ||
| } | ||
| requests.Deposits = drs | ||
| return unmarshalItems(requestListInSSZBytes, drSize, func() *DepositRequest { return &DepositRequest{} }) | ||
| } | ||
|
|
||
| // withdrawal requests | ||
| wrs, err := unmarshalItems(ebe.ExecutionRequests[1], wrSize, func() *WithdrawalRequest { return &WithdrawalRequest{} }) | ||
| if err != nil { | ||
| return nil, err | ||
| func unmarshalWithdrawals(requestListInSSZBytes []byte) ([]*WithdrawalRequest, error) { | ||
| if len(requestListInSSZBytes) < wrSize { | ||
| return nil, errors.New("invalid withdrawal request length, requests should be at least the size of 1 request") | ||
| } | ||
| requests.Withdrawals = wrs | ||
| if uint64(len(requestListInSSZBytes)) > uint64(wrSize)*params.BeaconConfig().MaxWithdrawalRequestsPerPayload { | ||
| return nil, fmt.Errorf("invalid withdrawal requests length, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), wrSize) | ||
| } | ||
| return unmarshalItems(requestListInSSZBytes, wrSize, func() *WithdrawalRequest { return &WithdrawalRequest{} }) | ||
| } | ||
|
|
||
| // consolidation requests | ||
| crs, err := unmarshalItems(ebe.ExecutionRequests[2], crSize, func() *ConsolidationRequest { return &ConsolidationRequest{} }) | ||
| if err != nil { | ||
| return nil, err | ||
| func unmarshalConsolidations(requestListInSSZBytes []byte) ([]*ConsolidationRequest, error) { | ||
| if len(requestListInSSZBytes) < crSize { | ||
| return nil, errors.New("invalid consolidations request length, requests should be at least the size of 1 request") | ||
| } | ||
| if uint64(len(requestListInSSZBytes)) > uint64(crSize)*params.BeaconConfig().MaxConsolidationsRequestsPerPayload { | ||
| return nil, fmt.Errorf("invalid consolidation requests length, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), crSize) | ||
| } | ||
| requests.Consolidations = crs | ||
| return unmarshalItems(requestListInSSZBytes, crSize, func() *ConsolidationRequest { return &ConsolidationRequest{} }) | ||
| } | ||
|
|
||
| return requests, nil | ||
| func decodeExecutionRequest(req []byte) (typ uint8, data []byte, err error) { | ||
| if len(req) < 1 { | ||
| return 0, nil, errors.New("invalid execution request, length less than 1") | ||
| } | ||
| return req[0], req[1:], nil | ||
| } | ||
|
|
||
| func EncodeExecutionRequests(requests *ExecutionRequests) ([]hexutil.Bytes, error) { | ||
| if requests == nil { | ||
| return nil, errors.New("invalid execution requests") | ||
| } | ||
|
|
||
| drBytes, err := marshalItems(requests.Deposits) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to marshal deposit requests") | ||
| } | ||
| requestsData := make([]hexutil.Bytes, 0) | ||
|
|
||
| wrBytes, err := marshalItems(requests.Withdrawals) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to marshal withdrawal requests") | ||
| // request types MUST be in sorted order starting from 0 | ||
| if len(requests.Deposits) > 0 { | ||
| drBytes, err := marshalItems(requests.Deposits) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to marshal deposit requests") | ||
| } | ||
| requestData := []byte{DepositRequestType} | ||
| requestData = append(requestData, drBytes...) | ||
| requestsData = append(requestsData, requestData) | ||
| } | ||
|
|
||
| crBytes, err := marshalItems(requests.Consolidations) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to marshal consolidation requests") | ||
| if len(requests.Withdrawals) > 0 { | ||
| wrBytes, err := marshalItems(requests.Withdrawals) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to marshal withdrawal requests") | ||
| } | ||
| requestData := []byte{WithdrawalRequestType} | ||
| requestData = append(requestData, wrBytes...) | ||
| requestsData = append(requestsData, requestData) | ||
| } | ||
| if len(requests.Consolidations) > 0 { | ||
| crBytes, err := marshalItems(requests.Consolidations) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to marshal consolidation requests") | ||
| } | ||
| requestData := []byte{ConsolidationRequestType} | ||
| requestData = append(requestData, crBytes...) | ||
| requestsData = append(requestsData, requestData) | ||
| } | ||
| return []hexutil.Bytes{drBytes, wrBytes, crBytes}, nil | ||
|
|
||
| return requestsData, nil | ||
| } | ||
|
|
||
| type sszUnmarshaler interface { | ||
|
|
||
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.