From e72313e6b3fbf865e0eaa9aee0a555b7a7fe6850 Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Mon, 28 Nov 2022 13:42:35 -0500 Subject: rpc: Require NodeStateStats object in getpeerinfo There is no situation in which CNodeStateStats could be missing for a legitimate reason - this can only happen if there is a race condition between peer disconnection and the getpeerinfo call, in which case the disconnected peer doesn't need to be included in the response. Github-Pull: bitcoin#26515 Rebased-From: 6fefd49 --- src/rpc/net.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index d701a180ab..f715926309 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -185,6 +185,14 @@ static RPCHelpMan getpeerinfo() UniValue obj(UniValue::VOBJ); CNodeStateStats statestats; bool fStateStats = peerman.GetNodeStateStats(stats.nodeid, statestats); + // GetNodeStateStats() requires the existence of a CNodeState and a Peer object + // to succeed for this peer. These are created at connection initialisation and + // exist for the duration of the connection - except if there is a race where the + // peer got disconnected in between the GetNodeStats() and the GetNodeStateStats() + // calls. In this case, the peer doesn't need to be reported here. + if (!fStateStats) { + continue; + } obj.pushKV("id", stats.nodeid); obj.pushKV("addr", stats.m_addr_name); if (stats.addrBind.IsValid()) { -- cgit v1.2.3