@@ -37,6 +37,18 @@ struct {
37
37
}
38
38
} descending;
39
39
40
+ // Sort by descending (effective) value prefer lower weight on tie
41
+ struct {
42
+ bool operator ()(const OutputGroup& a, const OutputGroup& b) const
43
+ {
44
+ if (a.GetSelectionAmount () == b.GetSelectionAmount ()) {
45
+ // Sort lower weight to front on tied effective_value
46
+ return a.m_weight < b.m_weight ;
47
+ }
48
+ return a.GetSelectionAmount () > b.GetSelectionAmount ();
49
+ }
50
+ } descending_effval_weight;
51
+
40
52
/*
41
53
* This is the Branch and Bound Coin Selection algorithm designed by Murch. It searches for an input
42
54
* set that can pay for the spending target and does not exceed the spending target by more than the
@@ -303,7 +315,7 @@ util::Result<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool
303
315
* set in the node.
304
316
*
305
317
* @param std::vector<OutputGroup>& utxo_pool The UTXOs that we are choosing from. These UTXOs will be sorted in
306
- * descending order by effective value, with lower waste preferred as a tie-breaker. (We can think of an output
318
+ * descending order by effective value, with lower weight preferred as a tie-breaker. (We can think of an output
307
319
* group with multiple as a heavier UTXO with the combined amount here.)
308
320
* @param const CAmount& selection_target This is the minimum amount that we need for the transaction without considering change.
309
321
* @param const CAmount& change_target The minimum budget for creating a change output, by which we increase the selection_target.
@@ -312,7 +324,7 @@ util::Result<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool
312
324
*/
313
325
util::Result<SelectionResult> CoinGrinder (std::vector<OutputGroup>& utxo_pool, const CAmount& selection_target, CAmount change_target, int max_weight)
314
326
{
315
- std::sort (utxo_pool.begin (), utxo_pool.end (), descending );
327
+ std::sort (utxo_pool.begin (), utxo_pool.end (), descending_effval_weight );
316
328
// The sum of UTXO amounts after this UTXO index, e.g. lookahead[5] = Σ(UTXO[6+].amount)
317
329
std::vector<CAmount> lookahead (utxo_pool.size ());
318
330
0 commit comments