Skip to content

Commit 475c20a

Browse files
committed
wallet: remove coin control arg from AutomaticCoinSelection
we only need the "include unsafe" flag, not all what coin control stores.
1 parent 8a55831 commit 475c20a

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/wallet/coinselection.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ struct CoinSelectionParams {
153153
* associated with the same address. This helps reduce privacy leaks resulting from address
154154
* reuse. Dust outputs are not eligible to be added to output groups and thus not considered. */
155155
bool m_avoid_partial_spends = false;
156+
/**
157+
* When true, allow unsafe coins to be selected during Coin Selection. This may spend unconfirmed outputs:
158+
* 1) Received from other wallets, 2) replacing other txs, 3) that have been replaced.
159+
*/
160+
bool m_include_unsafe_inputs = false;
156161

157162
CoinSelectionParams(FastRandomContext& rng_fast, size_t change_output_size, size_t change_spend_size,
158163
CAmount min_change_target, CFeeRate effective_feerate,

src/wallet/spend.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ util::Result<SelectionResult> SelectCoins(const CWallet& wallet, CoinsResult& av
617617
}
618618

619619
// Start wallet Coin Selection procedure
620-
auto op_selection_result = AutomaticCoinSelection(wallet, available_coins, selection_target, coin_control, coin_selection_params);
620+
auto op_selection_result = AutomaticCoinSelection(wallet, available_coins, selection_target, coin_selection_params);
621621
if (!op_selection_result) return op_selection_result;
622622

623623
// If needed, add preset inputs to the automatic coin selection result
@@ -632,7 +632,7 @@ util::Result<SelectionResult> SelectCoins(const CWallet& wallet, CoinsResult& av
632632
return op_selection_result;
633633
}
634634

635-
util::Result<SelectionResult> AutomaticCoinSelection(const CWallet& wallet, CoinsResult& available_coins, const CAmount& value_to_select, const CCoinControl& coin_control, const CoinSelectionParams& coin_selection_params)
635+
util::Result<SelectionResult> AutomaticCoinSelection(const CWallet& wallet, CoinsResult& available_coins, const CAmount& value_to_select, const CoinSelectionParams& coin_selection_params)
636636
{
637637
unsigned int limit_ancestor_count = 0;
638638
unsigned int limit_descendant_count = 0;
@@ -641,12 +641,10 @@ util::Result<SelectionResult> AutomaticCoinSelection(const CWallet& wallet, Coin
641641
const size_t max_descendants = (size_t)std::max<int64_t>(1, limit_descendant_count);
642642
const bool fRejectLongChains = gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS);
643643

644-
// form groups from remaining coins; note that preset coins will not
645-
// automatically have their associated (same address) coins included
646-
if (coin_control.m_avoid_partial_spends && available_coins.Size() > OUTPUT_GROUP_MAX_ENTRIES) {
647-
// Cases where we have 101+ outputs all pointing to the same destination may result in
648-
// privacy leaks as they will potentially be deterministically sorted. We solve that by
649-
// explicitly shuffling the outputs before processing
644+
// Cases where we have 101+ outputs all pointing to the same destination may result in
645+
// privacy leaks as they will potentially be deterministically sorted. We solve that by
646+
// explicitly shuffling the outputs before processing
647+
if (coin_selection_params.m_avoid_partial_spends && available_coins.Size() > OUTPUT_GROUP_MAX_ENTRIES) {
650648
available_coins.Shuffle(coin_selection_params.rng_fast);
651649
}
652650

@@ -673,7 +671,7 @@ util::Result<SelectionResult> AutomaticCoinSelection(const CWallet& wallet, Coin
673671
ordered_filters.push_back({CoinEligibilityFilter(0, 1, max_ancestors-1, max_descendants-1, /*include_partial=*/true)});
674672
// Try with unsafe inputs if they are allowed. This may spend unconfirmed outputs
675673
// received from other wallets.
676-
if (coin_control.m_include_unsafe_inputs) {
674+
if (coin_selection_params.m_include_unsafe_inputs) {
677675
ordered_filters.push_back({CoinEligibilityFilter(/*conf_mine=*/0, /*conf_theirs*/0, max_ancestors-1, max_descendants-1, /*include_partial=*/true)});
678676
}
679677
// Try with unlimited ancestors/descendants. The transaction will still need to meet
@@ -804,6 +802,7 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
804802

805803
CoinSelectionParams coin_selection_params{rng_fast}; // Parameters for coin selection, init with dummy
806804
coin_selection_params.m_avoid_partial_spends = coin_control.m_avoid_partial_spends;
805+
coin_selection_params.m_include_unsafe_inputs = coin_control.m_include_unsafe_inputs;
807806

808807
// Set the long term feerate estimate to the wallet's consolidate feerate
809808
coin_selection_params.m_long_term_feerate = wallet.m_consolidate_feerate;

src/wallet/spend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ util::Result<PreSelectedInputs> FetchSelectedInputs(const CWallet& wallet, const
191191
* or (2) an specific error message if there was something particularly wrong (e.g. a selection
192192
* result that surpassed the tx max weight size).
193193
*/
194-
util::Result<SelectionResult> AutomaticCoinSelection(const CWallet& wallet, CoinsResult& available_coins, const CAmount& nTargetValue, const CCoinControl& coin_control,
194+
util::Result<SelectionResult> AutomaticCoinSelection(const CWallet& wallet, CoinsResult& available_coins, const CAmount& nTargetValue,
195195
const CoinSelectionParams& coin_selection_params) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
196196

197197
/**

0 commit comments

Comments
 (0)