Skip to content

Commit

Permalink
fixup! opt: Skip evaluation of equivalent input sets
Browse files Browse the repository at this point in the history
  • Loading branch information
murchandamus committed Jan 9, 2024
1 parent 4e67f3d commit 6327cd7
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/wallet/coinselection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,35 +365,31 @@ util::Result<SelectionResult> CoinGrinder(std::vector<OutputGroup>& utxo_pool, c
}

while (!is_done && should_shift) {
if (should_shift) {
// Set `next_utxo` to one after last selected, then deselect last selected UTXO
if (curr_selection.empty()) {
// Exhausted search space before running into attempt limit
is_done = true;
result.SetSelectionsEvaluated(curr_try);
result.SetAlgoCompleted(true);
break;
}
next_utxo = curr_selection.back() + 1;
deselect_last();
should_shift = false;
// Set `next_utxo` to one after last selected, then deselect last selected UTXO
if (curr_selection.empty()) {
// Exhausted search space before running into attempt limit
is_done = true;
result.SetSelectionsEvaluated(curr_try);
result.SetAlgoCompleted(true);
break;
}
next_utxo = curr_selection.back() + 1;
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 (!should_shift && next_utxo > 0
&& (curr_selection.empty() || curr_selection.back() != next_utxo - 1)
&& utxo_pool[next_utxo - 1].GetSelectionAmount() == utxo_pool[next_utxo].GetSelectionAmount()
while (utxo_pool[next_utxo - 1].GetSelectionAmount() == utxo_pool[next_utxo].GetSelectionAmount()
&& utxo_pool[next_utxo - 1].fee == utxo_pool[next_utxo].fee) {
if (next_utxo < utxo_pool.size() - 1) {
// Skip clone: previous UTXO is equivalent and unselected
++next_utxo;
} else {
if (next_utxo >= utxo_pool.size() - 1) {
// Reached end of UTXO pool skipping clones: SHIFT instead
should_shift = true;
break;
}
// Skip clone: previous UTXO is equivalent and unselected
++next_utxo;
}
}
}
Expand Down

0 comments on commit 6327cd7

Please sign in to comment.