diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 6b6594f7da1..34958d5e901 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2137,7 +2137,7 @@ PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman, m_banman(banman), m_chainman(chainman), m_mempool(pool), - m_txdownloadman(node::TxDownloadOptions{pool, m_rng, opts.deterministic_rng}), + m_txdownloadman{node::TxDownloadOptions{pool, opts.deterministic_rng}}, m_warnings{warnings}, m_opts{opts}, m_inbound_inv_bucket(/*rate=*/m_opts.tx_send_rate, /*mult=*/1.0), diff --git a/src/node/txdownloadman.h b/src/node/txdownloadman.h index e362110212e..ab6d9accbeb 100644 --- a/src/node/txdownloadman.h +++ b/src/node/txdownloadman.h @@ -39,8 +39,6 @@ inline constexpr auto GETDATA_TX_INTERVAL{60s}; struct TxDownloadOptions { /** Read-only reference to mempool. */ const CTxMemPool& m_mempool; - /** RNG provided by caller. */ - FastRandomContext& m_rng; /** Instantiate TxRequestTracker as deterministic (used for tests). */ bool m_deterministic_txrequest{false}; }; diff --git a/src/node/txdownloadman_impl.cpp b/src/node/txdownloadman_impl.cpp index 00d69fb11a5..fe3f7a882a3 100644 --- a/src/node/txdownloadman_impl.cpp +++ b/src/node/txdownloadman_impl.cpp @@ -101,7 +101,7 @@ void TxDownloadManagerImpl::BlockConnected(const std::shared_ptr& for (const auto& ptx : pblock->vtx) { // Reconsider potential child transactions. - m_orphanage->AddChildrenToWorkSet(*ptx, m_opts.m_rng); + m_orphanage->AddChildrenToWorkSet(*ptx, m_rng); RecentConfirmedTransactionsFilter().insert(ptx->GetHash().ToUint256()); if (ptx->HasWitness()) { @@ -146,7 +146,7 @@ bool TxDownloadManagerImpl::AlreadyHaveTx(const GenTxid& gtxid, bool include_rec if (RecentConfirmedTransactionsFilter().contains(hash)) return true; - return RecentRejectsFilter().contains(hash) || std::visit([&](const auto& id) { return m_opts.m_mempool.exists(id); }, gtxid); + return RecentRejectsFilter().contains(hash) || std::visit([&](const auto& id) { return m_mempool.exists(id); }, gtxid); } void TxDownloadManagerImpl::ConnectedPeer(NodeId nodeid, const TxDownloadConnectionInfo& info) @@ -330,7 +330,7 @@ void TxDownloadManagerImpl::MempoolAcceptedTx(const CTransactionRef& tx) m_txrequest.ForgetTxHash(tx->GetHash().ToUint256()); m_txrequest.ForgetTxHash(tx->GetWitnessHash().ToUint256()); - m_orphanage->AddChildrenToWorkSet(*tx, m_opts.m_rng); + m_orphanage->AddChildrenToWorkSet(*tx, m_rng); // If it came from the orphanage, remove it. No-op if the tx is not in txorphanage. m_orphanage->EraseTx(tx->GetWitnessHash()); } @@ -380,7 +380,7 @@ node::RejectedTxTodo TxDownloadManagerImpl::MempoolRejectedTx(const CTransaction fRejectedParents = true; break; } else if (RecentRejectsReconsiderableFilter().contains(parent_txid.ToUint256()) && - !m_opts.m_mempool.exists(parent_txid)) { + !m_mempool.exists(parent_txid)) { // More than 1 parent in m_lazy_recent_rejects_reconsiderable: 1p1c will not be // sufficient to accept this package, so just give up here. if (rejected_parent_reconsiderable.has_value()) { diff --git a/src/node/txdownloadman_impl.h b/src/node/txdownloadman_impl.h index 8af0cb227f5..f49de20960a 100644 --- a/src/node/txdownloadman_impl.h +++ b/src/node/txdownloadman_impl.h @@ -13,13 +13,15 @@ #include #include #include +#include #include class CTxMemPool; namespace node { class TxDownloadManagerImpl { public: - TxDownloadOptions m_opts; + const CTxMemPool& m_mempool; + FastRandomContext m_rng; /** Manages unvalidated tx data (orphan transactions for which we are downloading ancestors). */ std::unique_ptr m_orphanage; @@ -128,7 +130,12 @@ public: return *m_lazy_recent_confirmed_transactions; } - TxDownloadManagerImpl(const TxDownloadOptions& options) : m_opts{options}, m_orphanage{MakeTxOrphanage()}, m_txrequest{options.m_deterministic_txrequest} {} + TxDownloadManagerImpl(const TxDownloadOptions& options) + : m_mempool{options.m_mempool}, + m_rng{options.m_deterministic_txrequest}, + m_orphanage{MakeTxOrphanage()}, + m_txrequest{options.m_deterministic_txrequest} + {} struct PeerInfo { /** Information relevant to scheduling tx requests. */ diff --git a/src/test/fuzz/txdownloadman.cpp b/src/test/fuzz/txdownloadman.cpp index c7a41da9485..8de5664b69a 100644 --- a/src/test/fuzz/txdownloadman.cpp +++ b/src/test/fuzz/txdownloadman.cpp @@ -174,8 +174,7 @@ FUZZ_TARGET(txdownloadman, .init = initialize) // Initialize txdownloadman bilingual_str error; CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node), error}; - FastRandomContext det_rand{true}; - node::TxDownloadManager txdownloadman{node::TxDownloadOptions{pool, det_rand, true}}; + node::TxDownloadManager txdownloadman{node::TxDownloadOptions{.m_mempool = pool, .m_deterministic_txrequest = true}}; std::chrono::microseconds time{244466666}; @@ -298,8 +297,7 @@ FUZZ_TARGET(txdownloadman_impl, .init = initialize) // Initialize a TxDownloadManagerImpl bilingual_str error; CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node), error}; - FastRandomContext det_rand{true}; - node::TxDownloadManagerImpl txdownload_impl{node::TxDownloadOptions{pool, det_rand, true}}; + node::TxDownloadManagerImpl txdownload_impl{node::TxDownloadOptions{.m_mempool = pool, .m_deterministic_txrequest = true}}; std::chrono::microseconds time{244466666}; diff --git a/src/test/txdownload_tests.cpp b/src/test/txdownload_tests.cpp index 296daf5fcfd..00d824f50c8 100644 --- a/src/test/txdownload_tests.cpp +++ b/src/test/txdownload_tests.cpp @@ -114,8 +114,7 @@ static CTransactionRef CreatePlaceholderTx(bool segwit) BOOST_FIXTURE_TEST_CASE(tx_rejection_types, TestChain100Setup) { CTxMemPool& pool = *Assert(m_node.mempool); - FastRandomContext det_rand{true}; - node::TxDownloadOptions DEFAULT_OPTS{pool, det_rand, true}; + node::TxDownloadOptions DEFAULT_OPTS{.m_mempool = pool, .m_deterministic_txrequest = true}; // A new TxDownloadManagerImpl is created for each tx so we can just reuse the same one. TxValidationState state; @@ -172,8 +171,7 @@ BOOST_FIXTURE_TEST_CASE(tx_rejection_types, TestChain100Setup) BOOST_FIXTURE_TEST_CASE(handle_missing_inputs, TestChain100Setup) { CTxMemPool& pool = *Assert(m_node.mempool); - FastRandomContext det_rand{true}; - node::TxDownloadOptions DEFAULT_OPTS{pool, det_rand, true}; + node::TxDownloadOptions DEFAULT_OPTS{.m_mempool = pool, .m_deterministic_txrequest = true}; NodeId nodeid{1}; node::TxDownloadConnectionInfo DEFAULT_CONN{/*m_preferred=*/false, /*m_relay_permissions=*/false, /*m_wtxid_relay=*/true};