AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 53 Bitcoin

Merge bitcoin/bitcoin#34193: wallet: make migration more robust against failures

Public commit record

What the developer wrote

Authored by Ava Chow

91/100 · Strong
Merge bitcoin/bitcoin#34193: wallet: make migration more robust against failures

399a5a3805884e7ac5a2cbdf616be8c9041bc2bd test: migrate a wallet with a leftover journal at its location (furszy)
42131a81fdc42ab0cb295a2267ce33e9fb8221ff test: migrate wallet located on a different filesystem (furszy)
b8ef499909b09f9dffa32172912c1e37f2e78867 wallet: migration, make sqlite creation robust against failures (furszy)
e3a5a48a03565696947be3ff3516ae013d4fd658 wallet: migration, add MigrationFilePrefix() helper (Ryan Ofsky)
b6b2f9f12b13e429a8511130bdcdc7075adbc28e wallet: use RunWithinTxn within MigrateToSQLite (furszy)
cf5e6803f07d1bfc6ae7ac655e7063c650bcb2f8 wallet: fail migration gracefully on non-writable wallets (furszy)
84a9f486475de9fab0b5cc8ab7b0338e04117163 wallet: migration, restore backup if an exception is thrown (furszy)
3a9ba874bb7efab4401d86a073964774f88de393 wallet: migration, handle exceptions during wallet creation (furszy)
edbf3b62a2cb258bb585045c769b1215c577e8e1 wallet: migration, unify watchonly and solvables wallets creation (furszy)

Pull request description:

This is just me finding a few more edge cases after #34156 and #34176

The goal of the PR is to handle failures in a controlled way. Just so the process can automatically restore the original wallet without requiring user manual intervention.

The covered cases are:

1. During `DoMigration()`: There are methods that can throw exceptions and abruptly abort the process.

Instead of crashing (GUI) or returning a generic exception, we now will catch and return the error gracefully. This lets the process restore the original wallet automatically.

2. Trying to migrate a wallet in a read-only directory throws a filesystem exception and skips cleanup.

Now the process will fail gracefully with a clear error msg, and automatically restore the original wallet.

3. Any failure during `MigrateToSQLite` requires user manual intervention.

Now the original wallet db will remain untouched, and only be updated once the sqlite db creation fully succeeds.

ACKs for top commit:
achow101:
ACK 399a5a3805884e7ac5a2cbdf616be8c9041bc2bd
w0xlt:
reACK 399a5a3805884e7ac5a2cbdf616be8c9041bc2bd
ryanofsky:
Code review ACK 399a5a3805884e7ac5a2cbdf616be8c9041bc2bd. This is a clear improvement over master, which deletes the original database before writing the new one and asserts if anything fails after that. Now the new database is fully built before it replaces the original, failures after that point restore the backup, and a leftover journal at the wallet location stops the migration instead of corrupting the new database.

Tree-SHA512: 429ab6462fd68886345ecf85d0e9080e77f6a216c2b92d4ddbad411afccc88a0382a021c58b070755f9c81ec2dd4dbf6f5f0e5a3d843fc2d4c9cf6233b666274
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This Bitcoin Core update hardens the wallet migration tool so that if something goes wrong while converting an old wallet to the new SQLite format, the original wallet is preserved or restored automatically instead of being left in a broken state. It also prevents migration from accidentally corrupting the new wallet when leftover database files are present. There is no evidence this is an actively exploitable attack; it is a defensive robustness fix.

Recommended action

Apply the patch. It is a defensive hardening improvement for the wallet migration path. Users planning to migrate legacy wallets should run a version that includes this fix to reduce the risk of wallet corruption or loss if migration fails.

Security signals we found

01

Original migration code deleted the legacy BDB file before the new SQLite database was fully created, risking data loss on failure

02

New migration builds SQLite database in a temporary path and atomically moves it only after successful record write

03

Leftover SQLite journal at destination is now rejected to prevent rollback corruption of the migrated database

04

Read-only wallet directory now fails gracefully with a clear error instead of throwing an unhandled filesystem exception

05

Failures after the original database may have been erased now throw so the caller restores the backup

06

Common wallet creation helper catches exceptions and returns false so backup restoration can proceed

Risk score

Why this scored 53/100

Our methodology →
Potential impact 18/30
Exploitability 8/25
Stealth signal 6/15
Affected reach 9/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.