diff --git a/src/net_processing.cpp b/src/net_processing.cpp index cd538d614e4fc1..eeefe17afa8453 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -510,6 +510,7 @@ class PeerManagerImpl final : public PeerManager std::optional FetchBlock(NodeId peer_id, const CBlockIndex& block_index) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); + size_t GetPeerMemory(NodeId nodeid) const override; bool IgnoresIncomingTxs() override { return m_opts.ignore_incoming_txs; } void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void RelayTransaction(const uint256& txid, const uint256& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); @@ -1670,6 +1671,11 @@ PeerRef PeerManagerImpl::RemovePeer(NodeId id) return ret; } +size_t PeerManagerImpl::GetPeerMemory(NodeId nodeid) const +{ + return 0; +} + bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const { { diff --git a/src/net_processing.h b/src/net_processing.h index 80d07648a48ef6..20f7e97c263e4b 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -83,6 +83,8 @@ class PeerManager : public CValidationInterface, public NetEventsInterface /** Get statistics from node state */ virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0; + virtual size_t GetPeerMemory(NodeId nodeid) const = 0; + /** Whether this node ignores txs received over p2p. */ virtual bool IgnoresIncomingTxs() = 0; diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index e1992127d33ebf..078aeb3316f03f 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -111,7 +111,8 @@ static RPCHelpMan getpeermemoryinfo() { { {RPCResult::Type::NUM, "id", "Peer id"}, - {RPCResult::Type::NUM, "memory", "the result of GetDynamicMemoryUsage for that node"}, + {RPCResult::Type::NUM, "dynamic-cnode-memory", "the result of CNode::DynamicMemoryUsage"}, + {RPCResult::Type::NUM, "dynamic-peer-memory", "the result of PeerManagerImpl::DynamicMemoryUsage"}, }}, }}, }, @@ -123,31 +124,22 @@ static RPCHelpMan getpeermemoryinfo() { NodeContext& node = EnsureAnyNodeContext(request.context); const CConnman& connman = EnsureConnman(node); - //const PeerManager& peerman = EnsurePeerman(node); + const PeerManager& peerman = EnsurePeerman(node); - //std::vector vstats; - //connman.GetNodeStats(vstats); + UniValue ret(UniValue::VARR); // map of node id -> memory usage std::map info; + // call DynamicMemoryUsage on all CNode objects connman.GetNodeMemory(info); + for (const auto& [node_id, node_memory] : info) { + UniValue obj(UniValue::VOBJ); + obj.pushKV("id", node_id); + obj.pushKV("dynamic-cnode-memory", node_memory); - UniValue ret(UniValue::VARR); - - //for (const CNodeStats& stats : vstats) { - //UniValue obj(UniValue::VOBJ); - //CNodeStateStats statestats; - //obj.pushKV("id", stats.nodeid); - //obj.pushKV("addr", stats.m_addr_name); - //obj.pushKV("addr_relay_enabled", statestats.m_addr_relay_enabled); - - //ret.push_back(obj); - //} + auto peer_memory = peerman.GetPeerMemory(node_id); + obj.pushKV("dynamic-peer-memory", peer_memory); - for (const auto& vals : info) { - UniValue obj(UniValue::VOBJ); - obj.pushKV("id", vals.first); - obj.pushKV("memory", vals.second); ret.push_back(obj); }