mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-06 19:23:41 +02:00
wallet: disallow migration of invalid or not-watched scripts
The legacy wallet allowed to import any raw script, without checking if it was valid or not. Appending it to the watch-only set. This causes a crash in the migration process because we are only expecting to find valid scripts inside the legacy spkm. These stored scripts internally map to `ISMINE_NO` (same as if they weren't stored at all..). So we need to check for these special case, and take into account that the legacy spkm could be storing invalid not watched scripts. Which, in code words, means IsMineInner() returning IsMineResult::INVALID for them.
This commit is contained in:
@@ -3920,6 +3920,13 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get all invalid or non-watched scripts that will not be migrated
|
||||
std::set<CTxDestination> not_migrated_dests;
|
||||
for (const auto& script : legacy_spkm->GetNotMineScriptPubKeys()) {
|
||||
CTxDestination dest;
|
||||
if (ExtractDestination(script, dest)) not_migrated_dests.emplace(dest);
|
||||
}
|
||||
|
||||
for (auto& desc_spkm : data.desc_spkms) {
|
||||
if (m_spk_managers.count(desc_spkm->GetID()) > 0) {
|
||||
error = _("Error: Duplicate descriptors created during migration. Your wallet may be corrupted.");
|
||||
@@ -4026,6 +4033,13 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Skip invalid/non-watched scripts that will not be migrated
|
||||
if (not_migrated_dests.count(addr_pair.first) > 0) {
|
||||
dests_to_delete.push_back(addr_pair.first);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Not ours, not in watchonly wallet, and not in solvable
|
||||
error = _("Error: Address book data in wallet cannot be identified to belong to migrated wallets");
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user