From b83d12656a5296043e38a45420e8ade81a6cd1de Mon Sep 17 00:00:00 2001 From: Murch Date: Thu, 4 Jan 2024 17:17:32 -0500 Subject: [PATCH] Split exit conditions --- src/wallet/coinselection.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp index 6b4c0964cd825e..88422d325b1cb4 100644 --- a/src/wallet/coinselection.cpp +++ b/src/wallet/coinselection.cpp @@ -324,6 +324,11 @@ util::Result CoinGrinder(std::vector& 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; @@ -334,11 +339,13 @@ util::Result CoinGrinder(std::vector& 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; @@ -346,11 +353,6 @@ util::Result CoinGrinder(std::vector& utxo_pool, c 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) @@ -362,14 +364,17 @@ util::Result CoinGrinder(std::vector& 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()) {