From 94da0de6efbbab258414e248986a6b9cd588c83a Mon Sep 17 00:00:00 2001 From: pasta Date: Sat, 23 Nov 2024 00:28:13 -0600 Subject: [PATCH] refactor: implement minimal RelayInv which doesn't rely on m_connman 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 --- src/net_processing.cpp | 10 ++++++++++ src/net_processing.h | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 8cd7c089e0..e43217d891 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -614,6 +614,7 @@ public: 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); @@ -2289,6 +2290,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::RelayDSQ(const CCoinJoinQueue& queue) { CInv inv{MSG_DSQ, queue.GetHash()}; diff --git a/src/net_processing.h b/src/net_processing.h index 93506873d7..2a302ee9dc 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -98,7 +98,8 @@ public: virtual void RelayDSQ(const CCoinJoinQueue& queue) = 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;