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.
This commit is contained in:
Murch 2023-06-13 15:56:18 -04:00
parent aaee65823c
commit 89d0956643

View file

@ -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;