coinselection: Track whether BnB completed

BnB may not be able to exhaustively search all potentially interesting
combinations for large UTXO pools, so we keep track of whether the
search was terminated by the iteration limit.
This commit is contained in:
Murch 2025-03-26 17:18:18 -07:00
parent d765ba9ae5
commit b6bf22cc1d
No known key found for this signature in database
GPG key ID: 7BA035CA5B901713

View file

@ -137,6 +137,7 @@ util::Result<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool
};
size_t curr_try = 0;
SelectionResult result(selection_target, SelectionAlgorithm::BNB);
while (true) {
bool should_shift{false}, should_cut{false};
// Select `next_utxo`
@ -172,6 +173,7 @@ util::Result<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool
if (curr_try >= TOTAL_TRIES) {
// Solution is not guaranteed to be optimal if `curr_try` hit TOTAL_TRIES
result.SetAlgoCompleted(false);
break;
}
@ -193,6 +195,7 @@ util::Result<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool
// 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
result.SetAlgoCompleted(true);
break;
}
next_utxo = curr_selection.back() + 1;
@ -201,7 +204,6 @@ util::Result<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool
}
}
SelectionResult result(selection_target, SelectionAlgorithm::BNB);
result.SetSelectionsEvaluated(curr_try);
if (best_selection.empty()) {