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

core/types: manually set withdrawals if withdrawalHash is emptyRootHash #26675

Merged
merged 4 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
4 changes: 3 additions & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,12 @@ func (g *Genesis) ToBlock() *types.Block {
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
}
}
var withdrawals []*types.Withdrawal
if g.Config != nil && g.Config.IsShanghai(g.Timestamp) {
head.WithdrawalsHash = &types.EmptyRootHash
withdrawals = make([]*types.Withdrawal, 0)
}
return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil))
return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil)).WithWithdrawals(withdrawals)
}

// Commit writes the block and state of a genesis specification to the database.
Expand Down
4 changes: 4 additions & 0 deletions eth/downloader/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,10 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListH
if header.WithdrawalsHash == nil {
// discard any withdrawals if we don't have a withdrawal hash set
withdrawalLists[index] = nil
} else if *header.WithdrawalsHash == types.EmptyRootHash {
// if the withdrawal hash is the emptyRootHash,
// we expect withdrawals to be [] instead of nil
withdrawalLists[index] = make([]*types.Withdrawal, 0)
MariusVanDerWijden marked this conversation as resolved.
Show resolved Hide resolved
} else if withdrawalListHashes[index] != *header.WithdrawalsHash {
return errInvalidBody
}
Expand Down
2 changes: 1 addition & 1 deletion eth/protocols/eth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func testGetBlockBodies(t *testing.T, protocol uint) {
RequestId: 123,
BlockBodiesPacket: bodies,
}); err != nil {
t.Errorf("test %d: bodies mismatch: %v", i, err)
t.Fatalf("test %d: bodies mismatch: %v", i, err)
}
}
}
Expand Down