Skip to content

Commit fa1b7cd

Browse files
committed
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.
1 parent 440ea1a commit fa1b7cd

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,21 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
19281928

19291929
// InferDescriptor as that will get us all the solving info if it is there
19301930
std::unique_ptr<Descriptor> desc = InferDescriptor(spk, *GetSolvingProvider(spk));
1931+
1932+
// Past bugs in InferDescriptor have caused it to create descriptors which cannot be re-parsed.
1933+
// Re-parse the descriptors to detect that, and skip any that do not parse.
1934+
{
1935+
std::string desc_str = desc->ToString();
1936+
FlatSigningProvider parsed_keys;
1937+
std::string parse_error;
1938+
std::vector<std::unique_ptr<Descriptor>> parsed_descs = Parse(desc_str, parsed_keys, parse_error);
1939+
if (parsed_descs.empty()) {
1940+
// Remove this scriptPubKey from the set
1941+
it = spks.erase(it);
1942+
continue;
1943+
}
1944+
}
1945+
19311946
// Get the private keys for this descriptor
19321947
std::vector<CScript> scripts;
19331948
FlatSigningProvider keys;

0 commit comments

Comments
 (0)