Skip to content

db: report unreadable coin metadata and keys as errors - #334

Merged
minuszka merged 1 commit into
defcon-project:v22.1.xfrom
minuszka:fix/coins-db-failure-paths-m06
Oct 28, 2026
Merged

minuszka merged 1 commit into
defcon-project:v22.1.xfrom
minuszka:fix/coins-db-failure-paths-m06

Conversation

@minuszka

Copy link
Copy Markdown
Contributor

The coin database could mistake damaged local data for normal states. A present but undecodable or empty head-blocks marker looked like a consistent database, so the replay of an interrupted flush could be skipped. The coins cursor could return a partly decoded first key and treated a damaged later key as the end of the coins, so UTXO statistics, scans and snapshot exports could finish on part of the set. A failed reopen during a cache resize left the coin view without a database and its new sizes already recorded.

What changes: CDBWrapper::TryRead() from Bitcoin Core #34931 tells a missing value from an undecodable one; Read() keeps its existing behavior. Undecodable or empty head-blocks markers and damaged coin keys are now reported as database errors, which stop startup or the RPC call instead of being treated as absent data. If a cache resize cannot reopen the database, it reopens with the previous size; a database that stays closed reports an error on use, and new cache sizes are recorded only after a successful reopen.

What stays the same: Healthy databases behave as before. Database formats, RPC and P2P interfaces and consensus rules are unchanged.

Validation: Independently reviewed and approved. Fault-injection tests cover truncated, count-only and empty head-blocks markers, damaged first and later coin keys and trailing key data, UTXO statistics over a damaged key, and single and double reopen failures, at the coin view and chainstate level. The unchanged code fails the corresponding tests, and the earlier review round's code fails the two cases added during review. All 11 final local CI gates passed, including 827 unit cases, strict unit and Qt leak checks, the required functional tests, and the configure and no-wallet gates; all five commit-lint checks passed.

The TryRead() backport adapts furszy's upstream commit to this fork; the author is credited in the commit.

A present head-blocks marker that did not decode, or named no block,
looked like a consistent coin database, so replay after an interrupted
flush could be skipped. The coins cursor could return a partly decoded
first key and treated a damaged later key as the end of the coins, so
statistics, scans and exports could finish on part of the UTXO set. A
failed reopen during a cache resize left the view without a database
while the new sizes were already recorded.

Add CDBWrapper::TryRead() from Bitcoin Core #34931 (commit 5dfbb91b)
to tell a missing value from an undecodable one. Report undecodable or
empty head-blocks markers and damaged coin keys as database errors.
Reopen with the previous size if a resize fails, report a database that
stays closed as an error, and record new cache sizes only after a
successful reopen. Fault-injection tests cover each case. Healthy
databases, their formats and consensus rules are unchanged.

Co-authored-by: furszy <[email protected]>
@minuszka
minuszka merged commit dff8d26 into defcon-project:v22.1.x Oct 28, 2026
6 checks passed
@minuszka
minuszka deleted the fix/coins-db-failure-paths-m06 branch October 28, 2026 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant