mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
opt: Skip evaluation of equivalent input sets
When two successive UTXOs match in effective value and weight, we can
skip the second if the prior is not selected: adding it would create an
equivalent input set to a previously evaluated.
E.g. if we have three UTXOs with effective values {5, 3, 3} of the same
weight each, we want to evaluate
{5, _, _}, {5, 3, _}, {5, 3, 3}, {_, 3, _}, {_, 3, 3},
but skip {5, _, 3}, and {_, _, 3}, because the first 3 is not selected,
and we therefore do not need to evaluate the second 3 at the same
position in the input set.
If we reach the end of the branch, we must SHIFT the previously selected
UTXO group instead.
This commit is contained in:
@@ -1180,7 +1180,7 @@ BOOST_AUTO_TEST_CASE(coin_grinder_tests)
|
||||
});
|
||||
BOOST_CHECK(res);
|
||||
// Demonstrate how following improvements reduce iteration count and catch any regressions in the future.
|
||||
size_t expected_attempts = 100'000;
|
||||
size_t expected_attempts = 184;
|
||||
BOOST_CHECK_MESSAGE(res->GetSelectionsEvaluated() == expected_attempts, strprintf("Expected %i attempts, but got %i", expected_attempts, res->GetSelectionsEvaluated()));
|
||||
}
|
||||
|
||||
@@ -1202,7 +1202,7 @@ BOOST_AUTO_TEST_CASE(coin_grinder_tests)
|
||||
add_coin(1 * COIN, 2, 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 = 4;
|
||||
size_t expected_attempts = 3;
|
||||
BOOST_CHECK_MESSAGE(res->GetSelectionsEvaluated() == expected_attempts, strprintf("Expected %i attempts, but got %i", expected_attempts, res->GetSelectionsEvaluated()));
|
||||
}
|
||||
|
||||
@@ -1271,7 +1271,7 @@ BOOST_AUTO_TEST_CASE(coin_grinder_tests)
|
||||
BOOST_CHECK(EquivalentResult(expected_result, *res));
|
||||
// Demonstrate how following improvements reduce iteration count and catch any regressions in the future.
|
||||
// If this takes more attempts, the implementation has regressed
|
||||
size_t expected_attempts = 82'407;
|
||||
size_t expected_attempts = 43;
|
||||
BOOST_CHECK_MESSAGE(res->GetSelectionsEvaluated() == expected_attempts, strprintf("Expected %i attempts, but got %i", expected_attempts, res->GetSelectionsEvaluated()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user