migration: Skip descriptors which do not parse

InferDescriptors can sometimes make descriptors which are actually
invalid and cannot be parsed. Detect and skip such descriptors by doing
a Parse() check before adding the descriptor to the wallet.
This commit is contained in:
Ava Chow 2024-12-13 14:45:32 -05:00
parent cb98957dd5
commit 0f0ce579ff

View file

@ -1925,6 +1925,19 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
// InferDescriptor as that will get us all the solving info if it is there
std::unique_ptr<Descriptor> desc = InferDescriptor(spk, *GetSolvingProvider(spk));
// Past bugs in InferDescriptor has caused it to create descriptors which cannot be re-parsed
// Re-parse the descriptors to detect that, and skip any that do not parse.
{
std::string desc_str = desc->ToString();
FlatSigningProvider parsed_keys;
std::string parse_error;
std::vector<std::unique_ptr<Descriptor>> parsed_descs = Parse(desc_str, parsed_keys, parse_error, false);
if (parsed_descs.empty()) {
continue;
}
}
// Get the private keys for this descriptor
std::vector<CScript> scripts;
FlatSigningProvider keys;