Skip to content

Commit c5b22fb

Browse files
committed
core: make txpool handle reorg due to setHead (ethereum#19308)
1 parent 676c4e8 commit c5b22fb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

core/tx_pool.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,22 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
415415
rem = pool.chain.GetBlock(oldHead.Hash(), oldHead.Number.Uint64())
416416
add = pool.chain.GetBlock(newHead.Hash(), newHead.Number.Uint64())
417417
)
418+
if rem == nil {
419+
// This can happen if a setHead is performed, where we simply discard the old
420+
// head from the chain.
421+
// If that is the case, we don't have the lost transactions any more, and
422+
// there's nothing to add
423+
if newNum < oldNum {
424+
// If the reorg ended up on a lower number, it's indicative of setHead being the cause
425+
log.Debug("Skipping transaction reset caused by setHead",
426+
"old", oldHead.Hash(), "oldnum", oldNum, "new", newHead.Hash(), "newnum", newNum)
427+
} else {
428+
// If we reorged to a same or higher number, then it's not a case of setHead
429+
log.Warn("Transaction pool reset with missing oldhead",
430+
"old", oldHead.Hash(), "oldnum", oldNum, "new", newHead.Hash(), "newnum", newNum)
431+
}
432+
return
433+
}
418434
for rem.NumberU64() > add.NumberU64() {
419435
discarded = append(discarded, rem.Transactions()...)
420436
if rem = pool.chain.GetBlock(rem.ParentHash(), rem.NumberU64()-1); rem == nil {

0 commit comments

Comments
 (0)