-
Notifications
You must be signed in to change notification settings - Fork 20.4k
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
all: implement push withdrawals (EIP-4895) #25838
Conversation
0cfa695
to
9c922f8
Compare
35ad617
to
b5351c6
Compare
@@ -90,15 +90,15 @@ type Engine interface { | |||
// Note: The block header and state database might be updated to reflect any | |||
// consensus rules that happen at finalization (e.g. block rewards). | |||
Finalize(chain ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, | |||
uncles []*types.Header) | |||
uncles []*types.Header, withdrawals []*types.Withdrawal) |
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.
Curious to know if there are better approaches than changing this interface.
core/beacon/types.go
Outdated
SuggestedFeeRecipient common.Address `json:"suggestedFeeRecipient" gencodec:"required"` | ||
} | ||
|
||
func (a *PayloadAttributesV1) ToV2() *PayloadAttributesV2 { |
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.
Please share any suggestions for improving this code. I thought about two other approaches:
- Interface -- I could define an interface for these types which is the sum of all the versions. The downside is I believe I will need to then manually define the JSON encoding for each and implement a bunch of simple getters.
- Single type -- I could extend the original type (and remove the V1) and then guard invalid combinations in the call sites. The downside for this is then that we always need to be careful about guarding against invalid configurations. Which may not be a big issue.
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.
I ended up trying 2) in f5c9b70. That reduced the overall diff by about 150 lines.
f5c9b70
to
090bd9f
Compare
d9cdfe1
to
7dbeb21
Compare
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.
This change requires some new tests -- specifically blockchain tests with a new format on the block bodies.
core/beacon/types.go
Outdated
BaseFee: params.BaseFeePerGas, | ||
Extra: params.ExtraData, | ||
MixDigest: params.Random, | ||
WithdrawalHash: withdrawalRoot, |
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.
WithdrawalHash: withdrawalRoot, | |
WithdrawalRoot: withdrawalRoot, |
maybe ? I don't know ?
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.
The reason for this name was to follow along the naming convention of TxHash
and ReceiptHash
(which fwiw, I think would be better if with s/Hash/Root
).
// The values of TxHash, UncleHash, ReceiptHash and Bloom in header | ||
// are ignored and set to values derived from the given txs, uncles | ||
// and receipts. | ||
func NewBlock2(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt, withdrawals []*Withdrawal, hasher TrieHasher) *Block { |
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.
Ouch, please use a better name!
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.
NewBlockWithWithdrawals?
@@ -378,6 +426,17 @@ func (b *Block) WithBody(transactions []*Transaction, uncles []*Header) *Block { | |||
return block | |||
} | |||
|
|||
// WithBody2 returns a new block with the given transaction, uncle, and | |||
// withdrawal contents. | |||
func (b *Block) WithBody2(transactions []*Transaction, uncles []*Header, withdrawals []*Withdrawal) *Block { |
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.
Ah my eyes!
Please use language.
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.
cc @fjl - he recommend this naming convention.
eab8499
to
49fb63d
Compare
03bbe62
to
cd6afba
Compare
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.
Mostly nitpicks
consensus/clique/clique.go
Outdated
@@ -743,6 +743,9 @@ func encodeSigHeader(w io.Writer, header *types.Header) { | |||
if header.BaseFee != nil { | |||
enc = append(enc, header.BaseFee) | |||
} | |||
if header.WithdrawalHash != nil { |
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.
I don't understand this change, shouldn't we just not add the withdrawal hash here, even if the header has it set for some reason? Maybe we should even panic/warn
// The values of TxHash, UncleHash, ReceiptHash and Bloom in header | ||
// are ignored and set to values derived from the given txs, uncles | ||
// and receipts. | ||
func NewBlock2(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt, withdrawals []*Withdrawal, hasher TrieHasher) *Block { |
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.
NewBlockWithWithdrawals?
eth/catalyst/api.go
Outdated
// Hash | ||
hasher := sha256.New() | ||
hasher.Write(headBlockHash[:]) | ||
binary.Write(hasher, binary.BigEndian, params.Timestamp) | ||
hasher.Write(params.Random[:]) | ||
hasher.Write(params.SuggestedFeeRecipient[:]) | ||
if params.Withdrawals != nil { | ||
// TODO: is it okay to throw away this error? |
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.
I think throwing away the error is fine, there's no spec around how the payload id should be generated anymore. It just needs to be unique per payload
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.
It might be weird when cls start updating only the withdrawals within a slot with invalid withdrawals, but thats on them and we might just return a payload with 'old' withdrawals
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.
The execution api specs define that this ID can be completely random. It used to be derived from payload attributes in the past, but maybe it's time to use a randomized ID to not break it with any changes to the attributes?
0c0f751
to
9e66c16
Compare
9e66c16
to
cc3d8da
Compare
Found this on a different branch ( |
57966d1
to
08d2458
Compare
Co-authored-by: lightclient <[email protected]> Co-authored-by: marioevz <[email protected]>
08d2458
to
256e54c
Compare
Just a note that the |
Closing in favour of #26484 |
This PR implements EIP-4895: Beacon chain push withdrawals as operations. WIP.