Skip to content

Commit

Permalink
Deduplicate code in BlockReader.blockWithSenders (#13028)
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis authored Dec 6, 2024
1 parent 7181f4c commit 8f59ba4
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions turbo/snapshotsync/freezeblocks/block_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,32 +865,23 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c
}
return
}
if txCount == 0 {
block = types.NewBlockFromStorage(hash, h, nil, b.Uncles, b.Withdrawals)
if len(senders) != block.Transactions().Len() {

var txs []types.Transaction
if txCount != 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())
}
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())
defer release()
txs, senders, err = r.txsFromSnapshot(baseTxnId, txCount, txnSeg, buf)
if err != nil {
return nil, nil, err
}
return
}
defer release()
var txs []types.Transaction
txs, senders, err = r.txsFromSnapshot(baseTxnId, txCount, txnSeg, buf)
if err != nil {
return nil, nil, err
release()
}
release()

block = types.NewBlockFromStorage(hash, h, txs, b.Uncles, b.Withdrawals)
if len(senders) != block.Transactions().Len() {
Expand Down

0 comments on commit 8f59ba4

Please sign in to comment.