Bitcoin Core has merged a wallet migration fix aimed at preventing data loss when wallets are moved to SQLite, according to a report from U.Today. The change, described as broadly merged on November 25, is designed to improve error handling and allow automatic recovery from failed migrations.
Sources: u.today
The pull request follows two earlier fixes: one for unnamed legacy wallets and another for crashes when Bitcoin Core could not write to the wallet directory. The report said the intent is to handle failures in a controlled way so the process can automatically restore the original wallet without manual intervention, to a significant degree.
How the migration process changes
The biggest change concerns how Bitcoin Core moves a wallet to SQLite. Previously, the original database was deleted before the new one was written. If something went wrong while creating the new database or writing wallet records, the user could end up restoring the backup by hand.
Now Bitcoin Core builds the SQLite database next to the original, so the old database stays in place while the new one is being built. Once wallet records have been written successfully, Bitcoin Core can move the new database into place. The pull request also tests this with a wallet stored on a separate filesystem.
The report noted that some mismatches during wallet creation could crash the graphical app or cause it to return a generic error. Those differences are now caught by Bitcoin Core and reported, which lets the migration process restore the original wallet from its backup.
Error handling and recovery limits
In another case, trying to migrate a wallet in a read-only directory could throw an error and skip cleanup. The report said the process now crashes with a clear error message, and the test checks that the wallet remains in the old database format after the failure.
A leftover SQLite journal in the wallet directory can corrupt the new database if SQLite uses it for the migrated wallet. Bitcoin Core now stops the migration when it finds such a file, and the test checks that the journal stays in place while the wallet keeps its legacy format.
The report added that automatic recovery still hinges on the backup being copied back successfully. As Ryan Ofsky mentioned in his review, if that copy fails, the recovery may not complete. The report did not specify a release date for the change.