From 08e58fa91198afda6f894c20026b64f239938e03 Mon Sep 17 00:00:00 2001 From: glozow Date: Thu, 15 May 2025 10:09:10 -0400 Subject: [PATCH] [prep/refactor] move txorphanage to node namespace and directory This is move-only. --- src/CMakeLists.txt | 2 +- src/net_processing.cpp | 6 +++--- src/net_processing.h | 4 ++-- src/node/txdownloadman.h | 3 +-- src/node/txdownloadman_impl.h | 2 +- src/{ => node}/txorphanage.cpp | 4 +++- src/{ => node}/txorphanage.h | 9 +++++---- src/rpc/mempool.cpp | 6 +++--- src/test/fuzz/txdownloadman.cpp | 2 +- src/test/fuzz/txorphan.cpp | 4 ++-- src/test/orphanage_tests.cpp | 16 ++++++++-------- 11 files changed, 30 insertions(+), 28 deletions(-) rename src/{ => node}/txorphanage.cpp (99%) rename src/{ => node}/txorphanage.h (97%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 96a6790e612..8be486579c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -277,6 +277,7 @@ add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL node/timeoffsets.cpp node/transaction.cpp node/txdownloadman_impl.cpp + node/txorphanage.cpp node/txreconciliation.cpp node/utxo_snapshot.cpp node/warnings.cpp @@ -308,7 +309,6 @@ add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL txdb.cpp txgraph.cpp txmempool.cpp - txorphanage.cpp txrequest.cpp validation.cpp validationinterface.cpp diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 5e0651aa3a3..7186f2aa1e9 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -53,7 +54,6 @@ #include #include #include -#include #include #include #include @@ -533,7 +533,7 @@ public: std::optional FetchBlock(NodeId peer_id, const CBlockIndex& block_index) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); - std::vector GetOrphanTransactions() override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex); + std::vector GetOrphanTransactions() override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex); PeerManagerInfo GetInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void RelayTransaction(const Txid& txid, const Wtxid& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); @@ -1754,7 +1754,7 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c return true; } -std::vector PeerManagerImpl::GetOrphanTransactions() +std::vector PeerManagerImpl::GetOrphanTransactions() { LOCK(m_tx_download_mutex); return m_txdownloadman.GetOrphanTransactions(); diff --git a/src/net_processing.h b/src/net_processing.h index 147ab681bed..d99674607ff 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -8,9 +8,9 @@ #include #include +#include #include #include -#include #include #include @@ -113,7 +113,7 @@ public: /** Get statistics from node state */ virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0; - virtual std::vector GetOrphanTransactions() = 0; + virtual std::vector GetOrphanTransactions() = 0; /** Get peer manager info. */ virtual PeerManagerInfo GetInfo() const = 0; diff --git a/src/node/txdownloadman.h b/src/node/txdownloadman.h index 9eb246740b9..0b9d828616f 100644 --- a/src/node/txdownloadman.h +++ b/src/node/txdownloadman.h @@ -6,9 +6,8 @@ #define BITCOIN_NODE_TXDOWNLOADMAN_H #include +#include #include -#include -#include #include #include diff --git a/src/node/txdownloadman_impl.h b/src/node/txdownloadman_impl.h index 3e0213352ca..245e251c3f3 100644 --- a/src/node/txdownloadman_impl.h +++ b/src/node/txdownloadman_impl.h @@ -10,9 +10,9 @@ #include #include #include +#include #include #include -#include #include class CTxMemPool; diff --git a/src/txorphanage.cpp b/src/node/txorphanage.cpp similarity index 99% rename from src/txorphanage.cpp rename to src/node/txorphanage.cpp index 0d359610adc..6ffd17ce637 100644 --- a/src/txorphanage.cpp +++ b/src/node/txorphanage.cpp @@ -2,7 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include #include #include @@ -12,6 +12,7 @@ #include +namespace node{ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer) { const Txid& hash = tx->GetHash(); @@ -361,3 +362,4 @@ void TxOrphanage::SanityCheck() const } } } +} // namespace node diff --git a/src/txorphanage.h b/src/node/txorphanage.h similarity index 97% rename from src/txorphanage.h rename to src/node/txorphanage.h index 5676c92efc7..502d19106d0 100644 --- a/src/txorphanage.h +++ b/src/node/txorphanage.h @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_TXORPHANAGE_H -#define BITCOIN_TXORPHANAGE_H +#ifndef BITCOIN_NODE_TXORPHANAGE_H +#define BITCOIN_NODE_TXORPHANAGE_H #include #include @@ -15,6 +15,7 @@ #include #include +namespace node{ /** Expiration time for orphan transactions */ static constexpr auto ORPHAN_TX_EXPIRE_TIME{20min}; /** Minimum time between orphan transactions expire time checks */ @@ -162,5 +163,5 @@ protected: /** Timestamp for the next scheduled sweep of expired orphans */ NodeSeconds m_next_sweep{0s}; }; - -#endif // BITCOIN_TXORPHANAGE_H +} // namespace node +#endif // BITCOIN_NODE_TXORPHANAGE_H diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp index 7b5597916c7..820c6a6a737 100644 --- a/src/rpc/mempool.cpp +++ b/src/rpc/mempool.cpp @@ -841,7 +841,7 @@ static std::vector OrphanDescription() }; } -static UniValue OrphanToJSON(const TxOrphanage::OrphanTxBase& orphan) +static UniValue OrphanToJSON(const node::TxOrphanage::OrphanTxBase& orphan) { UniValue o(UniValue::VOBJ); o.pushKV("txid", orphan.tx->GetHash().ToString()); @@ -849,7 +849,7 @@ static UniValue OrphanToJSON(const TxOrphanage::OrphanTxBase& orphan) o.pushKV("bytes", orphan.tx->GetTotalSize()); o.pushKV("vsize", GetVirtualTransactionSize(*orphan.tx)); o.pushKV("weight", GetTransactionWeight(*orphan.tx)); - o.pushKV("entry", int64_t{TicksSinceEpoch(orphan.nTimeExpire - ORPHAN_TX_EXPIRE_TIME)}); + o.pushKV("entry", int64_t{TicksSinceEpoch(orphan.nTimeExpire - node::ORPHAN_TX_EXPIRE_TIME)}); o.pushKV("expiration", int64_t{TicksSinceEpoch(orphan.nTimeExpire)}); UniValue from(UniValue::VARR); for (const auto fromPeer: orphan.announcers) { @@ -899,7 +899,7 @@ static RPCHelpMan getorphantxs() { const NodeContext& node = EnsureAnyNodeContext(request.context); PeerManager& peerman = EnsurePeerman(node); - std::vector orphanage = peerman.GetOrphanTransactions(); + std::vector orphanage = peerman.GetOrphanTransactions(); int verbosity{ParseVerbosity(request.params[0], /*default_verbosity=*/0, /*allow_bool*/false)}; diff --git a/src/test/fuzz/txdownloadman.cpp b/src/test/fuzz/txdownloadman.cpp index b65ba0eb383..c5d66e9fa0a 100644 --- a/src/test/fuzz/txdownloadman.cpp +++ b/src/test/fuzz/txdownloadman.cpp @@ -280,7 +280,7 @@ static bool HasRelayPermissions(NodeId peer) { return peer == 0; } static void CheckInvariants(const node::TxDownloadManagerImpl& txdownload_impl, size_t max_orphan_count) { - const TxOrphanage& orphanage = txdownload_impl.m_orphanage; + const node::TxOrphanage& orphanage = txdownload_impl.m_orphanage; // Orphanage usage should never exceed what is allowed Assert(orphanage.Size() <= max_orphan_count); diff --git a/src/test/fuzz/txorphan.cpp b/src/test/fuzz/txorphan.cpp index e9543f7ace1..4d552bf1160 100644 --- a/src/test/fuzz/txorphan.cpp +++ b/src/test/fuzz/txorphan.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include