rpc: read the peer list under cs_vNodes in getinfo/getnetworkinfo; z_getoperationstatus without cs_main
From origin/perf/wallet-scan-rpc-costs, both still on dev: - getinfo and getnetworkinfo read vNodes.size() and iterated vNodes without cs_vNodes, racing the network threads that add and remove peers (a reallocation mid-iteration is undefined behaviour). Both now count through one helper that takes the lock. - z_getoperationstatus and z_listoperationids took cs_main and cs_wallet, though they only read the async queue (which has its own mutex) and each operation's status. GUIs poll them, so every poll contended with block validation. Regtest: z_getoperationstatus reports a running sweep normally. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+6
-2
@@ -533,6 +533,10 @@ UniValue getnetworkinfo(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
+ HelpExampleRpc("getnetworkinfo", "")
|
||||
);
|
||||
|
||||
// vNodes is guarded by cs_vNodes, not cs_main (see getinfo).
|
||||
int nConnections = 0, nTlsConnections = 0;
|
||||
GetNodeCounts(nConnections, nTlsConnections);
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
@@ -541,8 +545,8 @@ UniValue getnetworkinfo(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
obj.push_back(Pair("protocolversion",PROTOCOL_VERSION));
|
||||
obj.push_back(Pair("localservices", strprintf("%016x", nLocalServices)));
|
||||
obj.push_back(Pair("timeoffset", 0));
|
||||
obj.push_back(Pair("connections", (int)vNodes.size()));
|
||||
obj.push_back(Pair("tls_connections", (int)std::count_if(vNodes.begin(), vNodes.end(), [](CNode* n) {return n->ssl != NULL;})));
|
||||
obj.push_back(Pair("connections", nConnections));
|
||||
obj.push_back(Pair("tls_connections", nTlsConnections));
|
||||
obj.push_back(Pair("networks", GetNetworksInfo()));
|
||||
obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
|
||||
UniValue localAddresses(UniValue::VARR);
|
||||
|
||||
Reference in New Issue
Block a user