@@ -286,27 +286,32 @@ func (txmp *TxMempool) CheckTx(
286
286
}
287
287
288
288
res , err := txmp .proxyAppConn .CheckTx (ctx , & abci.RequestCheckTx {Tx : tx })
289
+
290
+ // when a transaction is removed/expired/rejected, this should be called
291
+ // The expire tx handler unreserves the pending nonce
292
+ removeHandler := func (removeFromCache bool ) {
293
+ if removeFromCache {
294
+ txmp .cache .Remove (tx )
295
+ }
296
+ if res .ExpireTxHandler != nil {
297
+ res .ExpireTxHandler ()
298
+ }
299
+ }
300
+
289
301
if err != nil {
290
- txmp . cache . Remove ( tx )
302
+ removeHandler ( true )
291
303
res .Log = txmp .AppendCheckTxErr (res .Log , err .Error ())
292
304
}
293
305
294
306
wtx := & WrappedTx {
295
- tx : tx ,
296
- hash : txHash ,
297
- timestamp : time .Now ().UTC (),
298
- height : txmp .height ,
299
- evmNonce : res .EVMNonce ,
300
- evmAddress : res .EVMSenderAddress ,
301
- isEVM : res .IsEVM ,
302
- removeHandler : func (removeFromCache bool ) {
303
- if removeFromCache {
304
- txmp .cache .Remove (tx )
305
- }
306
- if res .ExpireTxHandler != nil {
307
- res .ExpireTxHandler ()
308
- }
309
- },
307
+ tx : tx ,
308
+ hash : txHash ,
309
+ timestamp : time .Now ().UTC (),
310
+ height : txmp .height ,
311
+ evmNonce : res .EVMNonce ,
312
+ evmAddress : res .EVMSenderAddress ,
313
+ isEVM : res .IsEVM ,
314
+ removeHandler : removeHandler ,
310
315
}
311
316
312
317
if err == nil {
@@ -561,9 +566,7 @@ func (txmp *TxMempool) addNewTransaction(wtx *WrappedTx, res *abci.ResponseCheck
561
566
562
567
txmp .metrics .FailedTxs .Add (1 )
563
568
564
- if ! txmp .config .KeepInvalidTxsInCache {
565
- txmp .cache .Remove (wtx .tx )
566
- }
569
+ wtx .removeHandler (! txmp .config .KeepInvalidTxsInCache )
567
570
if res .Code != abci .CodeTypeOK {
568
571
txmp .mtxFailedCheckTxCounts .Lock ()
569
572
defer txmp .mtxFailedCheckTxCounts .Unlock ()
@@ -601,7 +604,7 @@ func (txmp *TxMempool) addNewTransaction(wtx *WrappedTx, res *abci.ResponseCheck
601
604
if len (evictTxs ) == 0 {
602
605
// No room for the new incoming transaction so we just remove it from
603
606
// the cache.
604
- txmp . cache . Remove ( wtx .tx )
607
+ wtx .removeHandler ( true )
605
608
txmp .logger .Error (
606
609
"rejected incoming good transaction; mempool full" ,
607
610
"tx" , fmt .Sprintf ("%X" , wtx .tx .Hash ()),
@@ -983,7 +986,7 @@ func (txmp *TxMempool) handlePendingTransactions() {
983
986
}
984
987
if ! txmp .config .KeepInvalidTxsInCache {
985
988
for _ , tx := range rejected {
986
- txmp . cache . Remove ( tx .tx .tx )
989
+ tx .tx .removeHandler ( true )
987
990
}
988
991
}
989
992
}
0 commit comments