From af918349de52e654927d50279de64f548a8b53d6 Mon Sep 17 00:00:00 2001 From: glozow Date: Tue, 16 Apr 2024 15:31:35 +0100 Subject: [PATCH] [refactor] move ValidationInterface functions to TxDownloadManager This is move-only. --- src/net_processing.cpp | 27 ++--------------- src/node/txdownloadman.h | 9 ++++-- src/node/txdownloadman_impl.cpp | 52 +++++++++++++++++++++++++++++++++ src/node/txdownloadman_impl.h | 5 ++++ 4 files changed, 67 insertions(+), 26 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 9554b080cc2..665f6438b80 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2036,8 +2036,7 @@ void PeerManagerImpl::ActiveTipChange(const CBlockIndex& new_tip, bool is_ibd) // If the chain tip has changed, previously rejected transactions might now be valid, e.g. due // to a timelock. Reset the rejection filters to give those transactions another chance if we // see them again. - RecentRejectsFilter().reset(); - RecentRejectsReconsiderableFilter().reset(); + m_txdownloadman.ActiveTipChange(); } } @@ -2072,33 +2071,13 @@ void PeerManagerImpl::BlockConnected( return; } LOCK(m_tx_download_mutex); - auto& m_orphanage = m_txdownloadman.GetOrphanageRef(); - auto& m_txrequest = m_txdownloadman.GetTxRequestRef(); - - m_orphanage.EraseForBlock(*pblock); - - for (const auto& ptx : pblock->vtx) { - RecentConfirmedTransactionsFilter().insert(ptx->GetHash().ToUint256()); - if (ptx->HasWitness()) { - RecentConfirmedTransactionsFilter().insert(ptx->GetWitnessHash().ToUint256()); - } - m_txrequest.ForgetTxHash(ptx->GetHash()); - m_txrequest.ForgetTxHash(ptx->GetWitnessHash()); - } + m_txdownloadman.BlockConnected(pblock); } void PeerManagerImpl::BlockDisconnected(const std::shared_ptr &block, const CBlockIndex* pindex) { - // To avoid relay problems with transactions that were previously - // confirmed, clear our filter of recently confirmed transactions whenever - // there's a reorg. - // This means that in a 1-block reorg (where 1 block is disconnected and - // then another block reconnected), our filter will drop to having only one - // block's worth of transactions in it, but that should be fine, since - // presumably the most common case of relaying a confirmed transaction - // should be just after a new block containing it is found. LOCK(m_tx_download_mutex); - RecentConfirmedTransactionsFilter().reset(); + m_txdownloadman.BlockDisconnected(); } /** diff --git a/src/node/txdownloadman.h b/src/node/txdownloadman.h index d9c1b7c134b..3e010cda643 100644 --- a/src/node/txdownloadman.h +++ b/src/node/txdownloadman.h @@ -8,10 +8,10 @@ #include #include +class CBlock; +class CRollingBloomFilter; class TxOrphanage; class TxRequestTracker; -class CRollingBloomFilter; - namespace node { class TxDownloadManagerImpl; @@ -48,6 +48,11 @@ public: CRollingBloomFilter& RecentRejectsFilter(); CRollingBloomFilter& RecentRejectsReconsiderableFilter(); CRollingBloomFilter& RecentConfirmedTransactionsFilter(); + + // Responses to chain events. TxDownloadManager is not an actual client of ValidationInterface, these are called through PeerManager. + void ActiveTipChange(); + void BlockConnected(const std::shared_ptr& pblock); + void BlockDisconnected(); }; } // namespace node #endif // BITCOIN_NODE_TXDOWNLOADMAN_H diff --git a/src/node/txdownloadman_impl.cpp b/src/node/txdownloadman_impl.cpp index 4c301221d19..f0a1256c4fe 100644 --- a/src/node/txdownloadman_impl.cpp +++ b/src/node/txdownloadman_impl.cpp @@ -5,7 +5,13 @@ #include #include +#include +#include +#include +#include + namespace node { +// TxDownloadManager wrappers TxDownloadManager::TxDownloadManager() : m_impl{std::make_unique()} {} @@ -31,4 +37,50 @@ CRollingBloomFilter& TxDownloadManager::RecentConfirmedTransactionsFilter() { return m_impl->RecentConfirmedTransactionsFilter(); } +void TxDownloadManager::ActiveTipChange() +{ + m_impl->ActiveTipChange(); +} +void TxDownloadManager::BlockConnected(const std::shared_ptr& pblock) +{ + m_impl->BlockConnected(pblock); +} +void TxDownloadManager::BlockDisconnected() +{ + m_impl->BlockDisconnected(); +} + +// TxDownloadManagerImpl +void TxDownloadManagerImpl::ActiveTipChange() +{ + RecentRejectsFilter().reset(); + RecentRejectsReconsiderableFilter().reset(); +} + +void TxDownloadManagerImpl::BlockConnected(const std::shared_ptr& pblock) +{ + m_orphanage.EraseForBlock(*pblock); + + for (const auto& ptx : pblock->vtx) { + RecentConfirmedTransactionsFilter().insert(ptx->GetHash().ToUint256()); + if (ptx->HasWitness()) { + RecentConfirmedTransactionsFilter().insert(ptx->GetWitnessHash().ToUint256()); + } + m_txrequest.ForgetTxHash(ptx->GetHash()); + m_txrequest.ForgetTxHash(ptx->GetWitnessHash()); + } +} + +void TxDownloadManagerImpl::BlockDisconnected() +{ + // To avoid relay problems with transactions that were previously + // confirmed, clear our filter of recently confirmed transactions whenever + // there's a reorg. + // This means that in a 1-block reorg (where 1 block is disconnected and + // then another block reconnected), our filter will drop to having only one + // block's worth of transactions in it, but that should be fine, since + // presumably the most common case of relaying a confirmed transaction + // should be just after a new block containing it is found. + RecentConfirmedTransactionsFilter().reset(); +} } // namespace node diff --git a/src/node/txdownloadman_impl.h b/src/node/txdownloadman_impl.h index aee895dbc9f..d55d218c917 100644 --- a/src/node/txdownloadman_impl.h +++ b/src/node/txdownloadman_impl.h @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -122,6 +123,10 @@ public: } TxDownloadManagerImpl() = default; + + void ActiveTipChange(); + void BlockConnected(const std::shared_ptr& pblock); + void BlockDisconnected(); }; } // namespace node #endif // BITCOIN_NODE_TXDOWNLOADMAN_IMPL_H