Skip to content

Commit 8e0e11f

Browse files
furszyjanus
authored andcommitted
wallet: remove coin control arg from AutomaticCoinSelection
we only need the "include unsafe" flag, not all what coin control stores.
1 parent d703b0e commit 8e0e11f

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/wallet/coinselection.h

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

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

src/wallet/spend.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ util::Result<SelectionResult> SelectCoins(const CWallet& wallet, CoinsResult& av
619619
}
620620

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

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

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

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

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

807805
CoinSelectionParams coin_selection_params{rng_fast}; // Parameters for coin selection, init with dummy
808806
coin_selection_params.m_avoid_partial_spends = coin_control.m_avoid_partial_spends;
807+
coin_selection_params.m_include_unsafe_inputs = coin_control.m_include_unsafe_inputs;
809808

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

src/wallet/spend.h

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

192192
/**

0 commit comments

Comments
 (0)