aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/coinselection.cpp
diff options
context:
space:
mode:
authorMurch <murch@murch.one>2023-06-13 15:56:18 -0400
committerMurch <murch@murch.one>2024-01-15 09:08:01 -0500
commit89d09566431f57034d9a7df32547ceb13d79c62c (patch)
treebb1c6b35ba9652f1f1005a93311254beda30dc03 /src/wallet/coinselection.cpp
parentaaee65823c6e620bef5cc96d8026567e64d822fe (diff)
downloadbitcoin-89d09566431f57034d9a7df32547ceb13d79c62c.tar.xz
opt: Tie-break UTXO sort by waste for BnB
Since we are searching for the minimal waste, we sort UTXOs with equal effective value by ascending waste to be able to cut barren branches earlier.
Diffstat (limited to 'src/wallet/coinselection.cpp')
-rw-r--r--src/wallet/coinselection.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp
index 7d15a9997a..570fac6900 100644
--- a/src/wallet/coinselection.cpp
+++ b/src/wallet/coinselection.cpp
@@ -25,10 +25,14 @@ static util::Result<SelectionResult> ErrorMaxWeightExceeded()
"Please try sending a smaller amount or manually consolidating your wallet's UTXOs")};
}
-// Descending order comparator
+// Sort by descending (effective) value prefer lower waste on tie
struct {
bool operator()(const OutputGroup& a, const OutputGroup& b) const
{
+ if (a.GetSelectionAmount() == b.GetSelectionAmount()) {
+ // Lower waste is better when effective_values are tied
+ return (a.fee - a.long_term_fee) < (b.fee - b.long_term_fee);
+ }
return a.GetSelectionAmount() > b.GetSelectionAmount();
}
} descending;