From 68bd8745ee70627878796ad7ada10344201bc3b7 Mon Sep 17 00:00:00 2001 From: Steven Landers Date: Mon, 29 Jan 2024 17:24:10 -0500 Subject: [PATCH] add logging for expired txs --- internal/mempool/mempool.go | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/internal/mempool/mempool.go b/internal/mempool/mempool.go index 612a0bc48..820e46593 100644 --- a/internal/mempool/mempool.go +++ b/internal/mempool/mempool.go @@ -848,6 +848,7 @@ func (txmp *TxMempool) removeTx(wtx *WrappedTx, removeFromCache bool) { // Remove the transaction from the gossip index and cleanup the linked-list // element so it can be garbage collected. + txmp.gossipIndex.Remove(wtx.gossipEl) wtx.gossipEl.DetachPrev() @@ -856,6 +857,32 @@ func (txmp *TxMempool) removeTx(wtx *WrappedTx, removeFromCache bool) { wtx.removeHandler(removeFromCache) } +func (txmp *TxMempool) expire(blockHeight int64, wtx *WrappedTx) { + txmp.metrics.ExpiredTxs.Add(1) + txmp.logExpiredTx(blockHeight, wtx) + wtx.removeHandler(!txmp.config.KeepInvalidTxsInCache) +} + +func (txmp *TxMempool) logExpiredTx(blockHeight int64, wtx *WrappedTx) { + // defensive check + if wtx == nil { + return + } + + txmp.logger.Info( + "transaction expired", + "priority", wtx.priority, + "tx", fmt.Sprintf("%X", wtx.tx.Hash()), + "address", wtx.evmAddress, + "evm", wtx.isEVM, + "nonce", wtx.evmNonce, + "height", blockHeight, + "tx_height", wtx.height, + "tx_timestamp", wtx.timestamp, + "age", time.Since(wtx.timestamp), + ) +} + // purgeExpiredTxs removes all transactions that have exceeded their respective // height- and/or time-based TTLs from their respective indexes. Every expired // transaction will be removed from the mempool, but preserved in the cache (except for pending txs). @@ -902,14 +929,12 @@ func (txmp *TxMempool) purgeExpiredTxs(blockHeight int64) { } for _, wtx := range expiredTxs { - txmp.metrics.ExpiredTxs.Add(1) - txmp.removeTx(wtx, !txmp.config.KeepInvalidTxsInCache) + txmp.expire(blockHeight, wtx) } // remove pending txs that have expired txmp.pendingTxs.PurgeExpired(txmp.config.TTLNumBlocks, blockHeight, txmp.config.TTLDuration, now, func(wtx *WrappedTx) { - txmp.metrics.ExpiredTxs.Add(1) - wtx.removeHandler(!txmp.config.KeepInvalidTxsInCache) + txmp.expire(blockHeight, wtx) }) }