mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
wallet: calculate and store min_viable_change
This commit is contained in:
@@ -123,6 +123,10 @@ struct CoinSelectionParams {
|
|||||||
/** Mininmum change to target in Knapsack solver: select coins to cover the payment and
|
/** Mininmum change to target in Knapsack solver: select coins to cover the payment and
|
||||||
* at least this value of change. */
|
* at least this value of change. */
|
||||||
CAmount m_min_change_target{0};
|
CAmount m_min_change_target{0};
|
||||||
|
/** Minimum amount for creating a change output.
|
||||||
|
* If change budget is smaller than min_change then we forgo creation of change output.
|
||||||
|
*/
|
||||||
|
CAmount min_viable_change{0};
|
||||||
/** Cost of creating the change output. */
|
/** Cost of creating the change output. */
|
||||||
CAmount m_change_fee{0};
|
CAmount m_change_fee{0};
|
||||||
/** Cost of creating the change output + cost of spending the change output in the future. */
|
/** Cost of creating the change output + cost of spending the change output in the future. */
|
||||||
|
|||||||
@@ -855,6 +855,13 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
|
|||||||
|
|
||||||
coin_selection_params.m_min_change_target = GenerateChangeTarget(std::floor(recipients_sum / vecSend.size()), coin_selection_params.m_change_fee, rng_fast);
|
coin_selection_params.m_min_change_target = GenerateChangeTarget(std::floor(recipients_sum / vecSend.size()), coin_selection_params.m_change_fee, rng_fast);
|
||||||
|
|
||||||
|
// The smallest change amount should be:
|
||||||
|
// 1. at least equal to dust threshold
|
||||||
|
// 2. at least 1 sat greater than fees to spend it at m_discard_feerate
|
||||||
|
const auto dust = GetDustThreshold(change_prototype_txout, coin_selection_params.m_discard_feerate);
|
||||||
|
const auto change_spend_fee = coin_selection_params.m_discard_feerate.GetFee(coin_selection_params.change_spend_size);
|
||||||
|
coin_selection_params.min_viable_change = std::max(change_spend_fee + 1, dust);
|
||||||
|
|
||||||
// vouts to the payees
|
// vouts to the payees
|
||||||
if (!coin_selection_params.m_subtract_fee_outputs) {
|
if (!coin_selection_params.m_subtract_fee_outputs) {
|
||||||
coin_selection_params.tx_noinputs_size = 10; // Static vsize overhead + outputs vsize. 4 nVersion, 4 nLocktime, 1 input count, 1 witness overhead (dummy, flag, stack size)
|
coin_selection_params.tx_noinputs_size = 10; // Static vsize overhead + outputs vsize. 4 nVersion, 4 nLocktime, 1 input count, 1 witness overhead (dummy, flag, stack size)
|
||||||
|
|||||||
Reference in New Issue
Block a user