From 7fb42e6db2dd91c0a82096e6f44733ff73f6a87c Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 15 Feb 2023 13:23:07 +0100 Subject: [PATCH] eth/downloader: handle missing withdrawals if empty list is expected (#26675) This PR relaxes the block body ingress handling a bit: if block body withdrawals are missing (but expected to be empty), the body withdrawals are set to 'empty list' before being passed to upper layers. This fixes an issue where a block passed from EthereumJS to geth was deemed invalid. --- core/genesis.go | 4 +++- eth/downloader/queue.go | 4 ++++ eth/protocols/eth/handler_test.go | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index 1b9ec20ed99d..1120be015f7a 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -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. diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index 13b3021b247d..b90f417ea44b 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -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 && withdrawalLists[index] == nil { + // if the withdrawal hash is the emptyRootHash, + // we expect withdrawals to be [] instead of nil + withdrawalLists[index] = make([]*types.Withdrawal, 0) } else if withdrawalListHashes[index] != *header.WithdrawalsHash { return errInvalidBody } diff --git a/eth/protocols/eth/handler_test.go b/eth/protocols/eth/handler_test.go index 51850c60eae2..76505ab8d32b 100644 --- a/eth/protocols/eth/handler_test.go +++ b/eth/protocols/eth/handler_test.go @@ -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) } } }