Skip to content

Commit

Permalink
Pre-Shapella blocks must have nil withdrawals (#13027)
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
yperbasis authored Dec 10, 2024
1 parent 15deff3 commit 478a1da
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions turbo/snapshotsync/freezeblocks/block_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 478a1da

Please sign in to comment.