From fa1b7cd6e2cfd581679d1fb6bc0fabcd6ee6e70a Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Fri, 13 Dec 2024 14:45:32 -0500 Subject: [PATCH] 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. --- src/wallet/scriptpubkeyman.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 504d5db811e..ef96f1cb436 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -1928,6 +1928,21 @@ std::optional LegacyDataSPKM::MigrateToDescriptor() // InferDescriptor as that will get us all the solving info if it is there std::unique_ptr desc = InferDescriptor(spk, *GetSolvingProvider(spk)); + + // Past bugs in InferDescriptor have 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> parsed_descs = Parse(desc_str, parsed_keys, parse_error); + if (parsed_descs.empty()) { + // Remove this scriptPubKey from the set + it = spks.erase(it); + continue; + } + } + // Get the private keys for this descriptor std::vector scripts; FlatSigningProvider keys;