mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-06 14:19:59 -05:00
opt: Skip heavier UTXOs with same effective value
When two successive UTXOs differ in weight but match in effective value, we can skip the second if the first is not selected, because all input sets we can generate by swapping out a lighter UTXOs with a heavier UTXO of matching effective value would be strictly worse.
This commit is contained in:
parent
9124c73742
commit
5248e2a60d
1 changed files with 6 additions and 6 deletions
|
@ -479,12 +479,12 @@ util::Result<SelectionResult> CoinGrinder(std::vector<OutputGroup>& utxo_pool, c
|
|||
deselect_last();
|
||||
should_shift = false;
|
||||
|
||||
// After SHIFTing to an omission branch, the `next_utxo` might have the same value and same weight as the
|
||||
// UTXO we just omitted (i.e. it is a "clone"). If so, selecting `next_utxo` would produce an equivalent
|
||||
// selection as one we previously evaluated. In that case, increment `next_utxo` until we find a UTXO with a
|
||||
// differing amount or weight.
|
||||
while (utxo_pool[next_utxo - 1].GetSelectionAmount() == utxo_pool[next_utxo].GetSelectionAmount()
|
||||
&& utxo_pool[next_utxo - 1].m_weight == utxo_pool[next_utxo].m_weight) {
|
||||
// After SHIFTing to an omission branch, the `next_utxo` might have the same effective value as the UTXO we
|
||||
// just omitted. Since lower weight is our tiebreaker on UTXOs with equal effective value for sorting, if it
|
||||
// ties on the effective value, it _must_ have the same weight (i.e. be a "clone" of the prior UTXO) or a
|
||||
// higher weight. If so, selecting `next_utxo` would produce an equivalent or worse selection as one we
|
||||
// previously evaluated. In that case, increment `next_utxo` until we find a UTXO with a differing amount.
|
||||
while (utxo_pool[next_utxo - 1].GetSelectionAmount() == utxo_pool[next_utxo].GetSelectionAmount()) {
|
||||
if (next_utxo >= utxo_pool.size() - 1) {
|
||||
// Reached end of UTXO pool skipping clones: SHIFT instead
|
||||
should_shift = true;
|
||||
|
|
Loading…
Add table
Reference in a new issue