0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

opt: Skip branches with worse weight

Once we exceed the weight of the current best selection, we can always
shift as adding more inputs can never yield a better solution.
This commit is contained in:
Murch 2024-01-08 15:26:21 -05:00
parent d68bc74fb2
commit 5f84f3cc04
2 changed files with 4 additions and 1 deletions

View file

@ -413,6 +413,9 @@ util::Result<SelectionResult> CoinGrinder(std::vector<OutputGroup>& 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;

View file

@ -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()));
}