diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp index abd710d56d..cf666e7459 100644 --- a/src/wallet/coinselection.cpp +++ b/src/wallet/coinselection.cpp @@ -413,6 +413,9 @@ util::Result CoinGrinder(std::vector& utxo_pool, c // max_weight exceeded: SHIFT max_tx_weight_exceeded = true; should_shift = true; + } else if (curr_weight > best_selection_weight) { + // Worse weight than best solution. More UTXOs only increase weight: SHIFT + should_shift = true; } else if (curr_amount >= total_target) { // Success, adding more weight cannot be better: SHIFT should_shift = true; diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp index e23292d21f..fe9922e31c 100644 --- a/src/wallet/test/coinselector_tests.cpp +++ b/src/wallet/test/coinselector_tests.cpp @@ -1231,7 +1231,7 @@ BOOST_AUTO_TEST_CASE(coin_grinder_tests) add_coin(4 * COIN, 3, expected_result); BOOST_CHECK(EquivalentResult(expected_result, *res)); // Demonstrate how following improvements reduce iteration count and catch any regressions in the future. - size_t expected_attempts = 2041; + size_t expected_attempts = 525; BOOST_CHECK_MESSAGE(res->GetSelectionsEvaluated() == expected_attempts, strprintf("Expected %i attempts, but got %i", expected_attempts, res->GetSelectionsEvaluated())); }