From 84e4ef843db3443278d6eb70ff89fa254fcc6631 Mon Sep 17 00:00:00 2001 From: glozow Date: Tue, 16 Apr 2024 17:04:00 +0100 Subject: [PATCH] [txdownload] add read-only reference to mempool This will become necessary in later commits that query mempool. We also introduce the TxDownloadOptions in this commit to make the later diff easier to review. --- src/net_processing.cpp | 1 + src/node/txdownloadman.h | 8 +++++++- src/node/txdownloadman_impl.cpp | 5 +++-- src/node/txdownloadman_impl.h | 5 ++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 665f6438b80..fb903d061cc 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2000,6 +2000,7 @@ PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman, m_banman(banman), m_chainman(chainman), m_mempool(pool), + m_txdownloadman(node::TxDownloadOptions{pool}), m_warnings{warnings}, m_opts{opts} { diff --git a/src/node/txdownloadman.h b/src/node/txdownloadman.h index 3e010cda643..b305b91616b 100644 --- a/src/node/txdownloadman.h +++ b/src/node/txdownloadman.h @@ -10,11 +10,17 @@ class CBlock; class CRollingBloomFilter; +class CTxMemPool; class TxOrphanage; class TxRequestTracker; namespace node { class TxDownloadManagerImpl; +struct TxDownloadOptions { + /** Read-only reference to mempool. */ + const CTxMemPool& m_mempool; +}; + /** * Class responsible for deciding what transactions to request and, once * downloaded, whether and how to validate them. It is also responsible for @@ -38,7 +44,7 @@ class TxDownloadManager { const std::unique_ptr m_impl; public: - explicit TxDownloadManager(); + explicit TxDownloadManager(const TxDownloadOptions& options); ~TxDownloadManager(); // Get references to internal data structures. Outside access to these data structures should be diff --git a/src/node/txdownloadman_impl.cpp b/src/node/txdownloadman_impl.cpp index f0a1256c4fe..984e6cf04c8 100644 --- a/src/node/txdownloadman_impl.cpp +++ b/src/node/txdownloadman_impl.cpp @@ -7,13 +7,14 @@ #include #include +#include #include #include namespace node { // TxDownloadManager wrappers -TxDownloadManager::TxDownloadManager() : - m_impl{std::make_unique()} +TxDownloadManager::TxDownloadManager(const TxDownloadOptions& options) : + m_impl{std::make_unique(options)} {} TxDownloadManager::~TxDownloadManager() = default; diff --git a/src/node/txdownloadman_impl.h b/src/node/txdownloadman_impl.h index d55d218c917..df7824cdb46 100644 --- a/src/node/txdownloadman_impl.h +++ b/src/node/txdownloadman_impl.h @@ -12,9 +12,12 @@ #include #include +class CTxMemPool; namespace node { class TxDownloadManagerImpl { public: + TxDownloadOptions m_opts; + /** Manages unvalidated tx data (orphan transactions for which we are downloading ancestors). */ TxOrphanage m_orphanage; /** Tracks candidates for requesting and downloading transaction data. */ @@ -122,7 +125,7 @@ public: return *m_lazy_recent_confirmed_transactions; } - TxDownloadManagerImpl() = default; + TxDownloadManagerImpl(const TxDownloadOptions& options) : m_opts{options} {} void ActiveTipChange(); void BlockConnected(const std::shared_ptr& pblock);