aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Zumsande <mzumsande@gmail.com>2022-11-28 13:42:35 -0500
committerjonatack <jon@atack.com>2023-01-11 09:18:32 -0800
commite72313e6b3fbf865e0eaa9aee0a555b7a7fe6850 (patch)
tree16ac10c639d82d8a11967ae7aa7c8fcd3721b753
parentca5f8f0de2c6fcf2ac122bd7fbb5a685d5935f71 (diff)
downloadbitcoin-e72313e6b3fbf865e0eaa9aee0a555b7a7fe6850.tar.xz
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
-rw-r--r--src/rpc/net.cpp8
1 files changed, 8 insertions, 0 deletions
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()) {