aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2021-05-20 20:20:49 -0400
committerAndrew Chow <achow101-github@achow101.com>2021-09-23 13:33:25 -0400
commit3633b667ffca5a715d9fb27e977515c1e24f600a (patch)
tree3726a303ec5bed9bcd998ed1d04877aae1558e91 /src/wallet
parent8bf789b4b4b26082aea1d91c4d7aa8b01aedfdcf (diff)
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.
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/spend.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index 4a7a268982..1724375f4c 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -387,6 +387,15 @@ bool AttemptSelection(const CWallet& wallet, const CAmount& nTargetValue, const
results.emplace_back(std::make_tuple(waste, std::move(knapsack_coins), knapsack_value));
}
+ // We include the minimum final change for SRD as we do want to avoid making really small change.
+ // KnapsackSolver does not need this because it includes MIN_CHANGE internally.
+ const CAmount srd_target = nTargetValue + coin_selection_params.m_change_fee + MIN_FINAL_CHANGE;
+ auto srd_result = SelectCoinsSRD(positive_groups, srd_target);
+ if (srd_result != std::nullopt) {
+ const auto waste = GetSelectionWaste(srd_result->first, coin_selection_params.m_cost_of_change, srd_target, !coin_selection_params.m_subtract_fee_outputs);
+ results.emplace_back(std::make_tuple(waste, std::move(srd_result->first), srd_result->second));
+ }
+
if (results.size() == 0) {
// No solution found
return false;