Skip to content

Commit

Permalink
fix expire metric (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenlanders authored and udpatil committed Apr 16, 2024
1 parent 36ad021 commit f0e859d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions internal/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ func (txmp *TxMempool) CheckTx(
evmNonce: res.EVMNonce,
evmAddress: res.EVMSenderAddress,
isEVM: res.IsEVM,
expiredCallback: func(removeFromCache bool) {
txmp.metrics.ExpiredTxs.Add(1)
removeHandler: func(removeFromCache bool) {
if removeFromCache {
txmp.cache.Remove(tx)
}
Expand Down Expand Up @@ -856,7 +855,7 @@ func (txmp *TxMempool) removeTx(wtx *WrappedTx, removeFromCache bool) {

atomic.AddInt64(&txmp.sizeBytes, int64(-wtx.Size()))

wtx.expiredCallback(removeFromCache)
wtx.removeHandler(removeFromCache)
}

// purgeExpiredTxs removes all transactions that have exceeded their respective
Expand Down Expand Up @@ -905,12 +904,14 @@ func (txmp *TxMempool) purgeExpiredTxs(blockHeight int64) {
}

for _, wtx := range expiredTxs {
txmp.metrics.ExpiredTxs.Add(1)
txmp.removeTx(wtx, !txmp.config.KeepInvalidTxsInCache)
}

// remove pending txs that have expired
txmp.pendingTxs.PurgeExpired(txmp.config.TTLNumBlocks, blockHeight, txmp.config.TTLDuration, now, func(wtx *WrappedTx) {
wtx.expiredCallback(!txmp.config.KeepInvalidTxsInCache)
txmp.metrics.ExpiredTxs.Add(1)
wtx.removeHandler(!txmp.config.KeepInvalidTxsInCache)
})
}

Expand Down
4 changes: 2 additions & 2 deletions internal/mempool/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ type WrappedTx struct {
// a reCheckTx callback executed.
removed bool

// this is the callback that can be called when a transaction expires
expiredCallback func(removeFromCache bool)
// this is the callback that can be called when a transaction is removed
removeHandler func(removeFromCache bool)

// evm properties that aid in prioritization
evmAddress string
Expand Down

0 comments on commit f0e859d

Please sign in to comment.