Thanks for your review @murchandamus
Perhaps if we are getting big into the business of changing the types of various transaction size, vsize and weight variables, we should perhaps consider introducing explicit types for weight, size, and vsize to prevent people accidentally mistaking them for the same type.
I agree with this suggestion and have same concern previously here #29242 (review) should make the code cleaner
Sorry for not explaining the rationale behind this in the commit messages, I will try and explain why I did the change below
On master we have
0 int max_inputs_weight = MAX_STANDARD_TX_WEIGHT - (coin_selection_params.tx_noinputs_size * WITNESS_SCALE_FACTOR);
1
2
3 .......
4 max_inputs_weight -= (coin_selection_params.change_output_size * WITNESS_SCALE_FACTOR);
After this PR maximum transaction weight can be configured by users, so we now subtract from user provided maximum weight or use the default if not given.
0int max_selection_weight = coin_selection_params.m_max_tx_weight.value_or(MAX_STANDARD_TX
1_WEIGHT) - coin_selection_params.tx_noinputs_size * WITNESS_SCALE_FACTOR;
m_max_tx_weight
is int
, tx_noinputs_size
and change_output_size
are both size_t
.
given that Bitcoin Core only supports platforms where int is exactly 32 bits
For signed integers (int), it ranges from -2^(31) to (2^(31)) - 1.
For unsigned integers (unsigned int), it ranges from 0 to (2^(32)) - 1.
The issue arises when after compiling with “ASan + LSan + UBSan + integer, without dependencies, USDT” and running the functional test.
From 854acd72e9 we allow passing 0 weight and test for that in the functional test, results of subtracting coin_selection_params.tx_noinputs_size * WITNESS_SCALE_FACTOR
from 0 causes max_selection_weight
to have some positive value instead of negative. hence the test fails see https://cirrus-ci.com/task/6341256662482944, This is reproducible locally.
Thats why I changed change_output_size
, and tx_noinputs_size
from size_t
to int64_t
and also use same datatype for m_max_tx_weight
which works fine.
0int64_t max_selection_weight = coin_selection_params.m_max_tx_weight.value_or(MAX_STANDARD_TX
1_WEIGHT) - static_cast<int64_t>(coin_selection_params.tx_noinputs_size * WITNESS_SCALE_FACTOR);
But since Bitcoin Core only supports platforms where int is exactly 32 bits I think using int for change_output_size
, and tx_noinputs_size
should work fine?