aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2022-12-14 16:06:05 -0500
committerAndrew Chow <github@achow101.com>2022-12-14 16:16:03 -0500
commitba47a4ba97e924fb628849754c78d9cd10841c31 (patch)
tree8f32c927899101a44f6380d46100317cbedde7bd /src/wallet
parent678889e6c6231cf461de59eefe6fb8eb07468848 (diff)
parent89c1491d35389eac0c1fecc59333cdfae3b1bd2c (diff)
downloadbitcoin-ba47a4ba97e924fb628849754c78d9cd10841c31.tar.xz
Merge bitcoin/bitcoin#26668: wallet: if only have one output type, don't perform "mixed" coin selection
89c1491d35389eac0c1fecc59333cdfae3b1bd2c 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 89c1491d35389eac0c1fecc59333cdfae3b1bd2c john-moffett: ACK 89c1491d35389eac0c1fecc59333cdfae3b1bd2c kristapsk: cr utACK 89c1491d35389eac0c1fecc59333cdfae3b1bd2c Tree-SHA512: 672eaeed3ba911d13fa61a46f719c8fe1ebe4d2dc7d723040e71937c693659411bc99cdbd9f0014e836b70eebeff1b8ca861f4d81d39e6f79f437364a526edbe
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/spend.cpp5
-rw-r--r--src/wallet/spend.h2
2 files changed, 5 insertions, 2 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index dd3f0e99d1..33289c1d2f 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -525,8 +525,9 @@ std::optional<SelectionResult> AttemptSelection(const CWallet& wallet, const CAm
if (results.size() > 0) return *std::min_element(results.begin(), results.end());
// If we can't fund the transaction from any individual OutputType, run coin selection one last time
- // over all available coins, which would allow mixing
- if (allow_mixed_output_types) {
+ // over all available coins, which would allow mixing.
+ // If TypesCount() <= 1, there is nothing to mix.
+ if (allow_mixed_output_types && available_coins.TypesCount() > 1) {
if (auto result{ChooseSelectionResult(wallet, nTargetValue, eligibility_filter, available_coins.All(), coin_selection_params)}) {
return result;
}
diff --git a/src/wallet/spend.h b/src/wallet/spend.h
index 2b861c2361..46144d4c92 100644
--- a/src/wallet/spend.h
+++ b/src/wallet/spend.h
@@ -46,6 +46,8 @@ struct CoinsResult {
/** The following methods are provided so that CoinsResult can mimic a vector,
* i.e., methods can work with individual OutputType vectors or on the entire object */
size_t Size() const;
+ /** Return how many different output types this struct stores */
+ size_t TypesCount() const { return coins.size(); }
void Clear();
void Erase(const std::unordered_set<COutPoint, SaltedOutpointHasher>& coins_to_remove);
void Shuffle(FastRandomContext& rng_fast);