From 0a8fc9e200b5018c1efd6f9126eb405ca0beeea3 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Fri, 12 Aug 2022 11:19:25 +0200 Subject: [PATCH] wallet: check solvability using descriptor in AvailableCoins This is a workaround for Miniscript descriptors containing hash challenges. For those we can't mock the signature creator without making OP_EQUAL mockable in the interpreter, so CalculateMaximumInputSize will always return -1 and outputs for these descriptors would appear unsolvable while they actually are. --- src/wallet/spend.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 8c0d56a1cb..565c54d962 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -294,9 +294,7 @@ CoinsResult AvailableCoins(const CWallet& wallet, std::unique_ptr provider = wallet.GetSolvingProvider(output.scriptPubKey); int input_bytes = CalculateMaximumSignedInputSize(output, COutPoint(), provider.get(), coinControl); - // Because CalculateMaximumSignedInputSize just uses ProduceSignature and makes a dummy signature, - // it is safe to assume that this input is solvable if input_bytes is greater -1. - bool solvable = input_bytes > -1; + bool solvable = provider ? InferDescriptor(output.scriptPubKey, *provider)->IsSolvable() : false; bool spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable)); // Filter by spendable outputs only