Skip to content

Commit fdd363e

Browse files
committed
Merge bitcoin/bitcoin#26910: wallet: migrate wallet, exit early if no legacy data exist
6d31900 wallet: migrate wallet, exit early if no legacy data exist (furszy) Pull request description: The process first creates a backup file then return an error, without removing the recently created file, when notices that the db is already running sqlite. ACKs for top commit: john-moffett: ACK 6d31900 achow101: ACK 6d31900 ishaanam: crACK 6d31900 Tree-SHA512: 9fb52e80de96e129487ab91bef13647bc4570a782003b1e37940e2a00ca26283fd24ad39bdb63a984ae0a56140b518fd0d74aa2fc59ab04405b2c179b7d3c54a
2 parents 2d5acc9 + 6d31900 commit fdd363e

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
@@ -3871,10 +3871,7 @@ std::optional<MigrationData> CWallet::GetDescriptorsForLegacy(bilingual_str& err
38713871
AssertLockHeld(cs_wallet);
38723872

38733873
LegacyScriptPubKeyMan* legacy_spkm = GetLegacyScriptPubKeyMan();
3874-
if (!legacy_spkm) {
3875-
error = _("Error: This wallet is already a descriptor wallet");
3876-
return std::nullopt;
3877-
}
3874+
assert(legacy_spkm);
38783875

38793876
std::optional<MigrationData> res = legacy_spkm->MigrateToDescriptor();
38803877
if (res == std::nullopt) {
@@ -4170,6 +4167,11 @@ bool DoMigration(CWallet& wallet, WalletContext& context, bilingual_str& error,
41704167

41714168
util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>&& wallet, WalletContext& context)
41724169
{
4170+
// Before anything else, check if there is something to migrate.
4171+
if (!wallet->GetLegacyScriptPubKeyMan()) {
4172+
return util::Error{_("Error: This wallet is already a descriptor wallet")};
4173+
}
4174+
41734175
MigrationResult res;
41744176
bilingual_str error;
41754177
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)