Bitcoin Core merges wallet migration fix to protect legacy data in SQLite move

Editorial illustration: An open Bitcoin wallet and a cylindrical storage container hold stacks of cream-colored records, connected by glowing arrows pointing in opposite directions.

In brief

  • Bitcoin Core merged a wallet migration change on November 25, according to U.Today.
  • The new SQLite database is now built beside the original rather than after deleting it.
  • Failed migrations can restore the original wallet from its backup without manual steps.
  • Reviewer Ryan Ofsky noted manual restoration is still needed if the backup copy crashes.

What changed in the SQLite move

U.Today called the change to how Bitcoin Core moves the wallet to SQLite the biggest part of the update. Previously, Bitcoin Core deleted the original database before writing the new one. If something broke while creating the new database (or while writing wallet records), the user could be left restoring the backup by hand.

That's the part this fixes.

Under the merged change, Bitcoin Core builds the SQLite database next to the original, so the old database stays in place. It only moves the new database into place once the wallet records have been written successfully. The pull request also tested the process with a wallet stored on a separate filesystem, per the report.

Cleaner failures, fewer crashes

The pull request followed two earlier fixes: one for unnamed legacy wallets, and another for crashes when Bitcoin Core couldn't write to the wallet directory. Some mismatches during wallet creation used to crash the graphical app or return a generic error. Bitcoin Core now catches and reports them, which lets migration restore the original wallet from its backup.

Read-only directories got attention too. Trying to migrate a wallet in one could throw an error and skip cleanup; U.Today said the process now stops with a clear error message, and a test checks that the wallet is still in the old database format after the failure.

A leftover SQLite journal is another edge case. If SQLite used that file for the migrated wallet, it could corrupt the new database. Bitcoin Core now stops the migration when it finds one (a test checks that the journal stays in place), and the wallet keeps its legacy format.

The remaining caveat

So what happens if the restore itself fails?

Automatic recovery still depends on the backup being copied back successfully. As reviewer Ryan Ofsky noted in his review, as reported by U.Today, the user still has to restore the backup manually if that copy crashes.

U.Today's report describes a merged change rather than a release, and it doesn't name a version number that will ship it.

Frequently asked questions

How does the Bitcoin Core change make wallet migration to SQLite safer?

Previously, Bitcoin Core deleted the original database before writing the new one. Under the merged change, it builds the SQLite database next to the original, leaves the old database in place, and moves the new one into place only after the wallet records are written successfully, according to U.Today.

Can a failed Bitcoin Core wallet migration still require manual recovery?

Yes. Automatic recovery still depends on the backup being copied back successfully. Reviewer Ryan Ofsky noted that if that copy crashes, the user still has to restore the backup by hand, as reported by U.Today.