Skip to content

Commit af56d63

Browse files
committed
Revert "bnb: exit selection when best_waste is 0"
This reverts commit 9b5950d. Waste can be negative. At feerates lower than long_term_feerate this means that a waste of 0 may be a suboptimal solution and this causes the search to exit prematurely. Only when the feerate is equal to the long_term_feerate would achieving a waste of 0 indicate that we have achieved an optimal solution, because it would mean that the excess is 0. It seems unlikely that this would ever occur outside of test cases, and even then we should prefer solutions with more inputs over solutions with fewer according to previous decisions—but solutions with more inputs are found later in the branch exploration. The "optimization" described in #18257 and implemented in #18262 is therefore a premature exit on a suboptimal solution and should be reverted.
1 parent 480d806 commit af56d63

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/wallet/coinselection.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_poo
104104
if (curr_waste <= best_waste) {
105105
best_selection = curr_selection;
106106
best_waste = curr_waste;
107-
if (best_waste == 0) {
108-
break;
109-
}
110107
}
111108
curr_waste -= (curr_value - selection_target); // Remove the excess value as we will be selecting different coins now
112109
backtrack = true;

src/wallet/test/coinselector_tests.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
198198
expected_result.Clear();
199199

200200
// Select 5 Cent
201-
add_coin(4 * CENT, 4, expected_result);
202-
add_coin(1 * CENT, 1, expected_result);
201+
add_coin(3 * CENT, 3, expected_result);
202+
add_coin(2 * CENT, 2, expected_result);
203203
const auto result3 = SelectCoinsBnB(GroupCoins(utxo_pool), 5 * CENT, 0.5 * CENT);
204204
BOOST_CHECK(result3);
205205
BOOST_CHECK(EquivalentResult(expected_result, *result3));
@@ -224,8 +224,9 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
224224

225225
// Select 10 Cent
226226
add_coin(5 * CENT, 5, utxo_pool);
227-
add_coin(5 * CENT, 5, expected_result);
228227
add_coin(4 * CENT, 4, expected_result);
228+
add_coin(3 * CENT, 3, expected_result);
229+
add_coin(2 * CENT, 2, expected_result);
229230
add_coin(1 * CENT, 1, expected_result);
230231
const auto result5 = SelectCoinsBnB(GroupCoins(utxo_pool), 10 * CENT, 0.5 * CENT);
231232
BOOST_CHECK(result5);

0 commit comments

Comments
 (0)