From 25749f1df77c78eb146978ca0485cf9f91b5ce49 Mon Sep 17 00:00:00 2001 From: furszy Date: Wed, 11 May 2022 11:39:54 -0300 Subject: [PATCH] =?UTF-8?q?wallet:=20unify=20=E2=80=9Callow/block=20other?= =?UTF-8?q?=20inputs=E2=80=9C=20concept?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Seeking to make the `CoinControl` option less confusing/redundant. In #16377 the `CoinControl` flag ‘m_add_inputs’ was added to tell the coin filtering and selection process two things: - Coin Filtering: Only use the provided inputs. Skip the Rest. - Coin Selection: Search the wtxs-outputs and append all the `CoinControl` selected outpoints to the selection result (skipping all the available output checks). Nothing else. Meanwhile, in `CoinControl` we already have a flag ‘fAllowOtherInputs’ which is already saying: - Coin Filtering: Only use the provided inputs. Skip the Rest. - Coin Selection: If false, no selection process -> append all the `CoinControl` selected outpoints to the selection result (while they passed all the `AvailableCoins` checks and are available in the 'vCoins' vector). As can notice, the first point in the coin filtering process is duplicated in the two option flags. And the second one, is slightly different merely because it takes into account whether the coin is on the `AvailableCoins` vector or not. So it makes sense to merge ‘m_add_inputs’ and ‘fAllowOtherInputs’ into a single field for the coin filtering process while introduce other changes to add the missing/skipped coins into 'vCoins' vector if they were manually selected by the user (follow-up commits). --- src/wallet/coincontrol.h | 5 ++--- src/wallet/rpc/spend.cpp | 10 +++++----- src/wallet/spend.cpp | 7 ------- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/wallet/coincontrol.h b/src/wallet/coincontrol.h index 65a5c83366f..e9687de14de 100644 --- a/src/wallet/coincontrol.h +++ b/src/wallet/coincontrol.h @@ -33,11 +33,10 @@ public: CTxDestination destChange = CNoDestination(); //! Override the default change type if set, ignored if destChange is set std::optional m_change_type; - //! If false, only selected inputs are used - bool m_add_inputs = true; //! If false, only safe inputs will be used bool m_include_unsafe_inputs = false; - //! If false, allows unselected inputs, but requires all selected inputs be used + //! If true, the selection process can add extra unselected inputs from the wallet + //! while requires all selected inputs be used bool fAllowOtherInputs = false; //! Includes watch only addresses which are solvable bool fAllowWatchOnly = false; diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp index e2ea2b691db..0aaa3c2ac37 100644 --- a/src/wallet/rpc/spend.cpp +++ b/src/wallet/rpc/spend.cpp @@ -535,8 +535,8 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out, }, true, true); - if (options.exists("add_inputs") ) { - coinControl.m_add_inputs = options["add_inputs"].get_bool(); + if (options.exists("add_inputs")) { + coinControl.fAllowOtherInputs = options["add_inputs"].get_bool(); } if (options.exists("changeAddress") || options.exists("change_address")) { @@ -823,7 +823,7 @@ RPCHelpMan fundrawtransaction() int change_position; CCoinControl coin_control; // Automatically select (additional) coins. Can be overridden by options.add_inputs. - coin_control.m_add_inputs = true; + coin_control.fAllowOtherInputs = true; FundTransaction(*pwallet, tx, fee, change_position, request.params[1], coin_control, /*override_min_fee=*/true); UniValue result(UniValue::VOBJ); @@ -1225,7 +1225,7 @@ RPCHelpMan send() CCoinControl coin_control; // Automatically select coins, unless at least one is manually selected. Can // be overridden by options.add_inputs. - coin_control.m_add_inputs = rawTx.vin.size() == 0; + coin_control.fAllowOtherInputs = rawTx.vin.size() == 0; SetOptionsInputWeights(options["inputs"], options); FundTransaction(*pwallet, rawTx, fee, change_position, options, coin_control, /*override_min_fee=*/false); @@ -1649,7 +1649,7 @@ RPCHelpMan walletcreatefundedpsbt() CCoinControl coin_control; // Automatically select coins, unless at least one is manually selected. Can // be overridden by options.add_inputs. - coin_control.m_add_inputs = rawTx.vin.size() == 0; + coin_control.fAllowOtherInputs = rawTx.vin.size() == 0; SetOptionsInputWeights(request.params[0], options); FundTransaction(wallet, rawTx, fee, change_position, options, coin_control, /*override_min_fee=*/true); diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 4547dc41334..693158fafbd 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -168,11 +168,6 @@ CoinsResult AvailableCoins(const CWallet& wallet, const CTxOut& output = wtx.tx->vout[i]; const COutPoint outpoint(wtxid, i); - // Only consider selected coins if add_inputs is false - if (coinControl && !coinControl->m_add_inputs && !coinControl->IsSelected(outpoint)) { - continue; - } - if (output.nValue < nMinimumAmount || output.nValue > nMaximumAmount) continue; @@ -1033,8 +1028,6 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet, vecSend.push_back(recipient); } - coinControl.fAllowOtherInputs = true; - // Acquire the locks to prevent races to the new locked unspents between the // CreateTransaction call and LockCoin calls (when lockUnspents is true). LOCK(wallet.cs_wallet);