From b6fc5043c16c2467a2a6768a6ca9b18035fc400f Mon Sep 17 00:00:00 2001 From: ismaelsadeeq Date: Thu, 21 Mar 2024 17:05:51 +0100 Subject: [PATCH] [wallet]: update the data type of `change_output_size`, `change_spend_size` and `tx_noinputs_size` to `int` - This change ensures consistency in transaction size and weight calculation within the wallet and prevents conversion overflow when calculating `max_selection_weight`. --- src/wallet/coinselection.h | 10 +++++----- src/wallet/spend.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wallet/coinselection.h b/src/wallet/coinselection.h index 6b0d1ab2a47..1f234427d2c 100644 --- a/src/wallet/coinselection.h +++ b/src/wallet/coinselection.h @@ -139,9 +139,9 @@ struct CoinSelectionParams { /** Randomness to use in the context of coin selection. */ FastRandomContext& rng_fast; /** Size of a change output in bytes, determined by the output type. */ - size_t change_output_size = 0; + int change_output_size = 0; /** Size of the input to spend a change output in virtual bytes. */ - size_t change_spend_size = 0; + int change_spend_size = 0; /** Mininmum change to target in Knapsack solver and CoinGrinder: * select coins to cover the payment and at least this value of change. */ CAmount m_min_change_target{0}; @@ -162,7 +162,7 @@ struct CoinSelectionParams { CFeeRate m_discard_feerate; /** Size of the transaction before coin selection, consisting of the header and recipient * output(s), excluding the inputs and change output(s). */ - size_t tx_noinputs_size = 0; + int tx_noinputs_size = 0; /** Indicate that we are subtracting the fee from outputs */ bool m_subtract_fee_outputs = false; /** When true, always spend all (up to OUTPUT_GROUP_MAX_ENTRIES) or none of the outputs @@ -175,9 +175,9 @@ struct CoinSelectionParams { */ bool m_include_unsafe_inputs = false; - CoinSelectionParams(FastRandomContext& rng_fast, size_t change_output_size, size_t change_spend_size, + CoinSelectionParams(FastRandomContext& rng_fast, int change_output_size, int 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) + CFeeRate long_term_feerate, CFeeRate discard_feerate, int tx_noinputs_size, bool avoid_partial) : rng_fast{rng_fast}, change_output_size(change_output_size), change_spend_size(change_spend_size), diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 4759f1eb956..e0546c6210a 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -1059,7 +1059,7 @@ static util::Result CreateTransactionInternal( if (change_spend_size == -1) { coin_selection_params.change_spend_size = DUMMY_NESTED_P2WPKH_INPUT_SIZE; } else { - coin_selection_params.change_spend_size = (size_t)change_spend_size; + coin_selection_params.change_spend_size = change_spend_size; } // Set discard feerate