[log] include wtxid in tx {relay,validation,orphanage} logging

pull/28364/head
glozow 1 year ago
parent ab42b2ebdb
commit a33dde1e41

@ -2919,9 +2919,10 @@ bool PeerManagerImpl::ProcessOrphanTx(Peer& peer)
const MempoolAcceptResult result = m_chainman.ProcessTransaction(porphanTx); const MempoolAcceptResult result = m_chainman.ProcessTransaction(porphanTx);
const TxValidationState& state = result.m_state; const TxValidationState& state = result.m_state;
const uint256& orphanHash = porphanTx->GetHash(); const uint256& orphanHash = porphanTx->GetHash();
const uint256& orphan_wtxid = porphanTx->GetWitnessHash();
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) { if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString()); LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s (wtxid=%s)\n", orphanHash.ToString(), orphan_wtxid.ToString());
RelayTransaction(orphanHash, porphanTx->GetWitnessHash()); RelayTransaction(orphanHash, porphanTx->GetWitnessHash());
m_orphanage.AddChildrenToWorkSet(*porphanTx); m_orphanage.AddChildrenToWorkSet(*porphanTx);
m_orphanage.EraseTx(orphanHash); m_orphanage.EraseTx(orphanHash);
@ -2931,8 +2932,9 @@ bool PeerManagerImpl::ProcessOrphanTx(Peer& peer)
return true; return true;
} else if (state.GetResult() != TxValidationResult::TX_MISSING_INPUTS) { } else if (state.GetResult() != TxValidationResult::TX_MISSING_INPUTS) {
if (state.IsInvalid()) { if (state.IsInvalid()) {
LogPrint(BCLog::MEMPOOL, " invalid orphan tx %s from peer=%d. %s\n", LogPrint(BCLog::MEMPOOL, " invalid orphan tx %s (wtxid=%s) from peer=%d. %s\n",
orphanHash.ToString(), orphanHash.ToString(),
orphan_wtxid.ToString(),
peer.m_id, peer.m_id,
state.ToString()); state.ToString());
// Maybe punish peer that gave us an invalid orphan tx // Maybe punish peer that gave us an invalid orphan tx
@ -2940,7 +2942,7 @@ bool PeerManagerImpl::ProcessOrphanTx(Peer& peer)
} }
// Has inputs but not accepted to mempool // Has inputs but not accepted to mempool
// Probably non-standard or insufficient fee // Probably non-standard or insufficient fee
LogPrint(BCLog::MEMPOOL, " removed orphan tx %s\n", orphanHash.ToString()); LogPrint(BCLog::MEMPOOL, " removed orphan tx %s (wtxid=%s)\n", orphanHash.ToString(), orphan_wtxid.ToString());
if (state.GetResult() != TxValidationResult::TX_WITNESS_STRIPPED) { if (state.GetResult() != TxValidationResult::TX_WITNESS_STRIPPED) {
// We can add the wtxid of this transaction to our reject filter. // We can add the wtxid of this transaction to our reject filter.
// Do not add txids of witness transactions or witness-stripped // Do not add txids of witness transactions or witness-stripped
@ -4115,9 +4117,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
// permission, even if they were already in the mempool, allowing // permission, even if they were already in the mempool, allowing
// the node to function as a gateway for nodes hidden behind it. // the node to function as a gateway for nodes hidden behind it.
if (!m_mempool.exists(GenTxid::Txid(tx.GetHash()))) { if (!m_mempool.exists(GenTxid::Txid(tx.GetHash()))) {
LogPrintf("Not relaying non-mempool transaction %s from forcerelay peer=%d\n", tx.GetHash().ToString(), pfrom.GetId()); LogPrintf("Not relaying non-mempool transaction %s (wtxid=%s) from forcerelay peer=%d\n",
tx.GetHash().ToString(), tx.GetWitnessHash().ToString(), pfrom.GetId());
} else { } else {
LogPrintf("Force relaying tx %s from peer=%d\n", tx.GetHash().ToString(), pfrom.GetId()); LogPrintf("Force relaying tx %s (wtxid=%s) from peer=%d\n",
tx.GetHash().ToString(), tx.GetWitnessHash().ToString(), pfrom.GetId());
RelayTransaction(tx.GetHash(), tx.GetWitnessHash()); RelayTransaction(tx.GetHash(), tx.GetWitnessHash());
} }
} }
@ -4137,9 +4141,10 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
pfrom.m_last_tx_time = GetTime<std::chrono::seconds>(); pfrom.m_last_tx_time = GetTime<std::chrono::seconds>();
LogPrint(BCLog::MEMPOOL, "AcceptToMemoryPool: peer=%d: accepted %s (poolsz %u txn, %u kB)\n", LogPrint(BCLog::MEMPOOL, "AcceptToMemoryPool: peer=%d: accepted %s (wtxid=%s) (poolsz %u txn, %u kB)\n",
pfrom.GetId(), pfrom.GetId(),
tx.GetHash().ToString(), tx.GetHash().ToString(),
tx.GetWitnessHash().ToString(),
m_mempool.size(), m_mempool.DynamicMemoryUsage() / 1000); m_mempool.size(), m_mempool.DynamicMemoryUsage() / 1000);
for (const CTransactionRef& removedTx : result.m_replaced_transactions.value()) { for (const CTransactionRef& removedTx : result.m_replaced_transactions.value()) {
@ -4191,7 +4196,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
// DoS prevention: do not allow m_orphanage to grow unbounded (see CVE-2012-3789) // DoS prevention: do not allow m_orphanage to grow unbounded (see CVE-2012-3789)
m_orphanage.LimitOrphans(m_opts.max_orphan_txs); m_orphanage.LimitOrphans(m_opts.max_orphan_txs);
} else { } else {
LogPrint(BCLog::MEMPOOL, "not keeping orphan with rejected parents %s\n",tx.GetHash().ToString()); LogPrint(BCLog::MEMPOOL, "not keeping orphan with rejected parents %s (wtxid=%s)\n",
tx.GetHash().ToString(),
tx.GetWitnessHash().ToString());
// We will continue to reject this tx since it has rejected // We will continue to reject this tx since it has rejected
// parents so avoid re-requesting it from other peers. // parents so avoid re-requesting it from other peers.
// Here we add both the txid and the wtxid, as we know that // 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,
// regardless of false positives. // regardless of false positives.
if (state.IsInvalid()) { if (state.IsInvalid()) {
LogPrint(BCLog::MEMPOOLREJ, "%s from peer=%d was not accepted: %s\n", tx.GetHash().ToString(), LogPrint(BCLog::MEMPOOLREJ, "%s (wtxid=%s) from peer=%d was not accepted: %s\n",
tx.GetHash().ToString(),
tx.GetWitnessHash().ToString(),
pfrom.GetId(), pfrom.GetId(),
state.ToString()); state.ToString());
MaybePunishNodeForTx(pfrom.GetId(), state); MaybePunishNodeForTx(pfrom.GetId(), state);

@ -21,6 +21,7 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
LOCK(m_mutex); LOCK(m_mutex);
const uint256& hash = tx->GetHash(); const uint256& hash = tx->GetHash();
const uint256& wtxid = tx->GetWitnessHash();
if (m_orphans.count(hash)) if (m_orphans.count(hash))
return false; return false;
@ -34,7 +35,7 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
unsigned int sz = GetTransactionWeight(*tx); unsigned int sz = GetTransactionWeight(*tx);
if (sz > MAX_STANDARD_TX_WEIGHT) if (sz > MAX_STANDARD_TX_WEIGHT)
{ {
LogPrint(BCLog::MEMPOOL, "ignoring large orphan tx (size: %u, hash: %s)\n", sz, hash.ToString()); LogPrint(BCLog::MEMPOOL, "ignoring large orphan tx (size: %u, txid: %s, wtxid: %s)\n", sz, hash.ToString(), wtxid.ToString());
return false; return false;
} }
@ -47,7 +48,7 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
m_outpoint_to_orphan_it[txin.prevout].insert(ret.first); m_outpoint_to_orphan_it[txin.prevout].insert(ret.first);
} }
LogPrint(BCLog::MEMPOOL, "stored orphan tx %s (mapsz %u outsz %u)\n", hash.ToString(), LogPrint(BCLog::MEMPOOL, "stored orphan tx %s (wtxid=%s) (mapsz %u outsz %u)\n", hash.ToString(), wtxid.ToString(),
m_orphans.size(), m_outpoint_to_orphan_it.size()); m_orphans.size(), m_outpoint_to_orphan_it.size());
return true; return true;
} }

@ -1079,9 +1079,11 @@ bool MemPoolAccept::Finalize(const ATMPArgs& args, Workspace& ws)
// Remove conflicting transactions from the mempool // Remove conflicting transactions from the mempool
for (CTxMemPool::txiter it : ws.m_all_conflicting) for (CTxMemPool::txiter it : ws.m_all_conflicting)
{ {
LogPrint(BCLog::MEMPOOL, "replacing tx %s with %s for %s additional fees, %d delta bytes\n", LogPrint(BCLog::MEMPOOL, "replacing tx %s (wtxid=%s) with %s (wtxid=%s) for %s additional fees, %d delta bytes\n",
it->GetTx().GetHash().ToString(), it->GetTx().GetHash().ToString(),
it->GetTx().GetWitnessHash().ToString(),
hash.ToString(), hash.ToString(),
tx.GetWitnessHash().ToString(),
FormatMoney(ws.m_modified_fees - ws.m_conflicting_fees), FormatMoney(ws.m_modified_fees - ws.m_conflicting_fees),
(int)entry->GetTxSize() - (int)ws.m_conflicting_size); (int)entry->GetTxSize() - (int)ws.m_conflicting_size);
TRACE7(mempool, replaced, TRACE7(mempool, replaced,

@ -106,7 +106,7 @@ class P2PPermissionsTests(BitcoinTestFramework):
self.log.debug("Check that node[1] will send the tx to node[0] even though it is already in the mempool") self.log.debug("Check that node[1] will send the tx to node[0] even though it is already in the mempool")
self.connect_nodes(1, 0) self.connect_nodes(1, 0)
with self.nodes[1].assert_debug_log(["Force relaying tx {} from peer=0".format(txid)]): with self.nodes[1].assert_debug_log(["Force relaying tx {} (wtxid={}) from peer=0".format(txid, tx.getwtxid())]):
p2p_rebroadcast_wallet.send_txs_and_test([tx], self.nodes[1]) p2p_rebroadcast_wallet.send_txs_and_test([tx], self.nodes[1])
self.wait_until(lambda: txid in self.nodes[0].getrawmempool()) self.wait_until(lambda: txid in self.nodes[0].getrawmempool())
@ -119,14 +119,14 @@ class P2PPermissionsTests(BitcoinTestFramework):
[tx], [tx],
self.nodes[1], self.nodes[1],
success=False, success=False,
reject_reason='{} from peer=0 was not accepted: txn-mempool-conflict'.format(txid) reject_reason='{} (wtxid={}) from peer=0 was not accepted: txn-mempool-conflict'.format(txid, tx.getwtxid())
) )
p2p_rebroadcast_wallet.send_txs_and_test( p2p_rebroadcast_wallet.send_txs_and_test(
[tx], [tx],
self.nodes[1], self.nodes[1],
success=False, success=False,
reject_reason='Not relaying non-mempool transaction {} from forcerelay peer=0'.format(txid) reject_reason='Not relaying non-mempool transaction {} (wtxid={}) from forcerelay peer=0'.format(txid, tx.getwtxid())
) )
def checkpermission(self, args, expectedPermissions): def checkpermission(self, args, expectedPermissions):

Loading…
Cancel
Save