diff options
author | glozow <gloriajzhao@gmail.com> | 2022-03-07 13:45:06 +0000 |
---|---|---|
committer | glozow <gloriajzhao@gmail.com> | 2022-03-25 11:56:46 +0000 |
commit | 1e52e6bd0a8888efb4ed247d74ec7ca9dfc2e002 (patch) | |
tree | 6bfea8ddf30f453c9e41f1278d09202f87814f01 /src/wallet/coinselection.h | |
parent | c9b5790e8da8a88d9022dd9725a1f7bb4474cbf7 (diff) |
refactor coin selection for parameterizable change target
no behavior changes, since the target is always MIN_CHANGE
Diffstat (limited to 'src/wallet/coinselection.h')
-rw-r--r-- | src/wallet/coinselection.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/wallet/coinselection.h b/src/wallet/coinselection.h index 504d57aa78..480c9664ca 100644 --- a/src/wallet/coinselection.h +++ b/src/wallet/coinselection.h @@ -94,6 +94,9 @@ struct CoinSelectionParams { size_t change_output_size = 0; /** Size of the input to spend a change output in virtual bytes. */ size_t change_spend_size = 0; + /** Mininmum change to target in Knapsack solver: select coins to cover the payment and + * at least this value of change. */ + CAmount m_min_change_target{MIN_CHANGE}; /** Cost of creating the change output. */ CAmount m_change_fee{0}; /** Cost of creating the change output + cost of spending the change output in the future. */ @@ -115,11 +118,13 @@ struct CoinSelectionParams { * reuse. Dust outputs are not eligible to be added to output groups and thus not considered. */ bool m_avoid_partial_spends = false; - CoinSelectionParams(FastRandomContext& rng_fast, size_t change_output_size, size_t change_spend_size, CFeeRate effective_feerate, + CoinSelectionParams(FastRandomContext& rng_fast, size_t change_output_size, size_t change_spend_size, + CAmount min_change_target, CFeeRate effective_feerate, CFeeRate long_term_feerate, CFeeRate discard_feerate, size_t tx_noinputs_size, bool avoid_partial) : rng_fast{rng_fast}, change_output_size(change_output_size), change_spend_size(change_spend_size), + m_min_change_target(min_change_target), m_effective_feerate(effective_feerate), m_long_term_feerate(long_term_feerate), m_discard_feerate(discard_feerate), @@ -267,7 +272,8 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_poo std::optional<SelectionResult> SelectCoinsSRD(const std::vector<OutputGroup>& utxo_pool, CAmount target_value, FastRandomContext& rng); // Original coin selection algorithm as a fallback -std::optional<SelectionResult> KnapsackSolver(std::vector<OutputGroup>& groups, const CAmount& nTargetValue, FastRandomContext& rng); +std::optional<SelectionResult> KnapsackSolver(std::vector<OutputGroup>& groups, const CAmount& nTargetValue, + CAmount change_target, FastRandomContext& rng); } // namespace wallet #endif // BITCOIN_WALLET_COINSELECTION_H |