@@ -1287,44 +1287,45 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
1287
1287
// head from the chain.
1288
1288
// If that is the case, we don't have the lost transactions any more, and
1289
1289
// there's nothing to add
1290
- if newNum < oldNum {
1291
- // If the reorg ended up on a lower number, it's indicative of setHead being the cause
1292
- log .Debug ("Skipping transaction reset caused by setHead" ,
1293
- "old" , oldHead .Hash (), "oldnum" , oldNum , "new" , newHead .Hash (), "newnum" , newNum )
1294
- } else {
1290
+ if newNum >= oldNum {
1295
1291
// If we reorged to a same or higher number, then it's not a case of setHead
1296
1292
log .Warn ("Transaction pool reset with missing oldhead" ,
1297
1293
"old" , oldHead .Hash (), "oldnum" , oldNum , "new" , newHead .Hash (), "newnum" , newNum )
1298
- }
1299
- return
1300
- }
1301
- for rem .NumberU64 () > add .NumberU64 () {
1302
- discarded = append (discarded , rem .Transactions ()... )
1303
- if rem = pool .chain .GetBlock (rem .ParentHash (), rem .NumberU64 ()- 1 ); rem == nil {
1304
- log .Error ("Unrooted old chain seen by tx pool" , "block" , oldHead .Number , "hash" , oldHead .Hash ())
1305
1294
return
1306
1295
}
1307
- }
1308
- for add .NumberU64 () > rem .NumberU64 () {
1309
- included = append (included , add .Transactions ()... )
1310
- if add = pool .chain .GetBlock (add .ParentHash (), add .NumberU64 ()- 1 ); add == nil {
1311
- log .Error ("Unrooted new chain seen by tx pool" , "block" , newHead .Number , "hash" , newHead .Hash ())
1312
- return
1296
+ // If the reorg ended up on a lower number, it's indicative of setHead being the cause
1297
+ log .Debug ("Skipping transaction reset caused by setHead" ,
1298
+ "old" , oldHead .Hash (), "oldnum" , oldNum , "new" , newHead .Hash (), "newnum" , newNum )
1299
+ // We still need to update the current state s.th. the lost transactions can be readded by the user
1300
+ } else {
1301
+ for rem .NumberU64 () > add .NumberU64 () {
1302
+ discarded = append (discarded , rem .Transactions ()... )
1303
+ if rem = pool .chain .GetBlock (rem .ParentHash (), rem .NumberU64 ()- 1 ); rem == nil {
1304
+ log .Error ("Unrooted old chain seen by tx pool" , "block" , oldHead .Number , "hash" , oldHead .Hash ())
1305
+ return
1306
+ }
1313
1307
}
1314
- }
1315
- for rem . Hash () != add .Hash () {
1316
- discarded = append ( discarded , rem . Transactions () ... )
1317
- if rem = pool . chain . GetBlock ( rem . ParentHash (), rem . NumberU64 () - 1 ); rem == nil {
1318
- log . Error ( "Unrooted old chain seen by tx pool" , "block" , oldHead . Number , "hash" , oldHead . Hash ())
1319
- return
1308
+ for add . NumberU64 () > rem . NumberU64 () {
1309
+ included = append ( included , add .Transactions () ... )
1310
+ if add = pool . chain . GetBlock ( add . ParentHash (), add . NumberU64 () - 1 ); add == nil {
1311
+ log . Error ( "Unrooted new chain seen by tx pool" , "block" , newHead . Number , "hash" , newHead . Hash ())
1312
+ return
1313
+ }
1320
1314
}
1321
- included = append (included , add .Transactions ()... )
1322
- if add = pool .chain .GetBlock (add .ParentHash (), add .NumberU64 ()- 1 ); add == nil {
1323
- log .Error ("Unrooted new chain seen by tx pool" , "block" , newHead .Number , "hash" , newHead .Hash ())
1324
- return
1315
+ for rem .Hash () != add .Hash () {
1316
+ discarded = append (discarded , rem .Transactions ()... )
1317
+ if rem = pool .chain .GetBlock (rem .ParentHash (), rem .NumberU64 ()- 1 ); rem == nil {
1318
+ log .Error ("Unrooted old chain seen by tx pool" , "block" , oldHead .Number , "hash" , oldHead .Hash ())
1319
+ return
1320
+ }
1321
+ included = append (included , add .Transactions ()... )
1322
+ if add = pool .chain .GetBlock (add .ParentHash (), add .NumberU64 ()- 1 ); add == nil {
1323
+ log .Error ("Unrooted new chain seen by tx pool" , "block" , newHead .Number , "hash" , newHead .Hash ())
1324
+ return
1325
+ }
1325
1326
}
1327
+ reinject = types .TxDifference (discarded , included )
1326
1328
}
1327
- reinject = types .TxDifference (discarded , included )
1328
1329
}
1329
1330
}
1330
1331
// Initialize the internal state to the current head
0 commit comments