Skip to content

Commit a33dde1

Browse files
committed
[log] include wtxid in tx {relay,validation,orphanage} logging
1 parent ab42b2e commit a33dde1

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

src/net_processing.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,9 +2919,10 @@ bool PeerManagerImpl::ProcessOrphanTx(Peer& peer)
29192919
const MempoolAcceptResult result = m_chainman.ProcessTransaction(porphanTx);
29202920
const TxValidationState& state = result.m_state;
29212921
const uint256& orphanHash = porphanTx->GetHash();
2922+
const uint256& orphan_wtxid = porphanTx->GetWitnessHash();
29222923

29232924
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
2924-
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
2925+
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s (wtxid=%s)\n", orphanHash.ToString(), orphan_wtxid.ToString());
29252926
RelayTransaction(orphanHash, porphanTx->GetWitnessHash());
29262927
m_orphanage.AddChildrenToWorkSet(*porphanTx);
29272928
m_orphanage.EraseTx(orphanHash);
@@ -2931,16 +2932,17 @@ bool PeerManagerImpl::ProcessOrphanTx(Peer& peer)
29312932
return true;
29322933
} else if (state.GetResult() != TxValidationResult::TX_MISSING_INPUTS) {
29332934
if (state.IsInvalid()) {
2934-
LogPrint(BCLog::MEMPOOL, " invalid orphan tx %s from peer=%d. %s\n",
2935+
LogPrint(BCLog::MEMPOOL, " invalid orphan tx %s (wtxid=%s) from peer=%d. %s\n",
29352936
orphanHash.ToString(),
2937+
orphan_wtxid.ToString(),
29362938
peer.m_id,
29372939
state.ToString());
29382940
// Maybe punish peer that gave us an invalid orphan tx
29392941
MaybePunishNodeForTx(peer.m_id, state);
29402942
}
29412943
// Has inputs but not accepted to mempool
29422944
// Probably non-standard or insufficient fee
2943-
LogPrint(BCLog::MEMPOOL, " removed orphan tx %s\n", orphanHash.ToString());
2945+
LogPrint(BCLog::MEMPOOL, " removed orphan tx %s (wtxid=%s)\n", orphanHash.ToString(), orphan_wtxid.ToString());
29442946
if (state.GetResult() != TxValidationResult::TX_WITNESS_STRIPPED) {
29452947
// We can add the wtxid of this transaction to our reject filter.
29462948
// Do not add txids of witness transactions or witness-stripped
@@ -4115,9 +4117,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
41154117
// permission, even if they were already in the mempool, allowing
41164118
// the node to function as a gateway for nodes hidden behind it.
41174119
if (!m_mempool.exists(GenTxid::Txid(tx.GetHash()))) {
4118-
LogPrintf("Not relaying non-mempool transaction %s from forcerelay peer=%d\n", tx.GetHash().ToString(), pfrom.GetId());
4120+
LogPrintf("Not relaying non-mempool transaction %s (wtxid=%s) from forcerelay peer=%d\n",
4121+
tx.GetHash().ToString(), tx.GetWitnessHash().ToString(), pfrom.GetId());
41194122
} else {
4120-
LogPrintf("Force relaying tx %s from peer=%d\n", tx.GetHash().ToString(), pfrom.GetId());
4123+
LogPrintf("Force relaying tx %s (wtxid=%s) from peer=%d\n",
4124+
tx.GetHash().ToString(), tx.GetWitnessHash().ToString(), pfrom.GetId());
41214125
RelayTransaction(tx.GetHash(), tx.GetWitnessHash());
41224126
}
41234127
}
@@ -4137,9 +4141,10 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
41374141

41384142
pfrom.m_last_tx_time = GetTime<std::chrono::seconds>();
41394143

4140-
LogPrint(BCLog::MEMPOOL, "AcceptToMemoryPool: peer=%d: accepted %s (poolsz %u txn, %u kB)\n",
4144+
LogPrint(BCLog::MEMPOOL, "AcceptToMemoryPool: peer=%d: accepted %s (wtxid=%s) (poolsz %u txn, %u kB)\n",
41414145
pfrom.GetId(),
41424146
tx.GetHash().ToString(),
4147+
tx.GetWitnessHash().ToString(),
41434148
m_mempool.size(), m_mempool.DynamicMemoryUsage() / 1000);
41444149

41454150
for (const CTransactionRef& removedTx : result.m_replaced_transactions.value()) {
@@ -4191,7 +4196,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
41914196
// DoS prevention: do not allow m_orphanage to grow unbounded (see CVE-2012-3789)
41924197
m_orphanage.LimitOrphans(m_opts.max_orphan_txs);
41934198
} else {
4194-
LogPrint(BCLog::MEMPOOL, "not keeping orphan with rejected parents %s\n",tx.GetHash().ToString());
4199+
LogPrint(BCLog::MEMPOOL, "not keeping orphan with rejected parents %s (wtxid=%s)\n",
4200+
tx.GetHash().ToString(),
4201+
tx.GetWitnessHash().ToString());
41954202
// We will continue to reject this tx since it has rejected
41964203
// parents so avoid re-requesting it from other peers.
41974204
// Here we add both the txid and the wtxid, as we know that
@@ -4256,7 +4263,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
42564263
// regardless of false positives.
42574264

42584265
if (state.IsInvalid()) {
4259-
LogPrint(BCLog::MEMPOOLREJ, "%s from peer=%d was not accepted: %s\n", tx.GetHash().ToString(),
4266+
LogPrint(BCLog::MEMPOOLREJ, "%s (wtxid=%s) from peer=%d was not accepted: %s\n",
4267+
tx.GetHash().ToString(),
4268+
tx.GetWitnessHash().ToString(),
42604269
pfrom.GetId(),
42614270
state.ToString());
42624271
MaybePunishNodeForTx(pfrom.GetId(), state);

src/txorphanage.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
2121
LOCK(m_mutex);
2222

2323
const uint256& hash = tx->GetHash();
24+
const uint256& wtxid = tx->GetWitnessHash();
2425
if (m_orphans.count(hash))
2526
return false;
2627

@@ -34,7 +35,7 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
3435
unsigned int sz = GetTransactionWeight(*tx);
3536
if (sz > MAX_STANDARD_TX_WEIGHT)
3637
{
37-
LogPrint(BCLog::MEMPOOL, "ignoring large orphan tx (size: %u, hash: %s)\n", sz, hash.ToString());
38+
LogPrint(BCLog::MEMPOOL, "ignoring large orphan tx (size: %u, txid: %s, wtxid: %s)\n", sz, hash.ToString(), wtxid.ToString());
3839
return false;
3940
}
4041

@@ -47,7 +48,7 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
4748
m_outpoint_to_orphan_it[txin.prevout].insert(ret.first);
4849
}
4950

50-
LogPrint(BCLog::MEMPOOL, "stored orphan tx %s (mapsz %u outsz %u)\n", hash.ToString(),
51+
LogPrint(BCLog::MEMPOOL, "stored orphan tx %s (wtxid=%s) (mapsz %u outsz %u)\n", hash.ToString(), wtxid.ToString(),
5152
m_orphans.size(), m_outpoint_to_orphan_it.size());
5253
return true;
5354
}

src/validation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,9 +1079,11 @@ bool MemPoolAccept::Finalize(const ATMPArgs& args, Workspace& ws)
10791079
// Remove conflicting transactions from the mempool
10801080
for (CTxMemPool::txiter it : ws.m_all_conflicting)
10811081
{
1082-
LogPrint(BCLog::MEMPOOL, "replacing tx %s with %s for %s additional fees, %d delta bytes\n",
1082+
LogPrint(BCLog::MEMPOOL, "replacing tx %s (wtxid=%s) with %s (wtxid=%s) for %s additional fees, %d delta bytes\n",
10831083
it->GetTx().GetHash().ToString(),
1084+
it->GetTx().GetWitnessHash().ToString(),
10841085
hash.ToString(),
1086+
tx.GetWitnessHash().ToString(),
10851087
FormatMoney(ws.m_modified_fees - ws.m_conflicting_fees),
10861088
(int)entry->GetTxSize() - (int)ws.m_conflicting_size);
10871089
TRACE7(mempool, replaced,

test/functional/p2p_permissions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def check_tx_relay(self):
106106

107107
self.log.debug("Check that node[1] will send the tx to node[0] even though it is already in the mempool")
108108
self.connect_nodes(1, 0)
109-
with self.nodes[1].assert_debug_log(["Force relaying tx {} from peer=0".format(txid)]):
109+
with self.nodes[1].assert_debug_log(["Force relaying tx {} (wtxid={}) from peer=0".format(txid, tx.getwtxid())]):
110110
p2p_rebroadcast_wallet.send_txs_and_test([tx], self.nodes[1])
111111
self.wait_until(lambda: txid in self.nodes[0].getrawmempool())
112112

@@ -119,14 +119,14 @@ def check_tx_relay(self):
119119
[tx],
120120
self.nodes[1],
121121
success=False,
122-
reject_reason='{} from peer=0 was not accepted: txn-mempool-conflict'.format(txid)
122+
reject_reason='{} (wtxid={}) from peer=0 was not accepted: txn-mempool-conflict'.format(txid, tx.getwtxid())
123123
)
124124

125125
p2p_rebroadcast_wallet.send_txs_and_test(
126126
[tx],
127127
self.nodes[1],
128128
success=False,
129-
reject_reason='Not relaying non-mempool transaction {} from forcerelay peer=0'.format(txid)
129+
reject_reason='Not relaying non-mempool transaction {} (wtxid={}) from forcerelay peer=0'.format(txid, tx.getwtxid())
130130
)
131131

132132
def checkpermission(self, args, expectedPermissions):

0 commit comments

Comments
 (0)