Skip to content

Commit 7fb42e6

Browse files
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.
1 parent 5967a22 commit 7fb42e6

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

core/genesis.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,12 @@ func (g *Genesis) ToBlock() *types.Block {
465465
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
466466
}
467467
}
468+
var withdrawals []*types.Withdrawal
468469
if g.Config != nil && g.Config.IsShanghai(g.Timestamp) {
469470
head.WithdrawalsHash = &types.EmptyRootHash
471+
withdrawals = make([]*types.Withdrawal, 0)
470472
}
471-
return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil))
473+
return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil)).WithWithdrawals(withdrawals)
472474
}
473475

474476
// Commit writes the block and state of a genesis specification to the database.

eth/downloader/queue.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,10 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListH
783783
if header.WithdrawalsHash == nil {
784784
// discard any withdrawals if we don't have a withdrawal hash set
785785
withdrawalLists[index] = nil
786+
} else if *header.WithdrawalsHash == types.EmptyRootHash && withdrawalLists[index] == nil {
787+
// if the withdrawal hash is the emptyRootHash,
788+
// we expect withdrawals to be [] instead of nil
789+
withdrawalLists[index] = make([]*types.Withdrawal, 0)
786790
} else if withdrawalListHashes[index] != *header.WithdrawalsHash {
787791
return errInvalidBody
788792
}

eth/protocols/eth/handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func testGetBlockBodies(t *testing.T, protocol uint) {
424424
RequestId: 123,
425425
BlockBodiesPacket: bodies,
426426
}); err != nil {
427-
t.Errorf("test %d: bodies mismatch: %v", i, err)
427+
t.Fatalf("test %d: bodies mismatch: %v", i, err)
428428
}
429429
}
430430
}

0 commit comments

Comments
 (0)