You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ComputeUTXOStats returns a hash of a partial UTXO set when the coins iterator fails #8293
kernel::ComputeUTXOStats() (src/kernel/coinstats.cpp) walks the coins database with a CCoinsViewCursor until Valid() returns false, and fails only when GetKey() or GetValue() cannot decode an entry. The cursor never reports the status of the underlying LevelDB iterator. If a disk read or checksum error ends the scan early, or skips a table block, the loop stops as if it had reached the end of the set, and the function returns a successful hash and counts for an incomplete UTXO set.
CDBIterator::HasError() already exposes that status, but CCoinsViewDBCursor (src/txdb.cpp) does not forward it, and ComputeUTXOStats() does not check it. Bitcoin Core has the same gap.
Effect
gettxoutsetinfo and dumptxoutset can report or write statistics for a partial set without any error.
AssumeUTXO completion (MaybeCompleteSnapshotValidation()) hashes the background chainstate's coins and compares the result with the pinned hash_serialized. A local read error there yields a mismatching hash instead of a failed scan. That takes the hash-mismatch path, which rejects a good snapshot and shuts the node down, rather than the local-failure path, which keeps it.
Expected
A scan that ends because of an iterator error fails like a decode error: ComputeUTXOStats() returns no result, so its callers report a local read failure instead of a wrong hash.
Suggested fix
Add HasError() to CCoinsViewCursor (default false), implement it in CCoinsViewDBCursor from the wrapped CDBIterator, and have ComputeUTXOStats() check it after the loop, before it finalizes the hash. A unit test can make the iterator report an error partway through the scan and check that no stats are returned.
Context
Raised during review of #8272. That PR keeps the snapshot on a failed scan, but this cursor gap is independent of the Evo snapshot work, so it is tracked here to be fixed in its own PR.
Activity