From 30fc76c3970371aa97aa8e7baada868162a3932d Mon Sep 17 00:00:00 2001 From: pasta Date: Sun, 1 Dec 2024 22:42:28 -0600 Subject: [PATCH] fix: simplify logic in AskPeersForTransactions and remove erroneous negative EXCLUSIVE_LOCKS_REQUIRED --- src/net_processing.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 08815dc6b0e1e..c94ea82b7c57a 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -637,7 +637,7 @@ class PeerManagerImpl final : public PeerManager /** * Private implementation of IsInvInFilter which does not call GetPeerRef; to be prefered when the PeerRef is available. */ - bool IsInvInFilter(const PeerRef& peer, const uint256& hash) const EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); + bool IsInvInFilter(const PeerRef& peer, const uint256& hash) const; /** Get a shared pointer to the Peer object. * May return an empty shared_ptr if the Peer object can't be found. */ @@ -2252,23 +2252,16 @@ void PeerManagerImpl::AskPeersForTransaction(const uint256& txid, bool is_master std::vector peersToAsk; peersToAsk.reserve(4); - auto maybe_add_to_nodesToAskFor = [&](const PeerRef& peer) { - if (peersToAsk.size() >= 4) { - return false; - } - if (IsInvInFilter(peer, txid)) { - peersToAsk.emplace_back(peer); - } - return true; - }; - { LOCK(m_peer_mutex); // TODO consider prioritizing MNs again, once that flag is moved into Peer for (const auto& [_, peer] : m_peer_map) { - if (!maybe_add_to_nodesToAskFor(peer)) { + if (peersToAsk.size() >= 4) { break; } + if (IsInvInFilter(peer, txid)) { + peersToAsk.emplace_back(peer); + } } } {