Bitcoin Core merged a Bitcoin wallet migration change on November 25th, with the core reason being to improve error handling and to minimize interruptions that require manual intervention during the use of the wallet.
This pull request is launched following the previous two fixes. The first two fixes addressed issues with unnamed old wallets, as well as the crash problem that occurred when Bitcoin Core was unable to write to the wallet directory. The overall approach is to handle failures in a controlled manner, allowing the process to automatically restore the original wallet to some extent without the need for manual intervention.
This is not the first time that Bitcoin Core has fixed issues related to wallet migration.
What happens when a migration goes wrong?
Some mismatches that occurred during the wallet creation process could previously cause graphical interface applications to crash or return a general error. Now, these discrepancies are captured and reported by Bitcoin Core, allowing the migration process to restore the original wallet from a backup. In some cases, the process may also stop abruptly.
If you attempt to migrate a wallet to a read-only directory, it may also throw an error in real-world scenarios and skip the cleanup process. Now, the program will crash with clear error messages. Tests for this situation will check whether the wallet still retains the old database format after a failure.
The new database will first be constructed by Bitcoin Core.
The biggest change lies in how to migrate the wallet from Bitcoin Core to SQLite. Previously, the program would delete the original database before writing to the new one. If an error occurred during the creation of the new database or while writing wallet records, users would have to manually restore from a backup.
Currently, Bitcoin Core will first build a SQLite database next to the original database, so the old database will continue to remain in its original location. Subsequently, the new database begins to be generated; only once the wallet records are successfully written will Bitcoin Core move the new database into its proper place. This process of pull and request has also been tested for cases where the wallet is stored on an independent file system.
If there are files SQLite and journal remaining in the wallet directory, and SQLite uses them during wallet migration, it may damage the new database. Now, Bitcoin Core will stop the migration upon detecting these files, and tests will also check whether the file journal remains unchanged; at the same time, the wallet will still retain the old format.
It should be noted that the automatic recovery still depends on whether the backup can be successfully copied back. As mentioned by Ryan Ofsky during the review, if this copying step also fails, users will still need to manually restore the backup.











