Skip to content

Commit 6d31900

Browse files
committed
wallet: migrate wallet, exit early if no legacy data exist
otherwise the process will create a backup file then return an error when notices that the db is already running sqlite.
1 parent 635f190 commit 6d31900

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/wallet/wallet.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3839,10 +3839,7 @@ std::optional<MigrationData> CWallet::GetDescriptorsForLegacy(bilingual_str& err
38393839
AssertLockHeld(cs_wallet);
38403840

38413841
LegacyScriptPubKeyMan* legacy_spkm = GetLegacyScriptPubKeyMan();
3842-
if (!legacy_spkm) {
3843-
error = _("Error: This wallet is already a descriptor wallet");
3844-
return std::nullopt;
3845-
}
3842+
assert(legacy_spkm);
38463843

38473844
std::optional<MigrationData> res = legacy_spkm->MigrateToDescriptor();
38483845
if (res == std::nullopt) {
@@ -4138,6 +4135,11 @@ bool DoMigration(CWallet& wallet, WalletContext& context, bilingual_str& error,
41384135

41394136
util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>&& wallet, WalletContext& context)
41404137
{
4138+
// Before anything else, check if there is something to migrate.
4139+
if (!wallet->GetLegacyScriptPubKeyMan()) {
4140+
return util::Error{_("Error: This wallet is already a descriptor wallet")};
4141+
}
4142+
41414143
MigrationResult res;
41424144
bilingual_str error;
41434145
std::vector<bilingual_str> warnings;

test/functional/wallet_migration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ def test_basic(self):
163163
assert_equal(basic2.getbalance(), basic2_balance)
164164
self.assert_list_txs_equal(basic2.listtransactions(), basic2_txs)
165165

166+
# Now test migration on a descriptor wallet
167+
self.log.info("Test \"nothing to migrate\" when the user tries to migrate a wallet with no legacy data")
168+
assert_raises_rpc_error(-4, "Error: This wallet is already a descriptor wallet", basic2.migratewallet)
169+
166170
def test_multisig(self):
167171
default = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
168172

0 commit comments

Comments
 (0)