Skip to content

Commit 3633b66

Browse files
committed
Use SelectCoinsSRD if it has less waste
Try to find a solution with SelectCoinsSRD. If we do have one, add it to the list of solutions from which we choose the one with the least waste as the solution to use.
1 parent 8bf789b commit 3633b66

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/wallet/spend.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,15 @@ bool AttemptSelection(const CWallet& wallet, const CAmount& nTargetValue, const
387387
results.emplace_back(std::make_tuple(waste, std::move(knapsack_coins), knapsack_value));
388388
}
389389

390+
// We include the minimum final change for SRD as we do want to avoid making really small change.
391+
// KnapsackSolver does not need this because it includes MIN_CHANGE internally.
392+
const CAmount srd_target = nTargetValue + coin_selection_params.m_change_fee + MIN_FINAL_CHANGE;
393+
auto srd_result = SelectCoinsSRD(positive_groups, srd_target);
394+
if (srd_result != std::nullopt) {
395+
const auto waste = GetSelectionWaste(srd_result->first, coin_selection_params.m_cost_of_change, srd_target, !coin_selection_params.m_subtract_fee_outputs);
396+
results.emplace_back(std::make_tuple(waste, std::move(srd_result->first), srd_result->second));
397+
}
398+
390399
if (results.size() == 0) {
391400
// No solution found
392401
return false;

0 commit comments

Comments
 (0)