diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 170352f7299..831cfe05a32 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -503,6 +503,7 @@ public: std::vector GetOrphanTransactions() override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex); PeerManagerInfo GetInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); + std::pair GetFanoutPeersCount() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void RelayTransaction(const uint256& txid, const uint256& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void SetBestBlock(int height, std::chrono::seconds time) override { @@ -2114,6 +2115,26 @@ void PeerManagerImpl::SendPings() for(auto& it : m_peer_map) it.second->m_ping_queued = true; } +std::pair PeerManagerImpl::GetFanoutPeersCount() +{ + + size_t inbounds_fanout_tx_relay = 0, outbounds_fanout_tx_relay = 0; + + if (m_txreconciliation) { + LOCK(m_peer_mutex); + for(const auto& [peer_id, peer] : m_peer_map) { + if (const auto tx_relay = peer->GetTxRelay()) { + const bool peer_relays_txs = WITH_LOCK(tx_relay->m_bloom_filter_mutex, return tx_relay->m_relay_txs); + if (peer_relays_txs && !m_txreconciliation->IsPeerRegistered(peer_id)) { + peer->m_is_inbound ? ++inbounds_fanout_tx_relay : ++outbounds_fanout_tx_relay; + } + } + } + } + + return std::pair(inbounds_fanout_tx_relay, outbounds_fanout_tx_relay); +} + void PeerManagerImpl::RelayTransaction(const uint256& txid, const uint256& wtxid) { LOCK(m_peer_mutex); diff --git a/src/net_processing.h b/src/net_processing.h index 0d2dc59c5ae..a51edb6f4dd 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -108,6 +108,9 @@ public: /** Relay transaction to all peers. */ virtual void RelayTransaction(const uint256& txid, const uint256& wtxid) = 0; + /** Get the amount of inbounds (first) and outbounds fanout peers (second). */ + virtual std::pair GetFanoutPeersCount() = 0; + /** Send ping message to all peers */ virtual void SendPings() = 0;