From 8a105ecd1aeff15f84c3883e2762bf71ad59d920 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 28 Mar 2022 15:39:25 -0400 Subject: [PATCH] wallet: Use CalculateMaximumSignedInputSize to indicate solvability In AvailableCoins, we need to know whether we can solve for an output. This was done by using IsSolvable, which just calls ProduceSignature and produces a dummy signature. However, we already do that in order to get the size of the input by using CalculateMaximumSignedInputSize. As this function returns -1 if ProduceSignature fails, we can just remove the use of IsSolvable and check that input_bytes is not -1 to determine the solvability of an output. --- src/wallet/spend.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index c00a2cd0231..cacefffe35c 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -213,7 +213,10 @@ CoinsResult AvailableCoins(const CWallet& wallet, std::unique_ptr provider = wallet.GetSolvingProvider(output.scriptPubKey); - bool solvable = provider ? IsSolvable(*provider, output.scriptPubKey) : false; + 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 spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable)); // Filter by spendable outputs only @@ -243,7 +246,6 @@ CoinsResult AvailableCoins(const CWallet& wallet, type = Solver(output.scriptPubKey, return_values_unused); } - int input_bytes = CalculateMaximumSignedInputSize(output, COutPoint(), provider.get(), coinControl); COutput coin(outpoint, output, nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me, feerate); switch (type) { case TxoutType::WITNESS_UNKNOWN: