Skip to content

Commit

Permalink
fixup! opt: Skip over barren combinations of tiny UTXOs
Browse files Browse the repository at this point in the history
  • Loading branch information
murchandamus committed Jan 9, 2024
1 parent 6327cd7 commit 0f812ed
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/wallet/coinselection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,10 @@ util::Result<SelectionResult> CoinGrinder(std::vector<OutputGroup>& 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;
}

Expand Down

0 comments on commit 0f812ed

Please sign in to comment.