Skip to content

Commit ba47a4b

Browse files
committed
Merge bitcoin/bitcoin#26668: wallet: if only have one output type, don't perform "mixed" coin selection
89c1491 wallet: if only have one output type, don't perform "mixed" coin selection (furszy) Pull request description: For wallets that only have one output type, we are currently performing the same selection process over the same coins twice. The "mixed coin selection" doesn't add any value to the result (there is nothing to mix if the available coins struct has only one type). ACKs for top commit: achow101: ACK 89c1491 john-moffett: ACK 89c1491 kristapsk: cr utACK 89c1491 Tree-SHA512: 672eaeed3ba911d13fa61a46f719c8fe1ebe4d2dc7d723040e71937c693659411bc99cdbd9f0014e836b70eebeff1b8ca861f4d81d39e6f79f437364a526edbe
2 parents 678889e + 89c1491 commit ba47a4b

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
@@ -525,8 +525,9 @@ std::optional<SelectionResult> AttemptSelection(const CWallet& wallet, const CAm
525525
if (results.size() > 0) return *std::min_element(results.begin(), results.end());
526526

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

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)