Skip to content
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

Closed
wants to merge 13 commits into from

Conversation

lightclient
Copy link
Member

@@ -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)
Copy link
Member Author

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.

SuggestedFeeRecipient common.Address `json:"suggestedFeeRecipient" gencodec:"required"`
}

func (a *PayloadAttributesV1) ToV2() *PayloadAttributesV2 {
Copy link
Member Author

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:

  1. 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.
  2. 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.

Copy link
Member Author

@lightclient lightclient Sep 28, 2022

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.

@lightclient lightclient changed the title core,eth: implement push withdrawals (EIP-4895) all: implement push withdrawals (EIP-4895) Sep 27, 2022
@lightclient lightclient force-pushed the withdrawals branch 4 times, most recently from d9cdfe1 to 7dbeb21 Compare October 19, 2022 22:05
Copy link
Contributor

@holiman holiman left a 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.

consensus/beacon/consensus.go Outdated Show resolved Hide resolved
BaseFee: params.BaseFeePerGas,
Extra: params.ExtraData,
MixDigest: params.Random,
WithdrawalHash: withdrawalRoot,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
WithdrawalHash: withdrawalRoot,
WithdrawalRoot: withdrawalRoot,

maybe ? I don't know ?

Copy link
Member Author

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 {
Copy link
Contributor

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!

Copy link
Member

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 {
Copy link
Contributor

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.

Copy link
Member Author

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.

@lightclient lightclient force-pushed the withdrawals branch 4 times, most recently from eab8499 to 49fb63d Compare October 24, 2022 18:01
Copy link
Member

@MariusVanDerWijden MariusVanDerWijden left a comment

Choose a reason for hiding this comment

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

Mostly nitpicks

cmd/evm/internal/t8ntool/execution.go Show resolved Hide resolved
@@ -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 {
Copy link
Member

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

core/beacon/blockparams_marshaling.go Outdated Show resolved Hide resolved
core/beacon/ed_marashaling.go Outdated Show resolved Hide resolved
core/beacon/types.go Show resolved Hide resolved
core/chain_makers.go Show resolved Hide resolved
// 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 {
Copy link
Member

Choose a reason for hiding this comment

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

NewBlockWithWithdrawals?

// 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?
Copy link
Member

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

Copy link
Member

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

Copy link
Contributor

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?

eth/fetcher/block_fetcher_test.go Outdated Show resolved Hide resolved
@marioevz
Copy link
Member

Found this on a different branch (withdrawals-timestamp) and leaving here as a reminder:
In params/config.go, ShanghaiTime field in ChainConfig is still parsed from the json field shanghaiBlock, but should eventually be changed to be parsed from shanghaiTime.

@Inphi
Copy link
Contributor

Inphi commented Dec 2, 2022

Just a note that the withdrawalsRoot is missing from the JSON-RPC header response.

@holiman
Copy link
Contributor

holiman commented Jan 12, 2023

Closing in favour of #26484

@holiman holiman closed this Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants