Skip to content

Commit b26d62c

Browse files
author
MarcoFalke
committed
Merge #18990: log: Properly log txs rejected from mempool
fa9f20b log: Properly log txs rejected from mempool (MarcoFalke) Pull request description: Currently `CheckTxInputs` rejections from the mempool are the only rejections that log directly and unconditionally to debug.log instead of leaving it to the caller. This has multiple issues: * A rejected RPC transaction will log a redundant failure reason to debug log. All other failures are merely reported to the RPC user. * A rejected p2p transaction will log the failure twice. Once with the `MEMPOOLREJ` flag, and once unconditionally. * A rejected orphan transaction will log no failure. Fix all issues by simply returning the state to the caller, like it is done for all other rejections. The patch includes whitespace fixups to highlight relevant parts of the codebase and simplify review. ACKs for top commit: naumenkogs: utACK fa9f20b rajarshimaitra: Concept ACK. Compiled and ran tests. `fa9f20b` jnewbery: code review ACK fa9f20b Tree-SHA512: 86cc17b2a9239c01c4fc3f254ad48ee1d3883266966b9811030176338b9ac3deaea7ea5babfb8bbf739d7440154e30011fede8f9313175f199d4a062af6494f7
2 parents 1a655e8 + fa9f20b commit b26d62c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/net_processing.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,10 @@ void static ProcessOrphanTx(CConnman* connman, CTxMemPool& mempool, std::set<uin
19891989
if (MaybePunishNodeForTx(fromPeer, orphan_state)) {
19901990
setMisbehaving.insert(fromPeer);
19911991
}
1992-
LogPrint(BCLog::MEMPOOL, " invalid orphan tx %s\n", orphanHash.ToString());
1992+
LogPrint(BCLog::MEMPOOL, " invalid orphan tx %s from peer=%d. %s\n",
1993+
orphanHash.ToString(),
1994+
fromPeer,
1995+
orphan_state.ToString());
19931996
}
19941997
// Has inputs but not accepted to mempool
19951998
// Probably non-standard or insufficient fee
@@ -2946,8 +2949,7 @@ void ProcessMessage(
29462949
// peer simply for relaying a tx that our recentRejects has caught,
29472950
// regardless of false positives.
29482951

2949-
if (state.IsInvalid())
2950-
{
2952+
if (state.IsInvalid()) {
29512953
LogPrint(BCLog::MEMPOOLREJ, "%s from peer=%d was not accepted: %s\n", tx.GetHash().ToString(),
29522954
pfrom.GetId(),
29532955
state.ToString());

src/validation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,9 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
573573
CAmount& nConflictingFees = ws.m_conflicting_fees;
574574
size_t& nConflictingSize = ws.m_conflicting_size;
575575

576-
if (!CheckTransaction(tx, state))
576+
if (!CheckTransaction(tx, state)) {
577577
return false; // state filled in by CheckTransaction
578+
}
578579

579580
// Coinbase is only valid in a block, not as a loose transaction
580581
if (tx.IsCoinBase())
@@ -684,7 +685,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
684685

685686
CAmount nFees = 0;
686687
if (!Consensus::CheckTxInputs(tx, state, m_view, GetSpendHeight(m_view), nFees)) {
687-
return error("%s: Consensus::CheckTxInputs: %s, %s", __func__, tx.GetHash().ToString(), state.ToString());
688+
return false; // state filled in by CheckTxInputs
688689
}
689690

690691
// Check for non-standard pay-to-script-hash in inputs

0 commit comments

Comments
 (0)