From 0f812ed8bd3298e01669a62c6b8752fe6b24d0fa Mon Sep 17 00:00:00 2001 From: Murch Date: Tue, 9 Jan 2024 10:04:26 -0500 Subject: [PATCH] fixup! opt: Skip over barren combinations of tiny UTXOs --- src/wallet/coinselection.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp index 6235f79a3e5f0..485cbcdc6eed9 100644 --- a/src/wallet/coinselection.cpp +++ b/src/wallet/coinselection.cpp @@ -338,8 +338,10 @@ util::Result CoinGrinder(std::vector& utxo_pool, c best_selection_weight = curr_weight; best_selection_amount = curr_amount; } - } else if (!best_selection.empty() && curr_weight + min_tail_weight[curr_tail] * std::ceil((selection_target + change_target - curr_amount) / utxo_pool[curr_tail].GetSelectionAmount()) > best_selection_weight) { - // Compare minimal tail weight and last selected amount with the amount missing to gauge whether a better weight is still possible. + } else if (!best_selection.empty() // needed to detect when we didn’t find a solution due to exceeding max_weight + && curr_weight + min_tail_weight[curr_tail] * (selection_target + change_target - curr_amount + utxo_pool[curr_tail].GetSelectionAmount() - 1) / utxo_pool[curr_tail].GetSelectionAmount() > best_selection_weight) { + // Compare minimal tail weight and last selected amount with the amount missing to gauge whether a better weight is possible. + // Makes use of `ceil(a/b) = (a + b - 1) / b` should_cut = true; }