mempool: log if we detect a non-optimal mempool
What changed, and why it matters
This commit only adds extra logging messages. It does not change how the mempool behaves or fix any bug. It lets developers see, via debug logs, when the mempool's internal transaction ordering is not in the best possible state after routine events such as adding transactions, handling blockchain reorganizations, or processing a new block. The change is observability-only and not a security patch.
No security action required. Treat as normal observability/logging improvement. If reviewing related work, confirm that non-optimal mempool ordering is handled safely elsewhere; this commit only surfaces the condition for debugging.
Security signals we found
No security fix: only adds debug logging
No change to transaction validation, eviction, fee estimation, or P2P behavior
No new assertions, locks, or resource limits introduced
No memory-safety, cryptographic, or consensus code touched
Evidence from the diff
The patch modifies CTxMemPool::Apply, removeForReorg, and removeForBlock in src/txmempool.cpp to capture the boolean return value of m_txgraph->DoWork(POST_CHANGE_WORK). When DoWork returns false, indicating the mempool graph is in a non-optimal ordering, a LogDebug(BCLog::MEMPOOL, …) message is emitted. No logic, assertions, or behavior are changed; the return value was previously discarded. This is a diagnostic/instrumentation change.
Changed components
src/txmempool.cppCTxMemPool::ApplyCTxMemPool::removeForReorgCTxMemPool::removeForBlockmempool debug logging (BCLog::MEMPOOL)Inspect captured patch +9 / −3
diff --git a/src/txmempool.cpp b/src/txmempool.cpp
index b8be3e08..27b4c886 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -221,7 +221,9 @@ void CTxMemPool::Apply(ChangeSet* changeset)
addNewTransaction(it);
}
- m_txgraph->DoWork(POST_CHANGE_WORK);
+ if (!m_txgraph->DoWork(POST_CHANGE_WORK)) {
+ LogDebug(BCLog::MEMPOOL, "Mempool in non-optimal ordering after addition(s).");
+ }
}
void CTxMemPool::addNewTransaction(CTxMemPool::txiter newit)
@@ -378,7 +380,9 @@ void CTxMemPool::removeForReorg(CChain& chain, std::function<bool(txiter)> check
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
assert(TestLockPointValidity(chain, it->GetLockPoints()));
}
- m_txgraph->DoWork(POST_CHANGE_WORK);
+ if (!m_txgraph->DoWork(POST_CHANGE_WORK)) {
+ LogDebug(BCLog::MEMPOOL, "Mempool in non-optimal ordering after reorg.");
+ }
}
void CTxMemPool::removeConflicts(const CTransaction &tx)
@@ -421,7 +425,9 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
}
lastRollingFeeUpdate = GetTime();
blockSinceLastRollingFeeBump = true;
- m_txgraph->DoWork(POST_CHANGE_WORK);
+ if (!m_txgraph->DoWork(POST_CHANGE_WORK)) {
+ LogDebug(BCLog::MEMPOOL, "Mempool in non-optimal ordering after block.");
+ }
}
void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendheight) const
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.