From adefb51c5437667696cacaf163ea08b39e961358 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 7 May 2023 12:34:40 +1000 Subject: [PATCH] rpc/net: add per-peer inv_to_send sizes --- src/net_processing.cpp | 2 ++ src/net_processing.h | 1 + src/rpc/net.cpp | 2 ++ test/functional/rpc_net.py | 1 + 4 files changed, 6 insertions(+) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index ec6f55cfdf6..373169c08bd 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1728,9 +1728,11 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c if (auto tx_relay = peer->GetTxRelay(); tx_relay != nullptr) { stats.m_relay_txs = WITH_LOCK(tx_relay->m_bloom_filter_mutex, return tx_relay->m_relay_txs); stats.m_fee_filter_received = tx_relay->m_fee_filter_received.load(); + stats.m_inv_to_send = WITH_LOCK(tx_relay->m_tx_inventory_mutex, return tx_relay->m_tx_inventory_to_send.size()); } else { stats.m_relay_txs = false; stats.m_fee_filter_received = 0; + stats.m_inv_to_send = 0; } stats.m_ping_wait = ping_wait; diff --git a/src/net_processing.h b/src/net_processing.h index 8c140d98ad6..ee12bd08d34 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -54,6 +54,7 @@ struct CNodeStateStats { std::chrono::microseconds m_ping_wait; std::vector vHeightInFlight; bool m_relay_txs; + int m_inv_to_send = 0; CAmount m_fee_filter_received; uint64_t m_addr_processed = 0; uint64_t m_addr_rate_limited = 0; diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index fbb70d72161..e5b9880ad96 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -142,6 +142,7 @@ static RPCHelpMan getpeerinfo() {RPCResult::Type::STR, "SERVICE_NAME", "the service name if it is recognised"} }}, {RPCResult::Type::BOOL, "relaytxes", "Whether we relay transactions to this peer"}, + {RPCResult::Type::NUM, "inv_to_send", "How many txs we have queued to announce to this peer"}, {RPCResult::Type::NUM_TIME, "lastsend", "The " + UNIX_EPOCH_TIME + " of the last send"}, {RPCResult::Type::NUM_TIME, "lastrecv", "The " + UNIX_EPOCH_TIME + " of the last receive"}, {RPCResult::Type::NUM_TIME, "last_transaction", "The " + UNIX_EPOCH_TIME + " of the last valid transaction received from this peer"}, @@ -238,6 +239,7 @@ static RPCHelpMan getpeerinfo() obj.pushKV("services", strprintf("%016x", services)); obj.pushKV("servicesnames", GetServicesNames(services)); obj.pushKV("relaytxes", statestats.m_relay_txs); + obj.pushKV("inv_to_send", statestats.m_inv_to_send); obj.pushKV("lastsend", count_seconds(stats.m_last_send)); obj.pushKV("lastrecv", count_seconds(stats.m_last_recv)); obj.pushKV("last_transaction", count_seconds(stats.m_last_tx_time)); diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py index 41ecbbed22d..f52d59d7b3e 100755 --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -166,6 +166,7 @@ class NetTest(BitcoinTestFramework): "permissions": [], "presynced_headers": -1, "relaytxes": False, + "inv_to_send": 0, "services": "0000000000000000", "servicesnames": [], "session_id": "" if not self.options.v2transport else no_version_peer.v2_state.peer['session_id'].hex(),