Skip to content

Commit

Permalink
opt: Tie-break UTXO sort by waste for BnB
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
murchandamus committed Jan 15, 2024
1 parent aaee658 commit 89d0956
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/wallet/coinselection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 89d0956

Please sign in to comment.