Skip to content

Commit 4bcbb8d

Browse files
MarcoFalkePastaPastaPasta
authored andcommitted
Merge bitcoin#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
1 parent 13d7f00 commit 4bcbb8d

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
@@ -2582,7 +2582,10 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
25822582
break;
25832583
} else if (state.GetResult() != TxValidationResult::TX_MISSING_INPUTS) {
25842584
if (state.IsInvalid()) {
2585-
LogPrint(BCLog::MEMPOOL, " invalid orphan tx %s\n", orphanHash.ToString());
2585+
LogPrint(BCLog::MEMPOOL, " invalid orphan tx %s from peer=%d. %s\n",
2586+
orphanHash.ToString(),
2587+
orphan_it->second.fromPeer,
2588+
state.ToString());
25862589
// Maybe punish peer that gave us an invalid orphan tx
25872590
MaybePunishNodeForTx(orphan_it->second.fromPeer, state);
25882591
}
@@ -3742,8 +3745,7 @@ void PeerManagerImpl::ProcessMessage(
37423745
// peer simply for relaying a tx that our m_recent_rejects has caught,
37433746
// regardless of false positives.
37443747

3745-
if (state.IsInvalid())
3746-
{
3748+
if (state.IsInvalid()) {
37473749
LogPrint(BCLog::MEMPOOLREJ, "%s from peer=%d was not accepted: %s\n", tx.GetHash().ToString(),
37483750
pfrom.GetId(),
37493751
state.ToString());

src/validation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,9 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
648648
std::unique_ptr<CTxMemPoolEntry>& entry = ws.m_entry;
649649
CAmount& nModifiedFees = ws.m_modified_fees;
650650

651-
if (!CheckTransaction(tx, state))
651+
if (!CheckTransaction(tx, state)) {
652652
return false; // state filled in by CheckTransaction
653+
}
653654

654655
assert(std::addressof(::ChainstateActive()) == std::addressof(m_active_chainstate));
655656
if (!ContextualCheckTransaction(tx, state, chainparams.GetConsensus(), m_active_chainstate.m_chain.Tip()))
@@ -761,7 +762,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
761762

762763
assert(std::addressof(g_chainman.m_blockman) == std::addressof(m_active_chainstate.m_blockman));
763764
if (!Consensus::CheckTxInputs(tx, state, m_view, m_active_chainstate.m_blockman.GetSpendHeight(m_view), ws.m_base_fees)) {
764-
return error("%s: Consensus::CheckTxInputs: %s, %s", __func__, tx.GetHash().ToString(), state.ToString());
765+
return false; // state filled in by CheckTxInputs
765766
}
766767

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

0 commit comments

Comments
 (0)