-
Notifications
You must be signed in to change notification settings - Fork 985
catalyst/api: centralize OPStack validation into helper functions #592
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
+360
−25
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c4f5a94
catalyist/api: centralize OPStack validation into helper functions
geoknee d24ba1e
add test coverage for optimism validation checks
geoknee 003cd64
lint
geoknee c266ce2
use engine.InvalidPayloadAttributes.With() for all failed optimism FC…
geoknee 8daaba7
typos
geoknee 6dd6374
Merge branch 'optimism' into gk/568
geoknee d84dde2
Merge branch 'optimism' into gk/568
geoknee a0662f1
Merge branch 'optimism' into gk/568
geoknee da473e0
Merge branch 'optimism' into gk/568
geoknee a0d7a2d
fix: only check optimism payload attributes if they are not nil
geoknee b5f874c
Merge branch 'optimism' into gk/568
geoknee b152dcc
combine conditions
geoknee b0b725b
move test
geoknee bdacd7e
combine checks
geoknee 821ee0c
add check on withdrawals root from canyon to isthmus
geoknee 0ef57ff
lint
geoknee 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package catalyst | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| "github.com/ethereum/go-ethereum/beacon/engine" | ||
| "github.com/ethereum/go-ethereum/consensus/misc/eip1559" | ||
| "github.com/ethereum/go-ethereum/core/types" | ||
| "github.com/ethereum/go-ethereum/params" | ||
| ) | ||
|
|
||
| // checkOptimismPayload performs Optimism-specific checks on the payload data (called during [(*ConsensusAPI).newPayload]). | ||
| func checkOptimismPayload(params engine.ExecutableData, cfg *params.ChainConfig) error { | ||
| // Canyon | ||
| if cfg.IsCanyon(params.Timestamp) && !cfg.IsIsthmus(params.Timestamp) { | ||
| if params.WithdrawalsRoot == nil || *params.WithdrawalsRoot != types.EmptyWithdrawalsHash { | ||
| return errors.New("withdrawalsRoot not equal to MPT root of empty list post-Canyon and pre-Isthmus") | ||
| } | ||
| } | ||
|
|
||
| // Holocene | ||
| if cfg.IsHolocene(params.Timestamp) { | ||
| if err := eip1559.ValidateHoloceneExtraData(params.ExtraData); err != nil { | ||
| return err | ||
| } | ||
| } else { | ||
| if len(params.ExtraData) > 0 { | ||
| return errors.New("extraData must be empty before Holocene") | ||
| } | ||
| } | ||
|
|
||
| // Isthmus | ||
| if cfg.IsIsthmus(params.Timestamp) { | ||
| if params.Withdrawals == nil || len(params.Withdrawals) != 0 { | ||
| return errors.New("non-empty or nil withdrawals post-isthmus") | ||
| } | ||
| if params.WithdrawalsRoot == nil { | ||
| return errors.New("nil withdrawalsRoot post-isthmus") | ||
| } | ||
| } | ||
|
sebastianst marked this conversation as resolved.
|
||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // checkOptimismPayloadAttributes performs Optimism-specific checks on the payload attributes (called during [(*ConsensusAPI).forkChoiceUpdated]. | ||
| // Will panic if payloadAttributes is nil. | ||
| func checkOptimismPayloadAttributes(payloadAttributes *engine.PayloadAttributes, cfg *params.ChainConfig) error { | ||
| if payloadAttributes.GasLimit == nil { | ||
| return errors.New("gasLimit parameter is required") | ||
| } | ||
|
|
||
| // Holocene | ||
| if cfg.IsHolocene(payloadAttributes.Timestamp) { | ||
| if err := eip1559.ValidateHolocene1559Params(payloadAttributes.EIP1559Params); err != nil { | ||
| return err | ||
| } | ||
| } else if len(payloadAttributes.EIP1559Params) != 0 { | ||
| return errors.New("eip155Params not supported prior to Holocene upgrade") | ||
| } | ||
|
|
||
| // Isthmus | ||
| if cfg.IsIsthmus(payloadAttributes.Timestamp) && payloadAttributes.Withdrawals == nil || len(payloadAttributes.Withdrawals) != 0 { | ||
| return errors.New("non-empty or nil withdrawals post-isthmus") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
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.