Skip to content

Commit 932cd1e

Browse files
committed
wallet: fix crash during watch-only wallet migration
The crash occurs because we assume the cached scripts structure will not be empty, but it can be empty when the legacy wallet contained only watch-only and solvable but not spendable scripts
1 parent 22723c8 commit 932cd1e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4085,7 +4085,11 @@ util::Result<void> CWallet::ApplyMigrationData(WalletBatch& local_wallet_batch,
40854085
if (ExtractDestination(script, dest)) not_migrated_dests.emplace(dest);
40864086
}
40874087

4088-
Assume(!m_cached_spks.empty());
4088+
// When the legacy wallet has no spendable scripts, the main wallet will be empty, leaving its script cache empty as well.
4089+
// The watch-only and/or solvable wallet(s) will contain the scripts in their respective caches.
4090+
if (!data.desc_spkms.empty()) Assume(!m_cached_spks.empty());
4091+
if (!data.watch_descs.empty()) Assume(!data.watchonly_wallet->m_cached_spks.empty());
4092+
if (!data.solvable_descs.empty()) Assume(!data.solvable_wallet->m_cached_spks.empty());
40894093

40904094
for (auto& desc_spkm : data.desc_spkms) {
40914095
if (m_spk_managers.count(desc_spkm->GetID()) > 0) {

0 commit comments

Comments
 (0)