Skip to content

Commit 0f602c5

Browse files
wallet, migration: Fix crash on empty wallet
Same as with a blank wallet, wallets with no legacy records (i.e. empty, non-blank, watch-only wallet) do not require to be migrated.
1 parent 42c1314 commit 0f602c5

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/wallet/wallet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4534,13 +4534,13 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
45344534
// First change to using SQLite
45354535
if (!local_wallet->MigrateToSQLite(error)) return util::Error{error};
45364536

4537-
// Do the migration of keys and scripts for non-blank wallets, and cleanup if it fails
4538-
success = local_wallet->IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET);
4539-
if (!success) {
4537+
// Do the migration of keys and scripts for non-empty wallets, and cleanup if it fails
4538+
if (HasLegacyRecords(*local_wallet)) {
45404539
success = DoMigration(*local_wallet, context, error, res);
45414540
} else {
45424541
// Make sure that descriptors flag is actually set
45434542
local_wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
4543+
success = true;
45444544
}
45454545
}
45464546

test/functional/wallet_migration.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,15 @@ def test_no_privkeys(self):
445445
# After migrating, the "keypool" is empty
446446
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", watchonly1.getnewaddress)
447447

448+
self.log.info("Test migration of a watch-only empty wallet")
449+
for idx, is_blank in enumerate([True, False], start=1):
450+
wallet_name = f"watchonly_empty{idx}"
451+
self.create_legacy_wallet(wallet_name, disable_private_keys=True, blank=is_blank)
452+
_, watchonly_empty = self.migrate_and_get_rpc(wallet_name)
453+
info = watchonly_empty.getwalletinfo()
454+
assert_equal(info["private_keys_enabled"], False)
455+
assert_equal(info["blank"], is_blank)
456+
448457
def test_pk_coinbases(self):
449458
self.log.info("Test migration of a wallet using old pk() coinbases")
450459
wallet = self.create_legacy_wallet("pkcb")

0 commit comments

Comments
 (0)