Skip to content

Commit b6fc504

Browse files
committed
[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`.
1 parent baab0d2 commit b6fc504

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/wallet/coinselection.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ struct CoinSelectionParams {
139139
/** Randomness to use in the context of coin selection. */
140140
FastRandomContext& rng_fast;
141141
/** Size of a change output in bytes, determined by the output type. */
142-
size_t change_output_size = 0;
142+
int change_output_size = 0;
143143
/** Size of the input to spend a change output in virtual bytes. */
144-
size_t change_spend_size = 0;
144+
int change_spend_size = 0;
145145
/** Mininmum change to target in Knapsack solver and CoinGrinder:
146146
* select coins to cover the payment and at least this value of change. */
147147
CAmount m_min_change_target{0};
@@ -162,7 +162,7 @@ struct CoinSelectionParams {
162162
CFeeRate m_discard_feerate;
163163
/** Size of the transaction before coin selection, consisting of the header and recipient
164164
* output(s), excluding the inputs and change output(s). */
165-
size_t tx_noinputs_size = 0;
165+
int tx_noinputs_size = 0;
166166
/** Indicate that we are subtracting the fee from outputs */
167167
bool m_subtract_fee_outputs = false;
168168
/** When true, always spend all (up to OUTPUT_GROUP_MAX_ENTRIES) or none of the outputs
@@ -175,9 +175,9 @@ struct CoinSelectionParams {
175175
*/
176176
bool m_include_unsafe_inputs = false;
177177

178-
CoinSelectionParams(FastRandomContext& rng_fast, size_t change_output_size, size_t change_spend_size,
178+
CoinSelectionParams(FastRandomContext& rng_fast, int change_output_size, int change_spend_size,
179179
CAmount min_change_target, CFeeRate effective_feerate,
180-
CFeeRate long_term_feerate, CFeeRate discard_feerate, size_t tx_noinputs_size, bool avoid_partial)
180+
CFeeRate long_term_feerate, CFeeRate discard_feerate, int tx_noinputs_size, bool avoid_partial)
181181
: rng_fast{rng_fast},
182182
change_output_size(change_output_size),
183183
change_spend_size(change_spend_size),

src/wallet/spend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
10591059
if (change_spend_size == -1) {
10601060
coin_selection_params.change_spend_size = DUMMY_NESTED_P2WPKH_INPUT_SIZE;
10611061
} else {
1062-
coin_selection_params.change_spend_size = (size_t)change_spend_size;
1062+
coin_selection_params.change_spend_size = change_spend_size;
10631063
}
10641064

10651065
// Set discard feerate

0 commit comments

Comments
 (0)