The coin selection strategy for MiniWallet is quite straight-forward: simply pick a single UTXO with the largest value:
If there are several candidates with the same value, however, it is not clear which one is taken. This can be particularly problematic for coinbase outputs with fixed block subsidy, since spending could lead to a bad-txns-premature-spend-of-coinbase
reject if an UTXO from a too-recent block is picked. Introduce block height as second criteria (saved in self._utxos
in the methods generate(...)
and rescan_utxos(...)
), in order to avoid potential issues with coinbases that are not matured yet. If there is a tie between coinbase UTXOs and non-coinbase UTXOs (the latter are added via scan_tx(...)
), prefer the non-coinbase UTXOs, since those don’t need to mature.
The issue came up while refactoring the test rpc_blockchain.py, see #23371 (review) (PR #23371).