This PR adds a new coin selection algorithm to the existing collection, namely CoinGrinder, which purpose is to minimize the input weight of the selected coins which the potential downside that it may fraction (grind) the wallet input set on the long term. The algorithm is intended to be used under higher fee periods in where looking for a changeless input set (as the ones BnB could provide) may result in a transaction paying a high fee.
The logic behind this is that under high fee periods we may prefer fractioning our wallet and, once fees go down, we could focus on consolidating.
Most of the discussion and analysis of this has happened offline in the office. I have gone over the basic algorithm, drawn some pen and paper examples and whiteboarded with both Mark and Pieter.
I think the proposal is sound, and the optimizations make it run in a reasonable number of iterations/time. The reasoning for why it is needed makes sense modulo the fee not following an upwards only trend, in where the wallet will end up completely fractioned. The alternative would be potentially overspending in fees during a long term period, which is also non ideal.
Initial review:
Second pass: