mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-27 07:18:33 +02:00
opt: Skip over barren combinations of tiny UTXOs
Given a lot of small amount UTXOs it is possible that the lookahead indicates sufficient funds, but any combination of them would push us beyond the current best_weight. We can estimate a lower bound for the minimal necessary weight to reach target from the maximal amount and minimal weight in the tail of the UTXO pool: if adding a number of hypothetical UTXOs of this maximum amount and minimum weight would not be able to beat `best_weight`, we can SHIFT to the omission branch, and CUT if the last selected UTXO is not heavier than the minimum weight of the remainder.
This commit is contained in:
@@ -454,6 +454,13 @@ 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 + int64_t{min_tail_weight[curr_tail]} * ((total_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 still possible.
|
||||
if (utxo_pool[curr_tail].m_weight <= min_tail_weight[curr_tail]) {
|
||||
should_cut = true;
|
||||
} else {
|
||||
should_shift = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (curr_try >= TOTAL_TRIES) {
|
||||
|
||||
Reference in New Issue
Block a user