Skip to content

Commit e72313e

Browse files
mzumsandejonatack
authored andcommitted
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
1 parent ca5f8f0 commit e72313e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/rpc/net.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ static RPCHelpMan getpeerinfo()
185185
UniValue obj(UniValue::VOBJ);
186186
CNodeStateStats statestats;
187187
bool fStateStats = peerman.GetNodeStateStats(stats.nodeid, statestats);
188+
// GetNodeStateStats() requires the existence of a CNodeState and a Peer object
189+
// to succeed for this peer. These are created at connection initialisation and
190+
// exist for the duration of the connection - except if there is a race where the
191+
// peer got disconnected in between the GetNodeStats() and the GetNodeStateStats()
192+
// calls. In this case, the peer doesn't need to be reported here.
193+
if (!fStateStats) {
194+
continue;
195+
}
188196
obj.pushKV("id", stats.nodeid);
189197
obj.pushKV("addr", stats.m_addr_name);
190198
if (stats.addrBind.IsValid()) {

0 commit comments

Comments
 (0)