Resolves #9466
I feel bad making the wallet coin selection even more spaghetti like, but I think this is a huge improvement over the existing code and it’s relatively simple to understand.
Essentially once you pick coins and if you have change, then try to reduce that change to meet the fee instead of repicking coins. Since we aim to have change of .01 BTC if we can’t make an exact match initially, this is usually more than sufficient to be reduced only slightly to pay for the fee.
I think for 0.15, we could take on a wholesale rewrite of the algorithm, but thats too much to ask for before 0.14. This however might be worthwhile.
I’m open to suggestions on how to make this cleaner or clearer.
EDIT: suggest viewing diff with ?w=1
EDIT 2: This is much simpler now. Also includes another commit to remove further cases of overpaying fees.