Skip to content

Commit

Permalink
Split exit conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
murchandamus committed Jan 4, 2024
1 parent 195fe2d commit b83d126
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/wallet/coinselection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ util::Result<SelectionResult> CoinGrinder(std::vector<OutputGroup>& utxo_pool, c
best_selection_amount = curr_amount;
}
}
if (curr_try >= TOTAL_TRIES) {
// Solution is not guaranteed to be optimal if `curr_try` hit TOTAL_TRIES
result.SetAlgoCompleted(false);
break;
}
if (next_utxo == utxo_pool.size()) {
// Reached end of UTXO pool, nothing left to add: CUT
should_cut = true;
Expand All @@ -334,23 +339,20 @@ util::Result<SelectionResult> CoinGrinder(std::vector<OutputGroup>& utxo_pool, c
should_shift = true;
should_cut = false;
}


if (should_shift) {
// Set `next_utxo` to one after last selected, deselect last selected UTXO, fallthrough to ADD
// Set `next_utxo` to one after last selected, deselect last selected UTXO
if (curr_selection.empty()) {
is_done = true;
result.SetAlgoCompleted(is_done);
// Exhausted search space before running into limit
result.SetAlgoCompleted(true);
break;
}
next_utxo = curr_selection.back() + 1;
deselect_last();
should_shift = false;
}

if (curr_try >= TOTAL_TRIES || is_done) {
// Solution is not guaranteed to be optimal if `curr_try` hit TOTAL_TRIES
result.SetAlgoCompleted(is_done);
break;
}
// Find next undecided UTXO that does not produce equivalent prefix
while (next_utxo > 0
&& (curr_selection.empty() || curr_selection.back() != next_utxo - 1)
Expand All @@ -362,14 +364,17 @@ util::Result<SelectionResult> CoinGrinder(std::vector<OutputGroup>& utxo_pool, c
} else {
// "Skipping" end of branch: SHIFT instead
if (curr_selection.empty()) {
// Exhausted search space before running into limit
is_done = true;
result.SetAlgoCompleted(is_done);
std::cout << "FINISHED SEARCH IN CLONE SKIPPING" << std::endl;
result.SetAlgoCompleted(true);
break;
}
next_utxo = curr_selection.back() + 1;
deselect_last();
}
}
if (is_done) break;
}

if (best_selection.empty()) {
Expand Down

0 comments on commit b83d126

Please sign in to comment.