You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge #21083: wallet: Avoid requesting fee rates multiple times during coin selection
f9cd2bf Rename CoinSelectionParams::effective_fee to m_effective_feerate (Andrew Chow)
bdd0c29 wallet: Move discard feerate fetching to CreateTransaction (Andrew Chow)
448d04b wallet: Move long term feerate setting to CreateTransaction (Andrew Chow)
e2f429e wallet: Replace nFeeRateNeeded with effective_fee (Andrew Chow)
1a6a0b0 wallet: Use existing feerate instead of getting a new one (Andrew Chow)
Pull request description:
During coin selection, there are various places where we need to have a feerate. We need the feerate for the transaction itself, the discard fee rate, and long term feerate. Fetching these each time we need them can lead to a race condition where two feerates that should be the same are actually different. One particular instance where this can happen is during the loop in `CreateTransactionInternal`. After inputs are chosen, the expected transaction fee is calculated using a newly fetched feerate. If `pick_new_inputs == false`, the loop will go again with the assumption that the fee for the transaction remains the same. However because the feerate is fetched again, it is possible that it actually isn't and this causes coin selection to fail.
Instead of fetching the feerate each time it is needed, we fetch them all at once at the top of `CreateTransactionInternal`, store them in `CoinSelectionParams`, and use them where needed.
While some of these fee rates probably don't need this caching, I've done it for consistency and the guarantee that they remain the same.
Fixes #19229
ACKs for top commit:
glozow:
reACK bitcoin/bitcoin@f9cd2bf
fjahr:
Code review re-ACK f9cd2bf
Xekyo:
tACK bitcoin/bitcoin@f9cd2bf
meshcollider:
Code review + test run ACK f9cd2bf
Tree-SHA512: be83ff64ba473c3cdd3469c812e214659b6e2a9584c22ed2b1595618fce0d4b35d0901e61068cd1069fc1a8fb911db01dd7312d05c3b8cbafbe2504ab7a3e863
unsignedint tx_size_with_change = nBytes + coin_selection_params.change_output_size + 2; // Add 2 as a buffer in case increasing # of outputs changes compact size
0 commit comments