From 478a1dac60d10b537c13246b7343e9ae06c311d2 Mon Sep 17 00:00:00 2001 From: Andrew Ashikhmin <34320705+yperbasis@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:01:48 +0100 Subject: [PATCH] Pre-Shapella blocks must have nil withdrawals (#13027) Apparently we saved some pre-Shappella blocks into snapshots with empty rather than nil withdrawals. This is a work-around for issues like #12297 to avoid regenerating block snapshots. You can see the problem by running ``` curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x103716A",false],"id":1}' http://localhost:8545 ``` --- .../snapshotsync/freezeblocks/block_reader.go | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/turbo/snapshotsync/freezeblocks/block_reader.go b/turbo/snapshotsync/freezeblocks/block_reader.go index 61135fdfbf4..022c524216f 100644 --- a/turbo/snapshotsync/freezeblocks/block_reader.go +++ b/turbo/snapshotsync/freezeblocks/block_reader.go @@ -712,33 +712,29 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c } return } - if txsAmount == 0 { - block = types.NewBlockFromStorage(hash, h, nil, b.Uncles, b.Withdrawals) - if len(senders) != block.Transactions().Len() { + + var txs []types.Transaction + if txsAmount != 0 { + txnSeg, ok, release := r.sn.ViewSingleFile(coresnaptype.Transactions, blockHeight) + if !ok { if dbgLogs { - log.Info(dbgPrefix + fmt.Sprintf("found block with %d transactions, but %d senders", block.Transactions().Len(), len(senders))) + log.Info(dbgPrefix+"no transactions file for this block num", "r.sn.BlocksAvailable()", r.sn.BlocksAvailable(), "r.sn.indicesReady", r.sn.indicesReady.Load()) } - return block, senders, nil // no senders is fine - will recover them on the fly + return } - block.SendersToTxs(senders) - return block, senders, nil - } - - txnSeg, ok, release := r.sn.ViewSingleFile(coresnaptype.Transactions, blockHeight) - if !ok { - if dbgLogs { - log.Info(dbgPrefix+"no transactions file for this block num", "r.sn.BlocksAvailable()", r.sn.BlocksAvailable(), "r.sn.indicesReady", r.sn.indicesReady.Load()) + defer release() + txs, senders, err = r.txsFromSnapshot(baseTxnId, txsAmount, txnSeg, buf) + if err != nil { + return nil, nil, err } - return - } - defer release() - var txs []types.Transaction - txs, senders, err = r.txsFromSnapshot(baseTxnId, txsAmount, txnSeg, buf) - if err != nil { - return nil, nil, err + release() } - release() + if h.WithdrawalsHash == nil && len(b.Withdrawals) == 0 { + // Hack for Issue 12297 + // Apparently some snapshots have pre-Shapella blocks with empty rather than nil withdrawals + b.Withdrawals = nil + } block = types.NewBlockFromStorage(hash, h, txs, b.Uncles, b.Withdrawals) if len(senders) != block.Transactions().Len() { if dbgLogs {