Skip to content

Commit 80279d4

Browse files
stevenlandersudpatil
authored andcommitted
call callback from mempool (#200)
1 parent 585bed3 commit 80279d4

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

internal/mempool/mempool.go

+24-21
Original file line numberDiff line numberDiff line change
@@ -286,27 +286,32 @@ func (txmp *TxMempool) CheckTx(
286286
}
287287

288288
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+
289301
if err != nil {
290-
txmp.cache.Remove(tx)
302+
removeHandler(true)
291303
res.Log = txmp.AppendCheckTxErr(res.Log, err.Error())
292304
}
293305

294306
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,
310315
}
311316

312317
if err == nil {
@@ -561,9 +566,7 @@ func (txmp *TxMempool) addNewTransaction(wtx *WrappedTx, res *abci.ResponseCheck
561566

562567
txmp.metrics.FailedTxs.Add(1)
563568

564-
if !txmp.config.KeepInvalidTxsInCache {
565-
txmp.cache.Remove(wtx.tx)
566-
}
569+
wtx.removeHandler(!txmp.config.KeepInvalidTxsInCache)
567570
if res.Code != abci.CodeTypeOK {
568571
txmp.mtxFailedCheckTxCounts.Lock()
569572
defer txmp.mtxFailedCheckTxCounts.Unlock()
@@ -601,7 +604,7 @@ func (txmp *TxMempool) addNewTransaction(wtx *WrappedTx, res *abci.ResponseCheck
601604
if len(evictTxs) == 0 {
602605
// No room for the new incoming transaction so we just remove it from
603606
// the cache.
604-
txmp.cache.Remove(wtx.tx)
607+
wtx.removeHandler(true)
605608
txmp.logger.Error(
606609
"rejected incoming good transaction; mempool full",
607610
"tx", fmt.Sprintf("%X", wtx.tx.Hash()),
@@ -983,7 +986,7 @@ func (txmp *TxMempool) handlePendingTransactions() {
983986
}
984987
if !txmp.config.KeepInvalidTxsInCache {
985988
for _, tx := range rejected {
986-
txmp.cache.Remove(tx.tx.tx)
989+
tx.tx.removeHandler(true)
987990
}
988991
}
989992
}

0 commit comments

Comments
 (0)