[prep/refactor] move txorphanage to node namespace and directory

This is move-only.
This commit is contained in:
glozow
2025-05-15 10:09:10 -04:00
parent bb91d23fa9
commit 08e58fa911
11 changed files with 30 additions and 28 deletions

View File

@@ -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

View File

@@ -35,6 +35,7 @@
#include <node/protocol_version.h>
#include <node/timeoffsets.h>
#include <node/txdownloadman.h>
#include <node/txorphanage.h>
#include <node/txreconciliation.h>
#include <node/warnings.h>
#include <policy/feerate.h>
@@ -53,7 +54,6 @@
#include <sync.h>
#include <tinyformat.h>
#include <txmempool.h>
#include <txorphanage.h>
#include <uint256.h>
#include <util/check.h>
#include <util/strencodings.h>
@@ -533,7 +533,7 @@ public:
std::optional<std::string> 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<TxOrphanage::OrphanTxBase> GetOrphanTransactions() override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex);
std::vector<node::TxOrphanage::OrphanTxBase> 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<TxOrphanage::OrphanTxBase> PeerManagerImpl::GetOrphanTransactions()
std::vector<node::TxOrphanage::OrphanTxBase> PeerManagerImpl::GetOrphanTransactions()
{
LOCK(m_tx_download_mutex);
return m_txdownloadman.GetOrphanTransactions();

View File

@@ -8,9 +8,9 @@
#include <consensus/amount.h>
#include <net.h>
#include <node/txorphanage.h>
#include <protocol.h>
#include <threadsafety.h>
#include <txorphanage.h>
#include <validationinterface.h>
#include <atomic>
@@ -113,7 +113,7 @@ public:
/** Get statistics from node state */
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0;
virtual std::vector<TxOrphanage::OrphanTxBase> GetOrphanTransactions() = 0;
virtual std::vector<node::TxOrphanage::OrphanTxBase> GetOrphanTransactions() = 0;
/** Get peer manager info. */
virtual PeerManagerInfo GetInfo() const = 0;

View File

@@ -6,9 +6,8 @@
#define BITCOIN_NODE_TXDOWNLOADMAN_H
#include <net.h>
#include <node/txorphanage.h>
#include <policy/packages.h>
#include <txorphanage.h>
#include <util/transaction_identifier.h>
#include <cstdint>
#include <memory>

View File

@@ -10,9 +10,9 @@
#include <consensus/validation.h>
#include <kernel/chain.h>
#include <net.h>
#include <node/txorphanage.h>
#include <primitives/transaction.h>
#include <policy/packages.h>
#include <txorphanage.h>
#include <txrequest.h>
class CTxMemPool;

View File

@@ -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 <txorphanage.h>
#include <node/txorphanage.h>
#include <consensus/validation.h>
#include <logging.h>
@@ -12,6 +12,7 @@
#include <cassert>
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

View File

@@ -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 <consensus/validation.h>
#include <net.h>
@@ -15,6 +15,7 @@
#include <map>
#include <set>
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

View File

@@ -841,7 +841,7 @@ static std::vector<RPCResult> 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<std::chrono::seconds>(orphan.nTimeExpire - ORPHAN_TX_EXPIRE_TIME)});
o.pushKV("entry", int64_t{TicksSinceEpoch<std::chrono::seconds>(orphan.nTimeExpire - node::ORPHAN_TX_EXPIRE_TIME)});
o.pushKV("expiration", int64_t{TicksSinceEpoch<std::chrono::seconds>(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<TxOrphanage::OrphanTxBase> orphanage = peerman.GetOrphanTransactions();
std::vector<node::TxOrphanage::OrphanTxBase> orphanage = peerman.GetOrphanTransactions();
int verbosity{ParseVerbosity(request.params[0], /*default_verbosity=*/0, /*allow_bool*/false)};

View File

@@ -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);

View File

@@ -6,6 +6,7 @@
#include <consensus/validation.h>
#include <net_processing.h>
#include <node/eviction.h>
#include <node/txorphanage.h>
#include <policy/policy.h>
#include <primitives/transaction.h>
#include <script/script.h>
@@ -14,7 +15,6 @@
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <test/util/setup_common.h>
#include <txorphanage.h>
#include <uint256.h>
#include <util/check.h>
#include <util/time.h>
@@ -36,7 +36,7 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
FastRandomContext orphanage_rng{/*fDeterministic=*/true};
SetMockTime(ConsumeTime(fuzzed_data_provider));
TxOrphanage orphanage;
node::TxOrphanage orphanage;
std::vector<COutPoint> outpoints; // Duplicates are tolerated
outpoints.reserve(200'000);

View File

@@ -4,6 +4,7 @@
#include <arith_uint256.h>
#include <consensus/validation.h>
#include <node/txorphanage.h>
#include <policy/policy.h>
#include <primitives/transaction.h>
#include <pubkey.h>
@@ -12,7 +13,6 @@
#include <test/util/random.h>
#include <test/util/setup_common.h>
#include <test/util/transaction_utils.h>
#include <txorphanage.h>
#include <array>
#include <cstdint>
@@ -21,7 +21,7 @@
BOOST_FIXTURE_TEST_SUITE(orphanage_tests, TestingSetup)
class TxOrphanageTest : public TxOrphanage
class TxOrphanageTest : public node::TxOrphanage
{
public:
TxOrphanageTest(FastRandomContext& rng) : m_rng{rng} {}
@@ -209,12 +209,12 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 1);
// One second shy of expiration
SetMockTime(now + ORPHAN_TX_EXPIRE_TIME - 1s);
SetMockTime(now + node::ORPHAN_TX_EXPIRE_TIME - 1s);
orphanage.LimitOrphans(1, rng);
BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 1);
// Jump one more second, orphan should be timed out on limiting
SetMockTime(now + ORPHAN_TX_EXPIRE_TIME);
SetMockTime(now + node::ORPHAN_TX_EXPIRE_TIME);
BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 1);
orphanage.LimitOrphans(1, rng);
BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 0);
@@ -223,7 +223,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
BOOST_AUTO_TEST_CASE(same_txid_diff_witness)
{
FastRandomContext det_rand{true};
TxOrphanage orphanage;
node::TxOrphanage orphanage;
NodeId peer{0};
std::vector<COutPoint> empty_outpoints;
@@ -291,7 +291,7 @@ BOOST_AUTO_TEST_CASE(get_children)
// All orphans provided by node1
{
TxOrphanage orphanage;
node::TxOrphanage orphanage;
BOOST_CHECK(orphanage.AddTx(child_p1n0, node1));
BOOST_CHECK(orphanage.AddTx(child_p2n1, node1));
BOOST_CHECK(orphanage.AddTx(child_p1n0_p1n1, node1));
@@ -314,7 +314,7 @@ BOOST_AUTO_TEST_CASE(get_children)
// Orphans provided by node1 and node2
{
TxOrphanage orphanage;
node::TxOrphanage orphanage;
BOOST_CHECK(orphanage.AddTx(child_p1n0, node1));
BOOST_CHECK(orphanage.AddTx(child_p2n1, node1));
BOOST_CHECK(orphanage.AddTx(child_p1n0_p1n1, node2));
@@ -359,7 +359,7 @@ BOOST_AUTO_TEST_CASE(get_children)
BOOST_AUTO_TEST_CASE(too_large_orphan_tx)
{
TxOrphanage orphanage;
node::TxOrphanage orphanage;
CMutableTransaction tx;
tx.vin.resize(1);