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 withdrawals (EIP-4895) #26484

Merged
merged 43 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
be4ad19
core/types: add withdrawal type
lightclient Nov 5, 2022
72c91a4
core/beacon: add withdrawals and make types version agnostic
lightclient Nov 5, 2022
1779e45
eth/catalyst,les/catalyst: add withdrawals and make types version agn…
lightclient Nov 5, 2022
79ed6d4
miner: add withdrawals and update catalyst types
lightclient Nov 5, 2022
ed15060
consensus: process withdrawals
lightclient Nov 5, 2022
43ff685
core/state_processor: finalize with withdrawals
lightclient Nov 5, 2022
5e37321
core/chain_makers: add withdrawal support
lightclient Nov 5, 2022
cf34465
core/block_validator: verify withdrawals root
lightclient Nov 5, 2022
e7170c2
core/rawdb: update block readers with new block format
lightclient Nov 5, 2022
18a3ced
eth: add p2p support for withdrawals
lightclient Nov 5, 2022
8c55bd6
cmd/evm: support withdrawals in t8n and b11r
lightclient Nov 5, 2022
a6dd779
eth/downloader: always use WithBody2 when constructing blocks
lightclient Nov 30, 2022
f00089f
eth/fetcher: always use WithBody2 when constructing blocks
lightclient Nov 30, 2022
c66dc48
params: core: enable shanghai based on timestamps
MariusVanDerWijden Sep 27, 2022
7c1651b
core,consensus: use timestamp based is shanghai check
lightclient Nov 6, 2022
218b71a
consensus: fail if running shanghai on clique or ethash
lightclient Nov 6, 2022
5c5cd11
core: set withdrawals hash in genesis, fix tests, add withdrawalRoot
MariusVanDerWijden Nov 8, 2022
2e8233a
all: implement forkid changes for shanghai
MariusVanDerWijden Nov 10, 2022
9c905c2
core/types: make fetchers fetch withdrawals without transactions
MariusVanDerWijden Dec 1, 2022
5daaafe
internal/ethapi: add withdrawals to full block
MariusVanDerWijden Nov 22, 2022
f701ea4
internal/ethapi: add comment
MariusVanDerWijden Dec 7, 2022
91b284e
miner: catalyst: return transaction fees for block
MariusVanDerWijden Oct 16, 2022
47b582d
core/forkid: fix forkid filter
MariusVanDerWijden Dec 13, 2022
a686276
core/forkid: reduce diff by anonymous function
MariusVanDerWijden Dec 15, 2022
91b47e3
core/beacon: correctly marshal block value
MariusVanDerWijden Dec 17, 2022
101041a
core: fix rebasing issues
MariusVanDerWijden Jan 11, 2023
bac9e89
eth/protocols/eth: revert accidental modification
MariusVanDerWijden Jan 13, 2023
300f5f2
core, eth: use gwei for withdrawals
MariusVanDerWijden Jan 13, 2023
f959d38
eth/catalyst: use gwei in test instead of hard coded value
lightclient Jan 13, 2023
cf0ed02
core: fix nil panic
MariusVanDerWijden Jan 18, 2023
8c74d60
all: fix review comments, add beacon.Faker, fix tests
MariusVanDerWijden Jan 19, 2023
3263936
consensus/beacon: add faker
MariusVanDerWijden Jan 19, 2023
1931e38
eth/catalyst: go generate, fix nitpicks
MariusVanDerWijden Jan 19, 2023
493741d
Update consensus/beacon/consensus.go
holiman Jan 25, 2023
dd3c41a
Apply suggestions from code review
holiman Jan 25, 2023
7b073d1
Update internal/ethapi/api.go
holiman Jan 25, 2023
3481ebc
Update core/types/block.go
holiman Jan 25, 2023
b43da37
all: rebase on uint64 timestamps
MariusVanDerWijden Jan 25, 2023
f665111
consensus/beacon: add check for Shanghai activation in FinalizeAndAss…
fjl Jan 25, 2023
31a979c
core: remove Shanghai fork check in GenerateChain
fjl Jan 25, 2023
8bdbf39
consensus/beacon: remove Shanghai fork check in Finalize
fjl Jan 25, 2023
8783b19
core: simplify withdrawals existence check in StateProcessor
fjl Jan 25, 2023
428b0e6
consensus/beacon: ensure correct empty withdrawals root in Shanghai b…
fjl Jan 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
core/beacon: add withdrawals and make types version agnostic
  • Loading branch information
lightclient authored and MariusVanDerWijden committed Jan 25, 2023
commit 72c91a4a788bfd11076138a38fa1bf59b24e2435
37 changes: 22 additions & 15 deletions core/beacon/gen_blockparams.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 57 additions & 50 deletions core/beacon/gen_ed.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 62 additions & 47 deletions core/beacon/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,41 @@ import (
"github.com/ethereum/go-ethereum/trie"
)

//go:generate go run github.com/fjl/gencodec -type PayloadAttributesV1 -field-override payloadAttributesMarshaling -out gen_blockparams.go

// PayloadAttributesV1 structure described at https://github.com/ethereum/execution-apis/pull/74
type PayloadAttributesV1 struct {
Timestamp uint64 `json:"timestamp" gencodec:"required"`
Random common.Hash `json:"prevRandao" gencodec:"required"`
SuggestedFeeRecipient common.Address `json:"suggestedFeeRecipient" gencodec:"required"`
//go:generate go run github.com/fjl/gencodec -type PayloadAttributes -field-override payloadAttributesMarshaling -out gen_blockparams.go

// PayloadAttributes describes the environment context in which a block should
// be built.
type PayloadAttributes struct {
Timestamp uint64 `json:"timestamp" gencodec:"required"`
Random common.Hash `json:"prevRandao" gencodec:"required"`
SuggestedFeeRecipient common.Address `json:"suggestedFeeRecipient" gencodec:"required"`
Withdrawals []*types.Withdrawal `json:"withdrawals"`
}

// JSON type overrides for PayloadAttributesV1.
// JSON type overrides for PayloadAttributes.
type payloadAttributesMarshaling struct {
Timestamp hexutil.Uint64
}

//go:generate go run github.com/fjl/gencodec -type ExecutableDataV1 -field-override executableDataMarshaling -out gen_ed.go

// ExecutableDataV1 structure described at https://github.com/ethereum/execution-apis/tree/main/src/engine/specification.md
type ExecutableDataV1 struct {
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
FeeRecipient common.Address `json:"feeRecipient" gencodec:"required"`
StateRoot common.Hash `json:"stateRoot" gencodec:"required"`
ReceiptsRoot common.Hash `json:"receiptsRoot" gencodec:"required"`
LogsBloom []byte `json:"logsBloom" gencodec:"required"`
Random common.Hash `json:"prevRandao" gencodec:"required"`
Number uint64 `json:"blockNumber" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
Timestamp uint64 `json:"timestamp" gencodec:"required"`
ExtraData []byte `json:"extraData" gencodec:"required"`
BaseFeePerGas *big.Int `json:"baseFeePerGas" gencodec:"required"`
BlockHash common.Hash `json:"blockHash" gencodec:"required"`
Transactions [][]byte `json:"transactions" gencodec:"required"`
//go:generate go run github.com/fjl/gencodec -type ExecutableData -field-override executableDataMarshaling -out gen_ed.go

// ExecutableData is the data necessary to execute an EL payload.
type ExecutableData struct {
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
FeeRecipient common.Address `json:"feeRecipient" gencodec:"required"`
StateRoot common.Hash `json:"stateRoot" gencodec:"required"`
ReceiptsRoot common.Hash `json:"receiptsRoot" gencodec:"required"`
LogsBloom []byte `json:"logsBloom" gencodec:"required"`
Random common.Hash `json:"prevRandao" gencodec:"required"`
Number uint64 `json:"blockNumber" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
Timestamp uint64 `json:"timestamp" gencodec:"required"`
ExtraData []byte `json:"extraData" gencodec:"required"`
BaseFeePerGas *big.Int `json:"baseFeePerGas" gencodec:"required"`
BlockHash common.Hash `json:"blockHash" gencodec:"required"`
Transactions [][]byte `json:"transactions" gencodec:"required"`
Withdrawals []*types.Withdrawal `json:"withdrawals"`
}

// JSON type overrides for executableData.
Expand Down Expand Up @@ -141,8 +144,10 @@ func decodeTransactions(enc [][]byte) ([]*types.Transaction, error) {
// uncleHash = emptyUncleHash
// difficulty = 0
//
// and that the blockhash of the constructed block matches the parameters.
func ExecutableDataToBlock(params ExecutableDataV1) (*types.Block, error) {
// and that the blockhash of the constructed block matches the parameters. Nil
// Withdrawals value will propagate through the returned block. Empty
// Withdrawals value must be passed via non-nil, length 0 value in params.
func ExecutableDataToBlock(params ExecutableData) (*types.Block, error) {
txs, err := decodeTransactions(params.Transactions)
if err != nil {
return nil, err
Expand All @@ -157,34 +162,43 @@ func ExecutableDataToBlock(params ExecutableDataV1) (*types.Block, error) {
if params.BaseFeePerGas != nil && (params.BaseFeePerGas.Sign() == -1 || params.BaseFeePerGas.BitLen() > 256) {
return nil, fmt.Errorf("invalid baseFeePerGas: %v", params.BaseFeePerGas)
}
// Only set withdrawalsRoot if it is non-nil. This allows CLs to use
// ExecutableData before withdrawals are enabled by marshaling
// Withdrawals as the json null value.
var withdrawalsRoot *common.Hash
if params.Withdrawals != nil {
h := types.DeriveSha(types.Withdrawals(params.Withdrawals), trie.NewStackTrie(nil))
withdrawalsRoot = &h
}
header := &types.Header{
ParentHash: params.ParentHash,
UncleHash: types.EmptyUncleHash,
Coinbase: params.FeeRecipient,
Root: params.StateRoot,
TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)),
ReceiptHash: params.ReceiptsRoot,
Bloom: types.BytesToBloom(params.LogsBloom),
Difficulty: common.Big0,
Number: new(big.Int).SetUint64(params.Number),
GasLimit: params.GasLimit,
GasUsed: params.GasUsed,
Time: params.Timestamp,
BaseFee: params.BaseFeePerGas,
Extra: params.ExtraData,
MixDigest: params.Random,
ParentHash: params.ParentHash,
UncleHash: types.EmptyUncleHash,
Coinbase: params.FeeRecipient,
Root: params.StateRoot,
TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)),
ReceiptHash: params.ReceiptsRoot,
Bloom: types.BytesToBloom(params.LogsBloom),
Difficulty: common.Big0,
Number: new(big.Int).SetUint64(params.Number),
GasLimit: params.GasLimit,
GasUsed: params.GasUsed,
Time: params.Timestamp,
BaseFee: params.BaseFeePerGas,
Extra: params.ExtraData,
MixDigest: params.Random,
WithdrawalsHash: withdrawalsRoot,
}
block := types.NewBlockWithHeader(header).WithBody(txs, nil /* uncles */)
block := types.NewBlockWithHeader(header).WithBody2(txs, nil /* uncles */, params.Withdrawals)
if block.Hash() != params.BlockHash {
return nil, fmt.Errorf("blockhash mismatch, want %x, got %x", params.BlockHash, block.Hash())
}
return block, nil
}

// BlockToExecutableData constructs the executableDataV1 structure by filling the
// BlockToExecutableData constructs the ExecutableData structure by filling the
// fields from the given block. It assumes the given block is post-merge block.
func BlockToExecutableData(block *types.Block) *ExecutableDataV1 {
return &ExecutableDataV1{
func BlockToExecutableData(block *types.Block) *ExecutableData {
return &ExecutableData{
BlockHash: block.Hash(),
ParentHash: block.ParentHash(),
FeeRecipient: block.Coinbase(),
Expand All @@ -199,5 +213,6 @@ func BlockToExecutableData(block *types.Block) *ExecutableDataV1 {
Transactions: encodeTransactions(block.Transactions()),
Random: block.MixDigest(),
ExtraData: block.Extra(),
Withdrawals: block.Withdrawals(),
}
}