@@ -232,12 +232,11 @@ type TxPool struct {
232
232
locals * accountSet // Set of local transaction to exempt from eviction rules
233
233
journal * txJournal // Journal of local transaction to back up to disk
234
234
235
- pending map [common.Address ]* txList // All currently processable transactions
236
- queue map [common.Address ]* txList // Queued but non-processable transactions
237
- beats map [common.Address ]time.Time // Last heartbeat from each known account
238
- queuedTs map [common.Hash ]time.Time // Timestamp for when queued transactions were added
239
- all * txLookup // All transactions to allow lookups
240
- priced * txPricedList // All transactions sorted by price
235
+ pending map [common.Address ]* txList // All currently processable transactions
236
+ queue map [common.Address ]* txList // Queued but non-processable transactions
237
+ beats map [common.Address ]time.Time // Last heartbeat from each known account
238
+ all * txLookup // All transactions to allow lookups
239
+ priced * txPricedList // All transactions sorted by price
241
240
242
241
chainHeadCh chan ChainHeadEvent
243
242
chainHeadSub event.Subscription
@@ -268,7 +267,6 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block
268
267
pending : make (map [common.Address ]* txList ),
269
268
queue : make (map [common.Address ]* txList ),
270
269
beats : make (map [common.Address ]time.Time ),
271
- queuedTs : make (map [common.Hash ]time.Time ),
272
270
all : newTxLookup (),
273
271
chainHeadCh : make (chan ChainHeadEvent , chainHeadChanSize ),
274
272
reqResetCh : make (chan * txpoolResetRequest ),
@@ -365,12 +363,11 @@ func (pool *TxPool) loop() {
365
363
}
366
364
// Any non-locals old enough should be removed
367
365
if time .Since (pool .beats [addr ]) > pool .config .Lifetime {
368
- for _ , tx := range pool .queue [addr ].Flatten () {
369
- if time .Since (pool .queuedTs [tx .Hash ()]) > pool .config .Lifetime {
370
- queuedEvictionMeter .Mark (1 )
371
- pool .removeTx (tx .Hash (), true )
372
- }
366
+ list := pool .queue [addr ].Flatten ()
367
+ for _ , tx := range list {
368
+ pool .removeTx (tx .Hash (), true )
373
369
}
370
+ queuedEvictionMeter .Mark (int64 (len (list )))
374
371
}
375
372
}
376
373
pool .mu .Unlock ()
@@ -622,9 +619,11 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
622
619
pool .all .Add (tx )
623
620
pool .priced .Put (tx )
624
621
pool .journalTx (from , tx )
625
- pool .beats [from ] = time .Now ()
626
622
pool .queueTxEvent (tx )
627
623
log .Trace ("Pooled new executable transaction" , "hash" , hash , "from" , from , "to" , tx .To ())
624
+
625
+ // Successful promotion, bump the heartbeat
626
+ pool .beats [from ] = time .Now ()
628
627
return old != nil , nil
629
628
}
630
629
// New transaction isn't replacing a pending one, push into queue
@@ -665,20 +664,20 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction) (bool, er
665
664
}
666
665
// Discard any previous transaction and mark this
667
666
if old != nil {
668
- old_hash := old .Hash ()
669
- pool .all .Remove (old_hash )
667
+ pool .all .Remove (old .Hash ())
670
668
pool .priced .Removed (1 )
671
- delete (pool .queuedTs , old_hash )
672
669
queuedReplaceMeter .Mark (1 )
673
670
} else {
674
671
// Nothing was replaced, bump the queued counter
675
672
queuedGauge .Inc (1 )
676
- pool .queuedTs [hash ] = time .Now ()
677
673
}
678
674
if pool .all .Get (hash ) == nil {
679
675
pool .all .Add (tx )
680
676
pool .priced .Put (tx )
681
- pool .queuedTs [hash ] = time .Now ()
677
+ }
678
+ // If we never record the heartbeat, do it right now.
679
+ if _ , exist := pool .beats [from ]; ! exist {
680
+ pool .beats [from ] = time .Now ()
682
681
}
683
682
return old != nil , nil
684
683
}
@@ -711,7 +710,6 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
711
710
// An older transaction was better, discard this
712
711
pool .all .Remove (hash )
713
712
pool .priced .Removed (1 )
714
- delete (pool .queuedTs , hash )
715
713
pendingDiscardMeter .Mark (1 )
716
714
return false
717
715
}
@@ -730,10 +728,10 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
730
728
pool .priced .Put (tx )
731
729
}
732
730
// Set the potentially new pending nonce and notify any subsystems of the new tx
733
- pool .beats [addr ] = time .Now ()
734
- delete (pool .queuedTs , hash )
735
731
pool .pendingNonces .set (addr , tx .Nonce ()+ 1 )
736
732
733
+ // Successful promotion, bump the heartbeat
734
+ pool .beats [addr ] = time .Now ()
737
735
return true
738
736
}
739
737
@@ -923,10 +921,10 @@ func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {
923
921
if removed , _ := future .Remove (tx ); removed {
924
922
// Reduce the queued counter
925
923
queuedGauge .Dec (1 )
926
- delete (pool .queuedTs , hash )
927
924
}
928
925
if future .Empty () {
929
926
delete (pool .queue , addr )
927
+ delete (pool .beats , addr )
930
928
}
931
929
}
932
930
}
@@ -1202,15 +1200,13 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
1202
1200
for _ , tx := range forwards {
1203
1201
hash := tx .Hash ()
1204
1202
pool .all .Remove (hash )
1205
- delete (pool .queuedTs , hash )
1206
1203
}
1207
1204
log .Trace ("Removed old queued transactions" , "count" , len (forwards ))
1208
1205
// Drop all transactions that are too costly (low balance or out of gas)
1209
1206
drops , _ := list .Filter (pool .currentState .GetBalance (addr ).Uint64 (), pool .currentMaxGas )
1210
1207
for _ , tx := range drops {
1211
1208
hash := tx .Hash ()
1212
1209
pool .all .Remove (hash )
1213
- delete (pool .queuedTs , hash )
1214
1210
}
1215
1211
log .Trace ("Removed unpayable queued transactions" , "count" , len (drops ))
1216
1212
queuedNofundsMeter .Mark (int64 (len (drops )))
@@ -1233,7 +1229,6 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
1233
1229
for _ , tx := range caps {
1234
1230
hash := tx .Hash ()
1235
1231
pool .all .Remove (hash )
1236
- delete (pool .queuedTs , hash )
1237
1232
log .Trace ("Removed cap-exceeding queued transaction" , "hash" , hash )
1238
1233
}
1239
1234
queuedRateLimitMeter .Mark (int64 (len (caps )))
@@ -1247,6 +1242,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
1247
1242
// Delete the entire queue entry if it became empty.
1248
1243
if list .Empty () {
1249
1244
delete (pool .queue , addr )
1245
+ delete (pool .beats , addr )
1250
1246
}
1251
1247
}
1252
1248
return promoted
@@ -1431,7 +1427,6 @@ func (pool *TxPool) demoteUnexecutables() {
1431
1427
// Delete the entire pending entry if it became empty.
1432
1428
if list .Empty () {
1433
1429
delete (pool .pending , addr )
1434
- delete (pool .beats , addr )
1435
1430
}
1436
1431
}
1437
1432
}
0 commit comments