mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 03:03:22 -03: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.
This commit is contained in:
parent
6863ad79a6
commit
6fefd49527
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