Skip to content

Commit 89d0956

Browse files
committed
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.
1 parent aaee658 commit 89d0956

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/wallet/coinselection.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ static util::Result<SelectionResult> ErrorMaxWeightExceeded()
2525
"Please try sending a smaller amount or manually consolidating your wallet's UTXOs")};
2626
}
2727

28-
// Descending order comparator
28+
// Sort by descending (effective) value prefer lower waste on tie
2929
struct {
3030
bool operator()(const OutputGroup& a, const OutputGroup& b) const
3131
{
32+
if (a.GetSelectionAmount() == b.GetSelectionAmount()) {
33+
// Lower waste is better when effective_values are tied
34+
return (a.fee - a.long_term_fee) < (b.fee - b.long_term_fee);
35+
}
3236
return a.GetSelectionAmount() > b.GetSelectionAmount();
3337
}
3438
} descending;

0 commit comments

Comments
 (0)