Skip to content

Commit

Permalink
Merge #26457: [24.x] backport rpc: skip getpeerinfo for a peer withou…
Browse files Browse the repository at this point in the history
…t CNodeStateStats

e72313e rpc: Require NodeStateStats object in getpeerinfo (Martin Zumsande)

Pull request description:

  Backports #26515.

ACKs for top commit:
  fanquake:
    ACK e72313e

Tree-SHA512: 28e885ea299fe8a3a7538628d413c434bc42c251a2c1ae238bca0652709f5bd781eb157675171ab538f6e2f6f720f1c184200ac3857f6c78f48858949eed49da
  • Loading branch information
fanquake committed Jan 20, 2023
2 parents 5148145 + e72313e commit 2b87e90
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 2b87e90

Please sign in to comment.