mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
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
This commit is contained in:
parent
ca5f8f0de2
commit
e72313e6b3
1 changed files with 8 additions and 0 deletions
|
@ -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()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue