Skip to content

Commit 3d97496

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#26515: rpc: skip getpeerinfo for a peer without CNodeStateStats
6fefd49 rpc: Require NodeStateStats object in getpeerinfo (Martin Zumsande) Pull request description: The objects `CNode`, `CNodeState` and `Peer` store different info about a peer - `InitializeNode()` and `FinalizeNode()` make sure that for the duration of a connection, we should always have one of each for a peer. Therefore, there is no situation in which, as part of getpeerinfo RPC, `GetNodeStateStats()` (which requires a `CNodeState` and a `Peer` entry for a `NodeId` to succeed) could fail for a legitimate reason while the peer is connected - this can only happen if there is a race condition between peer disconnection and the `getpeerinfo` processing (see also a more detailed description of this in bitcoin/bitcoin#26457 (review)). But in this case I think it's better to just not include the newly disconnected peer in the response instead of returning just parts of its data. An earlier version of this PR also made the affected `CNodeStateStats` fields non-optional (see mzumsande/bitcoin@5f900e2). Since this conflicts with #25923 and should be a separate discussion, I removed that commit from this PR. ACKs for top commit: dergoegge: Approach ACK 6fefd49 MarcoFalke: review ACK 6fefd49 👒 Tree-SHA512: 89c8f7318df4634c1630415de9c8350e6dc2d14d9d07e039e5b180c51bfd3ee2ce99eeac4f9f858af7de846f7a6b48fcae96ebac08495b30e431a5d2d4660532
2 parents 65f5cfd + 6fefd49 commit 3d97496

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)