aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-01-20 11:21:32 +0000
committerfanquake <fanquake@gmail.com>2023-01-20 11:34:12 +0000
commit2b87e905857ba456db2cb3d0297a3102f17417be (patch)
tree282b9348de51872b2d873fb973ef9286b74b0332
parent5148145b3597cd6f99e68d0bdb9dae6705a3b9b6 (diff)
parente72313e6b3fbf865e0eaa9aee0a555b7a7fe6850 (diff)
downloadbitcoin-2b87e905857ba456db2cb3d0297a3102f17417be.tar.xz
Merge bitcoin/bitcoin#26457: [24.x] backport rpc: skip getpeerinfo for a peer without CNodeStateStats
e72313e6b3fbf865e0eaa9aee0a555b7a7fe6850 rpc: Require NodeStateStats object in getpeerinfo (Martin Zumsande) Pull request description: Backports #26515. ACKs for top commit: fanquake: ACK e72313e6b3fbf865e0eaa9aee0a555b7a7fe6850 Tree-SHA512: 28e885ea299fe8a3a7538628d413c434bc42c251a2c1ae238bca0652709f5bd781eb157675171ab538f6e2f6f720f1c184200ac3857f6c78f48858949eed49da
-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()) {