Skip to content

Commit

Permalink
Fix while loop
Browse files Browse the repository at this point in the history
  • Loading branch information
murchandamus committed Jan 5, 2024
1 parent f134ae0 commit a295fda
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 @@ -293,8 +293,8 @@ util::Result<SelectionResult> CoinGrinder(std::vector<OutputGroup>& utxo_pool, c

SelectionResult result(selection_target, SelectionAlgorithm::CG);
bool is_done = false;
size_t curr_try = 0;
while (!is_done) {
for (size_t curr_try = 0;;) {
bool should_shift{false}, should_cut{false};
// Select `next_utxo`
OutputGroup& utxo = utxo_pool[next_utxo];
Expand All @@ -304,7 +304,7 @@ util::Result<SelectionResult> CoinGrinder(std::vector<OutputGroup>& utxo_pool, c
++curr_try;
++next_utxo;

// EVALUATE the new input set candidate, default to exploring the inclusion branch further, else do exactly one SHIFT or CUT.
// EVALUATE current selection, default to exploring the inclusion branch further, else do exactly one SHIFT or CUT.
if (curr_amount + lookahead[curr_selection.back()] < selection_target + change_target) {
// Insufficient funds with lookahead: CUT
should_cut = true;
Expand All @@ -327,11 +327,13 @@ 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()) {
// Added UTXO was end of UTXO pool, nothing left to add on inclusion or omission branch: CUT
should_cut = true;
Expand Down

0 comments on commit a295fda

Please sign in to comment.