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:
2026-11-20 20:10:01 -06:00
co-authored by Claude Opus 5.5
parent 3537531901
commit 93f8b3768b
6 changed files with 43 additions and 10 deletions
+12 -3
View File
@@ -5288,7 +5288,11 @@ UniValue z_getoperationresult(const UniValue& params, bool fHelp, const CPubKey&
+ HelpExampleRpc("z_getoperationresult", "'[\"operationid\", ... ]'")
);
// This call will remove finished operations
// This call will remove finished operations. It keeps cs_main + cs_wallet, which
// z_getoperationstatus no longer takes: the wallet schedulers (RunSaplingSweep and friends,
// z_consolidate) cancel and pop their previous operation under cs_wallet, and this keeps the
// removal serialised with them and with other z_getoperationresult callers, as before.
LOCK2(cs_main, pwalletMain->cs_wallet);
return z_getoperationstatus_IMPL(params, true);
}
@@ -5317,7 +5321,11 @@ UniValue z_getoperationstatus(const UniValue& params, bool fHelp, const CPubKey&
UniValue z_getoperationstatus_IMPL(const UniValue& params, bool fRemoveFinishedOperations=false)
{
LOCK2(cs_main, pwalletMain->cs_wallet);
// No cs_main/cs_wallet here (the removing caller, z_getoperationresult, takes them itself).
// Nothing below reads chain or wallet state: AsyncRPCQueue guards its map with its own mutex,
// and getStatus() (base and every override) reads only the atomic state_, members fixed at
// construction, and result/error under the operation's own lock_. Holding the wallet locks
// only made a GUI's status poll wait behind block connection and wallet scans.
std::set<AsyncRPCOperationId> filter;
if (params.size()==1) {
@@ -6454,7 +6462,8 @@ UniValue z_listoperationids(const UniValue& params, bool fHelp, const CPubKey& m
+ HelpExampleRpc("z_listoperationids", "")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
// No cs_main/cs_wallet: like z_getoperationstatus, this only reads the self-locking async
// queue and each operation's atomic state.
std::string filter;
bool useFilter = false;