@@ -387,11 +387,26 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
387
387
} else {
388
388
// Reorg seems shallow enough to pull in all transactions into memory
389
389
var discarded , included types.Transactions
390
-
391
390
var (
392
391
rem = pool .chain .GetBlock (oldHead .Hash (), oldHead .Number .Uint64 ())
393
392
add = pool .chain .GetBlock (newHead .Hash (), newHead .Number .Uint64 ())
394
393
)
394
+ if rem == nil {
395
+ // This can happen if a setHead is performed, where we simply discard the old
396
+ // head from the chain.
397
+ // If that is the case, we don't have the lost transactions any more, and
398
+ // there's nothing to add
399
+ if newNum < oldNum {
400
+ // If the reorg ended up on a lower number, it's indicative of setHead being the cause
401
+ log .Debug ("Skipping transaction reset caused by setHead" ,
402
+ "old" , oldHead .Hash (), "oldnum" , oldNum , "new" , newHead .Hash (), "newnum" , newNum )
403
+ } else {
404
+ // If we reorged to a same or higher number, then it's not a case of setHead
405
+ log .Warn ("Transaction pool reset with missing oldhead" ,
406
+ "old" , oldHead .Hash (), "oldnum" , oldNum , "new" , newHead .Hash (), "newnum" , newNum )
407
+ }
408
+ return
409
+ }
395
410
for rem .NumberU64 () > add .NumberU64 () {
396
411
discarded = append (discarded , rem .Transactions ()... )
397
412
if rem = pool .chain .GetBlock (rem .ParentHash (), rem .NumberU64 ()- 1 ); rem == nil {
0 commit comments