rpc, wallet: add an option to not load the wallet after migrating#35266
rpc, wallet: add an option to not load the wallet after migrating#35266polespinasa wants to merge 3 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35266. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, 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. |
|
Concept ACK. |
eca9cfe to
94d8334
Compare
94d8334 to
525b30d
Compare
| if (load_wallet) { | ||
| wallet = LoadWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error, warnings); |
There was a problem hiding this comment.
In 6d3916f "rpc, wallet: add option to not load the wallet after migration"
For watchonly_wallet and solvables_wallet, without loading those wallets, we lose the output to the user that those wallets were created. MigrationResult should be updated to include the watchonly and solvables wallets names so we can return that info to the user when those wallets are not being loaded.
There was a problem hiding this comment.
We only lose that output when not loading the wallet? I mean is it something this PR broke?
There was a problem hiding this comment.
When those wallets are not loaded, we no longer inform the user that those wallets have been created in the RPC result. But we should still do that, so MigrationResult should have fields for those wallet names.
525b30d to
d77b45e
Compare
This comment was marked as resolved.
This comment was marked as resolved.
After migrating from legacy wallet to a descriptor based wallet the wallet is loaded into the node by default. This commit adds an RPC argumment to disable wallet loading.
d77b45e to
4f9002b
Compare
|
The current code fails when migration creates watchonly and/or solvables wallets. This happens in the post-migration loop inside for (std::shared_ptr<CWallet>* wallet_ptr : {&local_wallet, &res.watchonly_wallet, &res.solvables_wallet}) { ... }Inside the loop, the wallet pointer is reset before the optional reload: wallet.reset();When if (!res.wallet) {
res.wallet_name = wallet_name;
}Because The same no-load path also clears Test: diff --git a/test/functional/wallet_migration.py b/test/functional/wallet_migration.py
index 48ae1fb051..78730aa3fe 100755
--- a/test/functional/wallet_migration.py
+++ b/test/functional/wallet_migration.py
@@ -1537,6 +1537,27 @@ class WalletMigrationTest(BitcoinTestFramework):
assert_equal(loaded_wallet.getbalance(), bals["mine"]["trusted"])
loaded_wallet.unloadwallet()
+ def test_no_load_reports_auxiliary_wallet_names(self):
+ self.log.info("Test no-load migration reports auxiliary wallet names")
+ wallet_name = "no_load_auxiliary_names"
+ wallet = self.create_legacy_wallet(wallet_name)
+
+ wallet.importaddress(address=self.master_node.get_wallet_rpc(self.default_wallet_name).getnewaddress(), rescan=False)
+ _, pubkey = generate_keypair(compressed=True, wif=True)
+ wallet.addmultisigaddress(nrequired=1, keys=[pubkey.hex()])
+
+ self.old_node.unloadwallet(wallet_name)
+ shutil.copytree(self.old_node.wallets_path / wallet_name, self.master_node.wallets_path / wallet_name)
+
+ migrate_info = self.master_node.migratewallet(wallet_name=wallet_name, load_wallet=False)
+
+ assert_equal(migrate_info["wallet_name"], wallet_name)
+ assert_equal(migrate_info["watchonly_name"], f"{wallet_name}_watchonly")
+ assert_equal(migrate_info["solvables_name"], f"{wallet_name}_solvables")
+ assert wallet_name not in self.master_node.listwallets()
+ assert f"{wallet_name}_watchonly" not in self.master_node.listwallets()
+ assert f"{wallet_name}_solvables" not in self.master_node.listwallets()
+
def test_solvable_no_privs(self):
self.log.info("Test migrating a multisig that we do not have any private keys for")
wallet = self.create_legacy_wallet("multisig_noprivs")
@@ -1669,6 +1690,7 @@ class WalletMigrationTest(BitcoinTestFramework):
self.test_miniscript()
self.test_taproot()
self.test_no_load_after_migration()
+ self.test_no_load_reports_auxiliary_wallet_names()
self.test_solvable_no_privs()
self.test_loading_failure_after_migration() |
This PR is motivated by this Stack Exchange question.
Long story short, someone who has a node pruned before his legacy wallet birthday, is unable to migrate the wallet as it is not possible to load it.
Loading is not necessary for migration, and migrating without wanting to use the wallet in that node is a valid use-case.
This PR adds a new RPC argument to
migratewalletthat allow the user disabling the wallet loading.Second commits adds tests for it.