mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 19:37:27 -03:00
wallet: Update BnB upper bound to be consistent with tx building
Use min_viable_change instead of cost_of_change as the upper limit of excess allowed when computing a changeless BnB solution. This prevents a corner case where dust threshold > change_fee results in some changeless BnB solutions not being considered, despite change being dropped during tx building. h/t @S3RK for identifying this issue in #26466 .
This commit is contained in:
parent
17bc70f80a
commit
7df63761eb
1 changed files with 2 additions and 6 deletions
|
@ -1119,12 +1119,6 @@ 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);
|
||||
|
||||
if (coin_control.m_max_excess) {
|
||||
coin_selection_params.m_max_excess = std::max(coin_control.m_max_excess.value(), coin_selection_params.m_cost_of_change);
|
||||
} else {
|
||||
coin_selection_params.m_max_excess = coin_selection_params.m_cost_of_change;
|
||||
}
|
||||
|
||||
// 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
|
||||
|
@ -1132,6 +1126,8 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
|
|||
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);
|
||||
|
||||
coin_selection_params.m_max_excess = std::max(coin_control.m_max_excess.value_or(0), coin_selection_params.min_viable_change);
|
||||
|
||||
// If set, do not add any excess from a changeless transaction to fees
|
||||
coin_selection_params.m_add_excess_to_recipient_position = coin_control.m_add_excess_to_recipient_position;
|
||||
|
||||
|
|
Loading…
Reference in a new issue