Skip to content

Commit

Permalink
fix: simplify logic in AskPeersForTransactions and remove erroneous n…
Browse files Browse the repository at this point in the history
…egative EXCLUSIVE_LOCKS_REQUIRED
  • Loading branch information
PastaPastaPasta committed Dec 2, 2024
1 parent 090ae92 commit 30fc76c
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -2252,23 +2252,16 @@ void PeerManagerImpl::AskPeersForTransaction(const uint256& txid, bool is_master
std::vector<PeerRef> 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);
}
}
}
{
Expand Down

0 comments on commit 30fc76c

Please sign in to comment.