From 3a41926d1b59dc9bbabc38cdc461c169426d94e7 Mon Sep 17 00:00:00 2001 From: glozow Date: Thu, 25 Apr 2024 11:48:43 +0100 Subject: [PATCH] [refactor] move notfound processing to txdownload --- src/net_processing.cpp | 8 ++++---- src/node/txdownloadman.h | 3 +++ src/node/txdownloadman_impl.cpp | 13 +++++++++++++ src/node/txdownloadman_impl.h | 3 +++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 71162e957db..3f4f4f6af38 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -5133,16 +5133,16 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, if (msg_type == NetMsgType::NOTFOUND) { std::vector vInv; vRecv >> vInv; + std::vector tx_invs; if (vInv.size() <= node::MAX_PEER_TX_ANNOUNCEMENTS + MAX_BLOCKS_IN_TRANSIT_PER_PEER) { - LOCK(m_tx_download_mutex); for (CInv &inv : vInv) { if (inv.IsGenTxMsg()) { - // If we receive a NOTFOUND message for a tx we requested, mark the announcement for it as - // completed in TxRequestTracker. - m_txdownloadman.GetTxRequestRef().ReceivedResponse(pfrom.GetId(), inv.hash); + tx_invs.emplace_back(inv.hash); } } } + LOCK(m_tx_download_mutex); + m_txdownloadman.ReceivedNotFound(pfrom.GetId(), tx_invs); return; } diff --git a/src/node/txdownloadman.h b/src/node/txdownloadman.h index ce0c9594281..6995725ecc6 100644 --- a/src/node/txdownloadman.h +++ b/src/node/txdownloadman.h @@ -108,6 +108,9 @@ public: /** Get getdata requests to send. */ std::vector GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time); + + /** Should be called when a notfound for a tx has been received. */ + void ReceivedNotFound(NodeId nodeid, const std::vector& txhashes); }; } // namespace node #endif // BITCOIN_NODE_TXDOWNLOADMAN_H diff --git a/src/node/txdownloadman_impl.cpp b/src/node/txdownloadman_impl.cpp index d0125f69ec0..6b505af22f2 100644 --- a/src/node/txdownloadman_impl.cpp +++ b/src/node/txdownloadman_impl.cpp @@ -67,6 +67,10 @@ std::vector TxDownloadManager::GetRequestsToSend(NodeId nodeid, std::ch { return m_impl->GetRequestsToSend(nodeid, current_time); } +void TxDownloadManager::ReceivedNotFound(NodeId nodeid, const std::vector& txhashes) +{ + m_impl->ReceivedNotFound(nodeid, txhashes); +} // TxDownloadManagerImpl void TxDownloadManagerImpl::ActiveTipChange() @@ -205,4 +209,13 @@ std::vector TxDownloadManagerImpl::GetRequestsToSend(NodeId nodeid, std } return requests; } + +void TxDownloadManagerImpl::ReceivedNotFound(NodeId nodeid, const std::vector& txhashes) +{ + for (const auto& txhash : txhashes) { + // If we receive a NOTFOUND message for a tx we requested, mark the announcement for it as + // completed in TxRequestTracker. + m_txrequest.ReceivedResponse(nodeid, txhash); + } +} } // namespace node diff --git a/src/node/txdownloadman_impl.h b/src/node/txdownloadman_impl.h index 49948908d41..a2af7506e7b 100644 --- a/src/node/txdownloadman_impl.h +++ b/src/node/txdownloadman_impl.h @@ -156,6 +156,9 @@ public: /** Get getdata requests to send. */ std::vector GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time); + + /** Marks a tx as ReceivedResponse in txrequest. */ + void ReceivedNotFound(NodeId nodeid, const std::vector& txhashes); }; } // namespace node #endif // BITCOIN_NODE_TXDOWNLOADMAN_IMPL_H