[prep/refactor] move txorphanage to node namespace and directory
This is move-only.
This commit is contained in:
1 parent
bb91d23fa9
commit
08e58fa911
11 files changed
+30
-28
No files matched your search
+1
-1
@@ -277,6 +277,7 @@ add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
|
|||||||
node/timeoffsets.cpp
|
node/timeoffsets.cpp
|
||||||
node/transaction.cpp
|
node/transaction.cpp
|
||||||
node/txdownloadman_impl.cpp
|
node/txdownloadman_impl.cpp
|
||||||
|
node/txorphanage.cpp
|
||||||
node/txreconciliation.cpp
|
node/txreconciliation.cpp
|
||||||
node/utxo_snapshot.cpp
|
node/utxo_snapshot.cpp
|
||||||
node/warnings.cpp
|
node/warnings.cpp
|
||||||
@@ -308,7 +309,6 @@ add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
|
|||||||
txdb.cpp
|
txdb.cpp
|
||||||
txgraph.cpp
|
txgraph.cpp
|
||||||
txmempool.cpp
|
txmempool.cpp
|
||||||
txorphanage.cpp
|
|
||||||
txrequest.cpp
|
txrequest.cpp
|
||||||
validation.cpp
|
validation.cpp
|
||||||
validationinterface.cpp
|
validationinterface.cpp
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
#include <node/protocol_version.h>
|
#include <node/protocol_version.h>
|
||||||
#include <node/timeoffsets.h>
|
#include <node/timeoffsets.h>
|
||||||
#include <node/txdownloadman.h>
|
#include <node/txdownloadman.h>
|
||||||
|
#include <node/txorphanage.h>
|
||||||
#include <node/txreconciliation.h>
|
#include <node/txreconciliation.h>
|
||||||
#include <node/warnings.h>
|
#include <node/warnings.h>
|
||||||
#include <policy/feerate.h>
|
#include <policy/feerate.h>
|
||||||
@@ -53,7 +54,6 @@
|
|||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
#include <txorphanage.h>
|
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
#include <util/check.h>
|
#include <util/check.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
@@ -533,7 +533,7 @@ public:
|
|||||||
std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) override
|
std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) override
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||||
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const 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);
|
PeerManagerInfo GetInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||||
void SendPings() 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);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<TxOrphanage::OrphanTxBase> PeerManagerImpl::GetOrphanTransactions()
|
std::vector<node::TxOrphanage::OrphanTxBase> PeerManagerImpl::GetOrphanTransactions()
|
||||||
{
|
{
|
||||||
LOCK(m_tx_download_mutex);
|
LOCK(m_tx_download_mutex);
|
||||||
return m_txdownloadman.GetOrphanTransactions();
|
return m_txdownloadman.GetOrphanTransactions();
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
#include <consensus/amount.h>
|
#include <consensus/amount.h>
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
|
#include <node/txorphanage.h>
|
||||||
#include <protocol.h>
|
#include <protocol.h>
|
||||||
#include <threadsafety.h>
|
#include <threadsafety.h>
|
||||||
#include <txorphanage.h>
|
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
@@ -113,7 +113,7 @@ public:
|
|||||||
/** Get statistics from node state */
|
/** Get statistics from node state */
|
||||||
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0;
|
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. */
|
/** Get peer manager info. */
|
||||||
virtual PeerManagerInfo GetInfo() const = 0;
|
virtual PeerManagerInfo GetInfo() const = 0;
|
||||||
|
|||||||
@@ -6,9 +6,8 @@
|
|||||||
#define BITCOIN_NODE_TXDOWNLOADMAN_H
|
#define BITCOIN_NODE_TXDOWNLOADMAN_H
|
||||||
|
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
|
#include <node/txorphanage.h>
|
||||||
#include <policy/packages.h>
|
#include <policy/packages.h>
|
||||||
#include <txorphanage.h>
|
|
||||||
#include <util/transaction_identifier.h>
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|||||||
@@ -10,9 +10,9 @@
|
|||||||
#include <consensus/validation.h>
|
#include <consensus/validation.h>
|
||||||
#include <kernel/chain.h>
|
#include <kernel/chain.h>
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
|
#include <node/txorphanage.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
#include <policy/packages.h>
|
#include <policy/packages.h>
|
||||||
#include <txorphanage.h>
|
|
||||||
#include <txrequest.h>
|
#include <txrequest.h>
|
||||||
|
|
||||||
class CTxMemPool;
|
class CTxMemPool;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include <txorphanage.h>
|
#include <node/txorphanage.h>
|
||||||
|
|
||||||
#include <consensus/validation.h>
|
#include <consensus/validation.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
namespace node{
|
||||||
bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
|
bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
|
||||||
{
|
{
|
||||||
const Txid& hash = tx->GetHash();
|
const Txid& hash = tx->GetHash();
|
||||||
@@ -361,3 +362,4 @@ void TxOrphanage::SanityCheck() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} // namespace node
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#ifndef BITCOIN_TXORPHANAGE_H
|
#ifndef BITCOIN_NODE_TXORPHANAGE_H
|
||||||
#define BITCOIN_TXORPHANAGE_H
|
#define BITCOIN_NODE_TXORPHANAGE_H
|
||||||
|
|
||||||
#include <consensus/validation.h>
|
#include <consensus/validation.h>
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
namespace node{
|
||||||
/** Expiration time for orphan transactions */
|
/** Expiration time for orphan transactions */
|
||||||
static constexpr auto ORPHAN_TX_EXPIRE_TIME{20min};
|
static constexpr auto ORPHAN_TX_EXPIRE_TIME{20min};
|
||||||
/** Minimum time between orphan transactions expire time checks */
|
/** Minimum time between orphan transactions expire time checks */
|
||||||
@@ -162,5 +163,5 @@ protected:
|
|||||||
/** Timestamp for the next scheduled sweep of expired orphans */
|
/** Timestamp for the next scheduled sweep of expired orphans */
|
||||||
NodeSeconds m_next_sweep{0s};
|
NodeSeconds m_next_sweep{0s};
|
||||||
};
|
};
|
||||||
|
} // namespace node
|
||||||
#endif // BITCOIN_TXORPHANAGE_H
|
#endif // BITCOIN_NODE_TXORPHANAGE_H
|
||||||
+3
-3
@@ -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);
|
UniValue o(UniValue::VOBJ);
|
||||||
o.pushKV("txid", orphan.tx->GetHash().ToString());
|
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("bytes", orphan.tx->GetTotalSize());
|
||||||
o.pushKV("vsize", GetVirtualTransactionSize(*orphan.tx));
|
o.pushKV("vsize", GetVirtualTransactionSize(*orphan.tx));
|
||||||
o.pushKV("weight", GetTransactionWeight(*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)});
|
o.pushKV("expiration", int64_t{TicksSinceEpoch<std::chrono::seconds>(orphan.nTimeExpire)});
|
||||||
UniValue from(UniValue::VARR);
|
UniValue from(UniValue::VARR);
|
||||||
for (const auto fromPeer: orphan.announcers) {
|
for (const auto fromPeer: orphan.announcers) {
|
||||||
@@ -899,7 +899,7 @@ static RPCHelpMan getorphantxs()
|
|||||||
{
|
{
|
||||||
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||||
PeerManager& peerman = EnsurePeerman(node);
|
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)};
|
int verbosity{ParseVerbosity(request.params[0], /*default_verbosity=*/0, /*allow_bool*/false)};
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
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
|
// Orphanage usage should never exceed what is allowed
|
||||||
Assert(orphanage.Size() <= max_orphan_count);
|
Assert(orphanage.Size() <= max_orphan_count);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <consensus/validation.h>
|
#include <consensus/validation.h>
|
||||||
#include <net_processing.h>
|
#include <net_processing.h>
|
||||||
#include <node/eviction.h>
|
#include <node/eviction.h>
|
||||||
|
#include <node/txorphanage.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
@@ -14,7 +15,6 @@
|
|||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
#include <test/fuzz/util.h>
|
#include <test/fuzz/util.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <txorphanage.h>
|
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
#include <util/check.h>
|
#include <util/check.h>
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
@@ -36,7 +36,7 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
|
|||||||
FastRandomContext orphanage_rng{/*fDeterministic=*/true};
|
FastRandomContext orphanage_rng{/*fDeterministic=*/true};
|
||||||
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
||||||
|
|
||||||
TxOrphanage orphanage;
|
node::TxOrphanage orphanage;
|
||||||
std::vector<COutPoint> outpoints; // Duplicates are tolerated
|
std::vector<COutPoint> outpoints; // Duplicates are tolerated
|
||||||
outpoints.reserve(200'000);
|
outpoints.reserve(200'000);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <arith_uint256.h>
|
#include <arith_uint256.h>
|
||||||
#include <consensus/validation.h>
|
#include <consensus/validation.h>
|
||||||
|
#include <node/txorphanage.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
#include <pubkey.h>
|
#include <pubkey.h>
|
||||||
@@ -12,7 +13,6 @@
|
|||||||
#include <test/util/random.h>
|
#include <test/util/random.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <test/util/transaction_utils.h>
|
#include <test/util/transaction_utils.h>
|
||||||
#include <txorphanage.h>
|
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
BOOST_FIXTURE_TEST_SUITE(orphanage_tests, TestingSetup)
|
BOOST_FIXTURE_TEST_SUITE(orphanage_tests, TestingSetup)
|
||||||
|
|
||||||
class TxOrphanageTest : public TxOrphanage
|
class TxOrphanageTest : public node::TxOrphanage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TxOrphanageTest(FastRandomContext& rng) : m_rng{rng} {}
|
TxOrphanageTest(FastRandomContext& rng) : m_rng{rng} {}
|
||||||
@@ -209,12 +209,12 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
|
|||||||
BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 1);
|
BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 1);
|
||||||
|
|
||||||
// One second shy of expiration
|
// One second shy of expiration
|
||||||
SetMockTime(now + ORPHAN_TX_EXPIRE_TIME - 1s);
|
SetMockTime(now + node::ORPHAN_TX_EXPIRE_TIME - 1s);
|
||||||
orphanage.LimitOrphans(1, rng);
|
orphanage.LimitOrphans(1, rng);
|
||||||
BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 1);
|
BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 1);
|
||||||
|
|
||||||
// Jump one more second, orphan should be timed out on limiting
|
// 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);
|
BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 1);
|
||||||
orphanage.LimitOrphans(1, rng);
|
orphanage.LimitOrphans(1, rng);
|
||||||
BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 0);
|
BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 0);
|
||||||
@@ -223,7 +223,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
|
|||||||
BOOST_AUTO_TEST_CASE(same_txid_diff_witness)
|
BOOST_AUTO_TEST_CASE(same_txid_diff_witness)
|
||||||
{
|
{
|
||||||
FastRandomContext det_rand{true};
|
FastRandomContext det_rand{true};
|
||||||
TxOrphanage orphanage;
|
node::TxOrphanage orphanage;
|
||||||
NodeId peer{0};
|
NodeId peer{0};
|
||||||
|
|
||||||
std::vector<COutPoint> empty_outpoints;
|
std::vector<COutPoint> empty_outpoints;
|
||||||
@@ -291,7 +291,7 @@ BOOST_AUTO_TEST_CASE(get_children)
|
|||||||
|
|
||||||
// All orphans provided by node1
|
// All orphans provided by node1
|
||||||
{
|
{
|
||||||
TxOrphanage orphanage;
|
node::TxOrphanage orphanage;
|
||||||
BOOST_CHECK(orphanage.AddTx(child_p1n0, node1));
|
BOOST_CHECK(orphanage.AddTx(child_p1n0, node1));
|
||||||
BOOST_CHECK(orphanage.AddTx(child_p2n1, node1));
|
BOOST_CHECK(orphanage.AddTx(child_p2n1, node1));
|
||||||
BOOST_CHECK(orphanage.AddTx(child_p1n0_p1n1, 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
|
// Orphans provided by node1 and node2
|
||||||
{
|
{
|
||||||
TxOrphanage orphanage;
|
node::TxOrphanage orphanage;
|
||||||
BOOST_CHECK(orphanage.AddTx(child_p1n0, node1));
|
BOOST_CHECK(orphanage.AddTx(child_p1n0, node1));
|
||||||
BOOST_CHECK(orphanage.AddTx(child_p2n1, node1));
|
BOOST_CHECK(orphanage.AddTx(child_p2n1, node1));
|
||||||
BOOST_CHECK(orphanage.AddTx(child_p1n0_p1n1, node2));
|
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)
|
BOOST_AUTO_TEST_CASE(too_large_orphan_tx)
|
||||||
{
|
{
|
||||||
TxOrphanage orphanage;
|
node::TxOrphanage orphanage;
|
||||||
CMutableTransaction tx;
|
CMutableTransaction tx;
|
||||||
tx.vin.resize(1);
|
tx.vin.resize(1);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user