Previous fee-targeting behavior lead to needless looping, excessive fees, and surprising behavior.
This PR changes the “fee targeting” algorithm by considering “effective value” of considered inputs instead of simply trying to hit an absolute fee, seeing if it failed, then trying again with the estimated total fee at the end of the loop.
The algorithm also doesn’t select any coin with non-positive effective value.
In short:
effectiveValue = nValue - feeRate*num_bytes_for_signed_input
To do:
- Previously the wallet just kept stuffing fees until it succeeded. In this PR there is no strict sanity checks on the loop, so if there is some error where we are just shy and cannot re-balance change output to pay for it, it will look forever(I have no idea if this is possible since we should be over-estimating at worst). We should probably have something like #10333 for re-balancing, and then a sanity check to error out if a specified feerate cannot be hit for some reason post-coin selection, perhaps after a fixed number of tries.
- This breaks the
coinControl->nMinimumTotalFee
option. I can’t conceive a use for it, so I want to remove this anyways. https://github.com/bitcoin/bitcoin/pull/10390