Skip to content

Commit

Permalink
Log MemPoolRemovalReason in validation interface
Browse files Browse the repository at this point in the history
The reason parameter was removed in bitcoin#14384 as part of a clean-up but
the reason would be useful to log according to comments on the PR.
  • Loading branch information
jkczyz committed Nov 22, 2019
1 parent 0cadb12 commit 34d6486
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
24 changes: 23 additions & 1 deletion src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <txmempool.h>

#include <cassert>

#include <consensus/consensus.h>
#include <consensus/tx_verify.h>
#include <consensus/validation.h>
Expand Down Expand Up @@ -407,7 +409,7 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
CTransactionRef ptx = it->GetSharedTx();
NotifyEntryRemoved(ptx, reason);
if (reason != MemPoolRemovalReason::BLOCK && reason != MemPoolRemovalReason::CONFLICT) {
GetMainSignals().TransactionRemovedFromMempool(ptx);
GetMainSignals().TransactionRemovedFromMempool(ptx, reason);
}

const uint256 hash = it->GetTx().GetHash();
Expand Down Expand Up @@ -1106,3 +1108,23 @@ void CTxMemPool::SetIsLoaded(bool loaded)
}

SaltedTxidHasher::SaltedTxidHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}

std::string MemPoolRemovalReasonString(const MemPoolRemovalReason reason)
{
switch (reason) {
case MemPoolRemovalReason::EXPIRY:
return "EXPIRY";
case MemPoolRemovalReason::SIZELIMIT:
return "SIZELIMIT";
case MemPoolRemovalReason::REORG:
return "REORG";
case MemPoolRemovalReason::BLOCK:
return "BLOCK";
case MemPoolRemovalReason::CONFLICT:
return "CONFLICT";
case MemPoolRemovalReason::REPLACED:
return "REPLACED";
} // no default case, so the compiler can warn about missing cases

assert(false);
}
2 changes: 2 additions & 0 deletions src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ enum class MemPoolRemovalReason {
REPLACED, //!< Removed for replacement
};

std::string MemPoolRemovalReasonString(const MemPoolRemovalReason reason);

class SaltedTxidHasher
{
private:
Expand Down
8 changes: 5 additions & 3 deletions src/validationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <scheduler.h>
#include <txmempool.h>
#include <util/validation.h>

#include <future>
Expand Down Expand Up @@ -154,13 +155,14 @@ void CMainSignals::TransactionAddedToMempool(const CTransactionRef &ptx) {
ptx->GetWitnessHash().ToString());
}

void CMainSignals::TransactionRemovedFromMempool(const CTransactionRef &ptx) {
void CMainSignals::TransactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolRemovalReason reason) {
auto event = [ptx, this] {
m_internals->TransactionRemovedFromMempool(ptx);
};
ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__,
ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s reason=%s", __func__,
ptx->GetHash().ToString(),
ptx->GetWitnessHash().ToString());
ptx->GetWitnessHash().ToString(),
MemPoolRemovalReasonString(reason));
}

void CMainSignals::BlockConnected(const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex, const std::shared_ptr<const std::vector<CTransactionRef>>& pvtxConflicted) {
Expand Down
3 changes: 2 additions & 1 deletion src/validationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CConnman;
class CValidationInterface;
class uint256;
class CScheduler;
enum class MemPoolRemovalReason;

// These functions dispatch to one or all registered wallets

Expand Down Expand Up @@ -169,7 +170,7 @@ class CMainSignals {

void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload);
void TransactionAddedToMempool(const CTransactionRef &);
void TransactionRemovedFromMempool(const CTransactionRef &);
void TransactionRemovedFromMempool(const CTransactionRef &, MemPoolRemovalReason reason);
void BlockConnected(const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex, const std::shared_ptr<const std::vector<CTransactionRef>> &);
void BlockDisconnected(const std::shared_ptr<const CBlock> &, const CBlockIndex* pindex);
void ChainStateFlushed(const CBlockLocator &);
Expand Down

0 comments on commit 34d6486

Please sign in to comment.