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