From 7aa7e30441fe77bf8e8092916e36b004bbbfe2a7 Mon Sep 17 00:00:00 2001 From: Murch Date: Mon, 21 Aug 2023 15:27:23 -0400 Subject: Fold GetSelectionWaste() into ComputeAndSetWaste() Both `GetSelectionWaste()` and `ComputeAndSetWaste()` now are part of `SelectionResult`. Instead of `ComputeAndSetWaste()` being a wrapper for `GetSelectionWaste()`, we combine them to a new function `RecalculateWaste()`. As I was combining the logic of the two functions, I noticed that `GetSelectionWaste()` was making the odd assumption that the `change_cost` being set to zero means that no change is created. However, if we build transactions at a feerate of zero with the `discard_feerate` also set to zero, we'd organically have a `change_cost` of zero, even when we create change on a transaction. This commit cleans up this duplicate meaning of `change_cost` and relies on `GetChange()` to figure out whether there is change on basis of the `min_viable_change` and whatever is left after deducting fees. Since this broke a bunch of tests that relied on the double-meaning of `change_cost` a bunch of tests had to be fixed. --- src/bench/coin_selection.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/bench') diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index 249b76ee85..171c61c46f 100644 --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -71,15 +71,15 @@ static void CoinSelection(benchmark::Bench& bench) /*change_output_size=*/ 34, /*change_spend_size=*/ 148, /*min_change_target=*/ CHANGE_LOWER, - /*effective_feerate=*/ CFeeRate(0), - /*long_term_feerate=*/ CFeeRate(0), - /*discard_feerate=*/ CFeeRate(0), + /*effective_feerate=*/ CFeeRate(20'000), + /*long_term_feerate=*/ CFeeRate(10'000), + /*discard_feerate=*/ CFeeRate(3000), /*tx_noinputs_size=*/ 0, /*avoid_partial=*/ false, }; auto group = wallet::GroupOutputs(wallet, available_coins, coin_selection_params, {{filter_standard}})[filter_standard]; bench.run([&] { - auto result = AttemptSelection(wallet.chain(), 1003 * COIN, group, coin_selection_params, /*allow_mixed_output_types=*/true); + auto result = AttemptSelection(wallet.chain(), 1002.99 * COIN, group, coin_selection_params, /*allow_mixed_output_types=*/true); assert(result); assert(result->GetSelectedValue() == 1003 * COIN); assert(result->GetInputSet().size() == 2); -- cgit v1.2.3