Skip to content

Commit

Permalink
refactor: implement minimal RelayInv which doesn't rely on m_connman
Browse files Browse the repository at this point in the history
Vast majority of usages of RelayInv don't use the minProtoVersion, we may as well have these not contribute to contention of m_nodes_mutex / use m_connman
  • Loading branch information
PastaPastaPasta committed Nov 23, 2024
1 parent f9d044d commit a7cd23e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ class PeerManagerImpl final : public PeerManager
bool IgnoresIncomingTxs() override { return m_ignore_incoming_txs; }
void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);;
void PushInventory(NodeId nodeid, const CInv& inv) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void RelayInv(CInv &inv) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void RelayInv(CInv &inv, const int minProtoVersion) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void RelayInvFiltered(CInv &inv, const CTransaction &relatedTx, const int minProtoVersion) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void RelayInvFiltered(CInv &inv, const uint256 &relatedTxHash, const int minProtoVersion) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
Expand Down Expand Up @@ -2279,6 +2280,15 @@ void PeerManagerImpl::RelayInv(CInv &inv, const int minProtoVersion)
});
}

void PeerManagerImpl::RelayInv(CInv &inv)
{
LOCK(m_peer_mutex);
for (const auto& [_, peer] : m_peer_map) {
if (!peer->GetInvRelay()) continue;
PushInv(*peer, inv);
}
}

void PeerManagerImpl::RelayInvFiltered(CInv &inv, const CTransaction& relatedTx, const int minProtoVersion)
{
// TODO: Migrate to iteration through m_peer_map
Expand Down
3 changes: 2 additions & 1 deletion src/net_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
virtual void PushInventory(NodeId nodeid, const CInv& inv) = 0;

/** Relay inventories to all peers */
virtual void RelayInv(CInv &inv, const int minProtoVersion = MIN_PEER_PROTO_VERSION) = 0;
virtual void RelayInv(CInv &inv) = 0;
virtual void RelayInv(CInv &inv, const int minProtoVersion) = 0;
virtual void RelayInvFiltered(CInv &inv, const CTransaction &relatedTx,
const int minProtoVersion = MIN_PEER_PROTO_VERSION) = 0;

Expand Down

0 comments on commit a7cd23e

Please sign in to comment.