mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 10:12:28 +02:00
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:
@@ -131,6 +131,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`
|
||||
@@ -166,6 +167,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;
|
||||
}
|
||||
|
||||
@@ -185,6 +187,7 @@ util::Result<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool
|
||||
if (should_shift) {
|
||||
if (curr_selection.empty()) {
|
||||
// Exhausted search space before running into attempt limit
|
||||
result.SetAlgoCompleted(true);
|
||||
break;
|
||||
}
|
||||
// Set `next_utxo` to one after last selected, then deselect last selected UTXO
|
||||
@@ -193,7 +196,6 @@ util::Result<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool
|
||||
}
|
||||
}
|
||||
|
||||
SelectionResult result(selection_target, SelectionAlgorithm::BNB);
|
||||
result.SetSelectionsEvaluated(curr_try);
|
||||
|
||||
if (best_selection.empty()) {
|
||||
|
||||
Reference in New Issue
Block a user