rpc: hold cs_main across gettxoutsetinfo's flush and scan
gettxoutsetinfo flushed the chainstate and then scanned it with no lock. GetStats reads the best block and iterates a snapshot of the coins database separately, so a flush landing in between reported the UTXO totals of a different block than the "height" and "bestblock" it returned. Hold cs_main across both. The transparent UTXO set of a fully shielded chain is small, so the scan is short (12 outputs on a 113-block regtest chain). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -861,6 +861,11 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp, const CPubKey& mypk
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
|
||||
CCoinsStats stats;
|
||||
// Hold cs_main across the flush and the scan: GetStats reads the best block and iterates a
|
||||
// snapshot of the coins database separately, and a flush landing in between would report the
|
||||
// UTXO totals of a different block than "height"/"bestblock" claim. The transparent UTXO set
|
||||
// of a fully shielded chain is small, so the scan is short.
|
||||
LOCK(cs_main);
|
||||
FlushStateToDisk();
|
||||
if (pcoinsTip->GetStats(stats)) {
|
||||
ret.push_back(Pair("height", (int64_t)stats.nHeight));
|
||||
|
||||
Reference in New Issue
Block a user