From 3b8c17838a561616fd7c933753c7b98b6c6c7c99 Mon Sep 17 00:00:00 2001 From: glozow Date: Mon, 24 Jul 2023 16:09:50 +0100 Subject: [PATCH] [log] add more logs related to orphan handling - Whenever a tx is erased. Allows somebody to see which transactions have been erased due to expiry/overflow, not just how many. - Whenever a tx is added to a peer's workset. - AcceptToMemoryPool when a tx is accepted, mirroring the one logged for a tx received from a peer. This allows someone to see all of the transactions that are accepted to mempool just by looking for ATMP logs. - MEMPOOLREJ when a tx is rejected, mirroring the one logged for a tx received from a peer. This allows someone to see all of the transaction rejections by looking at MEMPOOLREJ logs. --- src/net_processing.cpp | 10 ++++++++++ src/txorphanage.cpp | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index a0946754a0..ec8230fd68 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2923,6 +2923,11 @@ bool PeerManagerImpl::ProcessOrphanTx(Peer& peer) if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) { LogPrint(BCLog::TXPACKAGES, " accepted orphan tx %s (wtxid=%s)\n", orphanHash.ToString(), orphan_wtxid.ToString()); + LogPrint(BCLog::MEMPOOL, "AcceptToMemoryPool: peer=%d: accepted %s (wtxid=%s) (poolsz %u txn, %u kB)\n", + peer.m_id, + orphanHash.ToString(), + orphan_wtxid.ToString(), + m_mempool.size(), m_mempool.DynamicMemoryUsage() / 1000); RelayTransaction(orphanHash, porphanTx->GetWitnessHash()); m_orphanage.AddChildrenToWorkSet(*porphanTx); m_orphanage.EraseTx(orphanHash); @@ -2937,6 +2942,11 @@ bool PeerManagerImpl::ProcessOrphanTx(Peer& peer) orphan_wtxid.ToString(), peer.m_id, state.ToString()); + LogPrint(BCLog::MEMPOOLREJ, "%s (wtxid=%s) from peer=%d was not accepted: %s\n", + orphanHash.ToString(), + orphan_wtxid.ToString(), + peer.m_id, + state.ToString()); // Maybe punish peer that gave us an invalid orphan tx MaybePunishNodeForTx(peer.m_id, state); } diff --git a/src/txorphanage.cpp b/src/txorphanage.cpp index 4fed6a60ed..7455d914e8 100644 --- a/src/txorphanage.cpp +++ b/src/txorphanage.cpp @@ -84,6 +84,8 @@ int TxOrphanage::EraseTxNoLock(const uint256& txid) m_orphan_list[old_pos] = it_last; it_last->second.list_pos = old_pos; } + const auto& wtxid = it->second.tx->GetWitnessHash(); + LogPrint(BCLog::TXPACKAGES, " removed orphan tx %s (wtxid=%s)\n", txid.ToString(), wtxid.ToString()); m_orphan_list.pop_back(); m_wtxid_to_orphan_it.erase(it->second.tx->GetWitnessHash()); @@ -160,6 +162,8 @@ void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx) std::set& orphan_work_set = m_peer_work_set.try_emplace(elem->second.fromPeer).first->second; // Add this tx to the work set orphan_work_set.insert(elem->first); + LogPrint(BCLog::TXPACKAGES, "added %s (wtxid=%s) to peer %d workset\n", + tx.GetHash().ToString(), tx.GetWitnessHash().ToString(), elem->second.fromPeer); } } }