diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 8dcd80635..36464159f 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -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));