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
This commit is contained in:
fanquake 2023-01-20 11:21:32 +00:00
commit 2b87e90585
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1

View File

@ -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()) {