Skip to content

Commit 89c1491

Browse files
committed
wallet: if only have one output type, don't perform "mixed" coin selection
there is nothing to mix.
1 parent 3eaf7be commit 89c1491

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/wallet/spend.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,9 @@ std::optional<SelectionResult> AttemptSelection(const CWallet& wallet, const CAm
524524
if (results.size() > 0) return *std::min_element(results.begin(), results.end());
525525

526526
// If we can't fund the transaction from any individual OutputType, run coin selection one last time
527-
// over all available coins, which would allow mixing
528-
if (allow_mixed_output_types) {
527+
// over all available coins, which would allow mixing.
528+
// If TypesCount() <= 1, there is nothing to mix.
529+
if (allow_mixed_output_types && available_coins.TypesCount() > 1) {
529530
if (auto result{ChooseSelectionResult(wallet, nTargetValue, eligibility_filter, available_coins.All(), coin_selection_params)}) {
530531
return result;
531532
}

src/wallet/spend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct CoinsResult {
4646
/** The following methods are provided so that CoinsResult can mimic a vector,
4747
* i.e., methods can work with individual OutputType vectors or on the entire object */
4848
size_t Size() const;
49+
/** Return how many different output types this struct stores */
50+
size_t TypesCount() const { return coins.size(); }
4951
void Clear();
5052
void Erase(const std::unordered_set<COutPoint, SaltedOutpointHasher>& coins_to_remove);
5153
void Shuffle(FastRandomContext& rng_fast);

0 commit comments

Comments
 (0)