aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/spend.cpp
diff options
context:
space:
mode:
authorMurch <murch@murch.one>2023-05-23 19:36:04 -0400
committerMurch <murch@murch.one>2024-02-09 10:44:32 +0100
commit6cc9a46cd0f4ed80d4523bbef1508142e0c80d27 (patch)
tree7458471f4a9468a2de94179bddda88b4d617c459 /src/wallet/spend.cpp
parent89d09566431f57034d9a7df32547ceb13d79c62c (diff)
downloadbitcoin-6cc9a46cd0f4ed80d4523bbef1508142e0c80d27.tar.xz
coinselection: Add CoinGrinder algorithm
CoinGrinder is a DFS-based coin selection algorithm that deterministically finds the input set with the lowest weight creating a change output.
Diffstat (limited to 'src/wallet/spend.cpp')
-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 b51cd6332f..c79079d33d 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -709,6 +709,15 @@ util::Result<SelectionResult> ChooseSelectionResult(interfaces::Chain& chain, co
results.push_back(*knapsack_result);
} else append_error(knapsack_result);
+ if (coin_selection_params.m_effective_feerate > CFeeRate{3 * coin_selection_params.m_long_term_feerate}) { // Minimize input set for feerates of at least 3×LTFRE (default: 30 ṩ/vB+)
+ if (auto cg_result{CoinGrinder(groups.positive_group, nTargetValue, coin_selection_params.m_min_change_target, max_inputs_weight)}) {
+ cg_result->ComputeAndSetWaste(coin_selection_params.min_viable_change, coin_selection_params.m_cost_of_change, coin_selection_params.m_change_fee);
+ results.push_back(*cg_result);
+ } else {
+ append_error(cg_result);
+ }
+ }
+
if (auto srd_result{SelectCoinsSRD(groups.positive_group, nTargetValue, coin_selection_params.m_change_fee, coin_selection_params.rng_fast, max_inputs_weight)}) {
results.push_back(*srd_result);
} else append_error(srd_result);