Skip to content

gui: Add a menu action to restore then migrate a legacy wallet #877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

achow101
Copy link
Member

Some users will have a backup of their legacy wallet. These cannot be restored since the "Restore Wallet" action expects to be able to load the wallet after restoring, and this fails for legacy wallets now that they are deleted. Furthermore, the "Migrate Wallet" action only allows users to migrate wallets that are in the wallets directory, so such backups cannot be migrated from the GUI.

This PR resolves this issue by adding a menu item in the "Migrate Wallet" menu which allows users to select their backup file so that it will first be restored but not loaded, and then migrated.

Depends on bitcoin/bitcoin#32620

@DrahtBot
Copy link
Contributor

DrahtBot commented May 26, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
Stale ACK pablomartin4btc

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed.
Task ARM, unit tests, no functional tests: https://github.com/bitcoin-core/gui/runs/42923129558
LLM reason (✨ experimental): The CI failure is caused by a compilation error in bitcoingui.cpp due to incorrect usage of the Qt connect() function.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@Krellan
Copy link
Contributor

Krellan commented May 27, 2025

Good idea. I had this happen to me just recently. I encountered a Catch-22: couldn't restore an old wallet file because it wasn't in a currently recognized format (it told me to use the migrate wallet option instead), but I also couldn't access the wallet in the migrate menu because it hadn't successfully been loaded yet!

I tried manually copying the wallet.dat file into a new directory created in my Bitcoin datadir, but that just produced an error at startup saying the wallet was not in a recognized format. So, it's clear we need an all-in-one "restore the old wallet.dat file AND migrate it simultaneously" feature.

@luke-jr
Copy link
Member

luke-jr commented May 27, 2025

by adding a menu item in the "Migrate Wallet" menu

IMO this is bad UX. Users will be looking to restore the wallet, and the details of how it does that shouldn't require unintuitive steps.

@achow101
Copy link
Member Author

IMO this is bad UX. Users will be looking to restore the wallet, and the details of how it does that shouldn't require unintuitive steps.

While it is an extra click, I don't think it is unintuitive.

When the user goes to restore a legacy wallet, they will be informed that the restore failed and that they will need to migrate the wallet via the corresponding menu. When the user goes there, this option to restore and migrate will be presented to them.

@achow101 achow101 force-pushed the gui-migrate-path branch from 7c0bb7f to 56407ca Compare June 4, 2025 23:56
@liamperfil
Copy link

I support the proposal, but I also consider that this extra click is a bad experience for the user. The ideal would be to directly integrate this functionality to automatically detect if it is a legacy wallet and offer the migration option in the same flow. If you need someone on your team I am available.

@pablomartin4btc
Copy link
Contributor

couldn't restore an old wallet file because it wasn't in a currently recognized format (it told me to use the migrate wallet option instead),

If you copy the .dat file or the backup file into the wallets dir (default: datadir/wallets) you will see the option in the "Migrate Wallet" menu item (you can check also with bitcoin-cli or the RPC console and if you call listwalletdir would show it in the output).

but I also couldn't access the wallet in the migrate menu because it hadn't successfully been loaded yet!

It's no longer possible to load a legacy wallet on the master branch and future releases, but you don't need to load the wallet in order to migrate it as I explained above, however you could do it in previous versions of QT or bircoind (v29 or earlier).

I tried manually copying the wallet.dat file into a new directory created in my Bitcoin datadir, but that just produced an error at startup saying the wallet was not in a recognized format.

Just tried and it works, if you launched QT with a test chain you need to add that into the path (eg if you used -regtest, the wallets dir path would be /datadir/regtest/wallets).

Copy link
Contributor

@pablomartin4btc pablomartin4btc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 56407ca

I'll try to review the code later (first commit is not longer needed, perhaps rebase?).

Regarding the approach IMHO:

integrate this functionality to automatically detect if it is a legacy wallet and offer the migration option in the same flow.

I thought the same at first glance as an additional to the current PR logic, if the user knows that has the backup to restore maybe goes directly there first.

I'd update the menu item title to "Wallet file...", since you could restore a .dat file or migrate a backup file directly - checked with CLI.

Perhaps @GBKS could add his view here...

image

achow101 added 4 commits June 20, 2025 13:56
RestoreWallet has a load_after_restore parameter, expose this to callers
using it through the wallet interface as well.
We will need to use the same migration code in a later commit, so first
move it to a separate function.
restore_and_migrate first restores a wallet file to the wallets
directory in the expected layout, then it performs legacy to descriptor
wallet migration on the restored wallet.
Some users will have backups of a legacy wallet which cannot be restored
due to being a legacy wallet, and therefore cannot be migrated from the
GUI. This menu item allows such users to restore and migrate their
wallets in a single action.
@achow101 achow101 marked this pull request as ready for review June 20, 2025 20:56
@achow101
Copy link
Member Author

Rebased and ready for review

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.

6 participants