Skip to content

Commit 18c05d9

Browse files
committed
Merge bitcoin#35590: test: wallet: BnB incomplete result on attempt-limit success
6ee05c4 test: wallet: BnB incomplete result on attempt-limit success (Bruno Garcia) Pull request description: BnB can return a valid selection before exhausting the search tree, then hit `TOTAL_TRIES` while continuing to look for a better one. Add a unit test for that path using a known exhaustion fixture plus an exact-match coin, and assert the result is marked incomplete via `GetAlgoCompleted() == false`. It kills the following mutant: ```diff diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp index 8d69957..e4d07415f3 100644 --- a/src/wallet/coinselection.cpp +++ b/src/wallet/coinselection.cpp @@ -212,7 +212,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); + result.SetAlgoCompleted(true); break; } ``` ACKs for top commit: yashbhutwala: tACK 6ee05c4 achow101: ACK 6ee05c4 murchandamus: ACK 6ee05c4 Tree-SHA512: 32d0cc6da7586abdd195b87459da0a6ebbdcf8115bef41f5e625864bfa9ce8231a58f8d4b61708279ebeaef372e4f3b5fb18eab28a01dad53f043ba083330b3d
2 parents b56b66f + 6ee05c4 commit 18c05d9

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/wallet/test/coinselection_tests.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,26 @@ BOOST_AUTO_TEST_CASE(bnb_test)
220220
}
221221
}
222222

223+
BOOST_AUTO_TEST_CASE(bnb_exhaustion_with_solution_test)
224+
{
225+
std::vector<OutputGroup> utxo_pool;
226+
utxo_pool.reserve(19);
227+
228+
CAmount selection_target{800'000};
229+
// A hard case with no exact-match solution: BnB must still report that the algorithm did not complete once the
230+
// search is pushed into the attempt limit, even though it finds a solution within cost_of_change of the target.
231+
for (size_t i = 0; i < 19; ++i) {
232+
utxo_pool.push_back(MakeCoin(100'000 + i, /*is_eff_value=*/true, default_cs_params));
233+
}
234+
235+
const auto result{SelectCoinsBnB(utxo_pool, selection_target, /*cost_of_change=*/default_cs_params.m_cost_of_change, MAX_STANDARD_TX_WEIGHT)};
236+
BOOST_CHECK_MESSAGE(result, "Falsy result in BnB-Success: Exhaust with early solution");
237+
BOOST_CHECK(result->GetSelectedEffectiveValue() > selection_target + 28);
238+
BOOST_CHECK_EQUAL(result->GetInputSet().size(), 8U);
239+
BOOST_CHECK_EQUAL(result->GetSelectionsEvaluated(), 100'000U);
240+
BOOST_CHECK(!result->GetAlgoCompleted());
241+
}
242+
223243
BOOST_AUTO_TEST_CASE(bnb_feerate_sensitivity_test)
224244
{
225245
// Create sets of UTXOs with the same effective amounts at different feerates (but different absolute amounts)

0 commit comments

Comments
 (0)