Skip to content

Commit

Permalink
wallet: fix crash during watch-only wallet migration
Browse files Browse the repository at this point in the history
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

Github-Pull: bitcoin#31374
Rebased-From: 932cd1e
  • Loading branch information
furszy authored and achow101 committed Dec 11, 2024
1 parent 227642d commit e2c5084
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4064,7 +4064,11 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
if (ExtractDestination(script, dest)) not_migrated_dests.emplace(dest);
}

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

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

0 comments on commit e2c5084

Please sign in to comment.