Skip to content

Commit 50422b7

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#26419: log: mempool: log removal reason in validation interface
25ef049 log: mempool: log removal reason in validation interface (James O'Beirne) Pull request description: Currently the exact reason a transaction is removed from the mempool isn't logged. It is sometimes detectable from context, but adding the `reason` to the validation interface logs (where it is already passed) seems like an easy way to disambiguate. For example in the case of mempool expiry, the logs look like this: ``` [validationinterface.cpp:220] [TransactionRemovedFromMempool] [validation] Enqueuing TransactionRemovedFromMempool: txid=<txid> wtxid=<wtxid> [txmempool.cpp:1050] [RemoveUnbroadcastTx] [mempool] Removed <txid> from set of unbroadcast txns before confirmation that txn was sent out [validationinterface.cpp:220] [operator()] [validation] TransactionRemovedFromMempool: txid=<txid> wtxid=<wtxid> [validation.cpp:267] [LimitMempoolSize] [mempool] Expired 1 transactions from the memory pool ``` There is no context-free way to know $txid was evicted on the basis of expiry. This change will make that case (and probably others) clear. ACKs for top commit: 0xB10C: ACK 25ef049 Tree-SHA512: 9890f9fa16f66c8a9296798d8c28993e1b81da17cf592946f2abc22041f0b30b0911ab86a0c48d4aa46b9a8b3f7f5de67778649ac48c97740b0a09aa6816e0af
2 parents ce57dba + 25ef049 commit 50422b7

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/txmempool.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,3 +1182,17 @@ void CTxMemPool::SetLoadTried(bool load_tried)
11821182
LOCK(cs);
11831183
m_load_tried = load_tried;
11841184
}
1185+
1186+
1187+
const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept
1188+
{
1189+
switch (r) {
1190+
case MemPoolRemovalReason::EXPIRY: return "expiry";
1191+
case MemPoolRemovalReason::SIZELIMIT: return "sizelimit";
1192+
case MemPoolRemovalReason::REORG: return "reorg";
1193+
case MemPoolRemovalReason::BLOCK: return "block";
1194+
case MemPoolRemovalReason::CONFLICT: return "conflict";
1195+
case MemPoolRemovalReason::REPLACED: return "replaced";
1196+
}
1197+
assert(false);
1198+
}

src/txmempool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ enum class MemPoolRemovalReason {
355355
REPLACED, //!< Removed for replacement
356356
};
357357

358+
const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept;
359+
358360
/**
359361
* CTxMemPool stores valid-according-to-the-current-best-chain transactions
360362
* that may be included in the next block.

src/validationinterface.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <unordered_map>
1818
#include <utility>
1919

20+
const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept;
21+
2022
/**
2123
* MainSignalsImpl manages a list of shared_ptr<CValidationInterface> callbacks.
2224
*
@@ -215,9 +217,10 @@ void CMainSignals::TransactionRemovedFromMempool(const CTransactionRef& tx, MemP
215217
auto event = [tx, reason, mempool_sequence, this] {
216218
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionRemovedFromMempool(tx, reason, mempool_sequence); });
217219
};
218-
ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__,
220+
ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s reason=%s", __func__,
219221
tx->GetHash().ToString(),
220-
tx->GetWitnessHash().ToString());
222+
tx->GetWitnessHash().ToString(),
223+
RemovalReasonToString(reason));
221224
}
222225

223226
void CMainSignals::BlockConnected(const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex) {

0 commit comments

Comments
 (0)