Skip to content

Commit 0df0438

Browse files
committed
fuzz: coinselection, improve ComputeAndSetWaste
Instead of using `cost_of_change` for `min_viable_change` and `change_cost`, and 0 for `change_fee`, use values from `coin_params`. The previous values don't generate any effects that is relevant for that context.
1 parent 1e351e5 commit 0df0438

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/wallet/test/fuzz/coinselection.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ FUZZ_TARGET(coinselection)
8585
const CFeeRate long_term_fee_rate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
8686
const CFeeRate effective_fee_rate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
8787
const CAmount cost_of_change{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
88+
const CAmount min_viable_change{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
8889
const CAmount target{fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(1, MAX_MONEY)};
8990
const bool subtract_fee_outputs{fuzzed_data_provider.ConsumeBool()};
9091

@@ -93,6 +94,8 @@ FUZZ_TARGET(coinselection)
9394
coin_params.m_subtract_fee_outputs = subtract_fee_outputs;
9495
coin_params.m_long_term_feerate = long_term_fee_rate;
9596
coin_params.m_effective_feerate = effective_fee_rate;
97+
coin_params.min_viable_change = min_viable_change;
98+
coin_params.m_cost_of_change = cost_of_change;
9699
coin_params.change_output_size = fuzzed_data_provider.ConsumeIntegralInRange<int>(10, 1000);
97100
coin_params.m_change_fee = effective_fee_rate.GetFee(coin_params.change_output_size);
98101

@@ -110,7 +113,7 @@ FUZZ_TARGET(coinselection)
110113
}
111114

112115
// Run coinselection algorithms
113-
auto result_bnb = SelectCoinsBnB(group_pos, target, cost_of_change, MAX_STANDARD_TX_WEIGHT);
116+
auto result_bnb = SelectCoinsBnB(group_pos, target, coin_params.m_cost_of_change, MAX_STANDARD_TX_WEIGHT);
114117
if (result_bnb) {
115118
(void)result_bnb->GetShuffledInputVector();
116119
(void)result_bnb->GetInputSet();
@@ -119,15 +122,15 @@ FUZZ_TARGET(coinselection)
119122
auto result_srd = SelectCoinsSRD(group_pos, target, coin_params.m_change_fee, fast_random_context, MAX_STANDARD_TX_WEIGHT);
120123
if (result_srd) {
121124
assert(result_srd->GetChange(CHANGE_LOWER, coin_params.m_change_fee) > 0); // Demonstrate that SRD creates change of at least CHANGE_LOWER
122-
result_srd->ComputeAndSetWaste(cost_of_change, cost_of_change, 0);
125+
result_srd->ComputeAndSetWaste(coin_params.min_viable_change, coin_params.m_cost_of_change, coin_params.m_change_fee);
123126
(void)result_srd->GetShuffledInputVector();
124127
(void)result_srd->GetInputSet();
125128
}
126129

127130
CAmount change_target{GenerateChangeTarget(target, coin_params.m_change_fee, fast_random_context)};
128131
auto result_knapsack = KnapsackSolver(group_all, target, change_target, fast_random_context, MAX_STANDARD_TX_WEIGHT);
129132
if (result_knapsack) {
130-
result_knapsack->ComputeAndSetWaste(cost_of_change, cost_of_change, 0);
133+
result_knapsack->ComputeAndSetWaste(coin_params.min_viable_change, coin_params.m_cost_of_change, coin_params.m_change_fee);
131134
(void)result_knapsack->GetShuffledInputVector();
132135
(void)result_knapsack->GetInputSet();
133136
}

0 commit comments

Comments
 (0)