From 0f0ce579fffe533534dc117c854ebef3f277f18e 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index c4e31ebc851..a4420c4ddeb 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -1925,6 +1925,19 @@ 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 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> parsed_descs = Parse(desc_str, parsed_keys, parse_error, false); + if (parsed_descs.empty()) { + continue; + } + } + // Get the private keys for this descriptor std::vector scripts; FlatSigningProvider keys;