fix: simplify logic in AskPeersForTransactions and remove erroneous negative EXCLUSIVE_LOCKS_REQUIRED

This commit is contained in:
pasta 2024-12-01 22:42:28 -06:00
parent 090ae9237e
commit 30fc76c397
No known key found for this signature in database
GPG Key ID: E2F3D7916E722D38

View File

@ -637,7 +637,7 @@ private:
/** /**
* Private implementation of IsInvInFilter which does not call GetPeerRef; to be prefered when the PeerRef is available. * 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. /** Get a shared pointer to the Peer object.
* May return an empty shared_ptr if the Peer object can't be found. */ * 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<PeerRef> peersToAsk; std::vector<PeerRef> peersToAsk;
peersToAsk.reserve(4); 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); LOCK(m_peer_mutex);
// TODO consider prioritizing MNs again, once that flag is moved into Peer // TODO consider prioritizing MNs again, once that flag is moved into Peer
for (const auto& [_, peer] : m_peer_map) { for (const auto& [_, peer] : m_peer_map) {
if (!maybe_add_to_nodesToAskFor(peer)) { if (peersToAsk.size() >= 4) {
break; break;
} }
if (IsInvInFilter(peer, txid)) {
peersToAsk.emplace_back(peer);
}
} }
} }
{ {