HomePhabricator

test: MiniWallet: more deterministic coin selection for coinbase UTXOs (oldest…

Description

test: MiniWallet: more deterministic coin selection for coinbase UTXOs (oldest first)

Summary:

The coin selection strategy for MiniWallet is quite straight-forward: simply
pick a single UTXO with the largest value:

self._utxos = sorted(self._utxos, key=lambda k: k['value'])
utxo_to_spend = utxo_to_spend or self._utxos.pop()

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.

Backport of core#23375.

Depends on D12730.

Test Plan:

ninja check-functional

Reviewers: #bitcoin_abc, sdulfari

Reviewed By: #bitcoin_abc, sdulfari

Differential Revision: https://reviews.bitcoinabc.org/D12731

Details

Provenance
FabienAuthored on Dec 2 2022, 15:18
FabienPushed on Dec 2 2022, 19:47
Reviewer
Restricted Project
Differential Revision
D12731: test: MiniWallet: more deterministic coin selection for coinbase UTXOs (oldest first)
Parents
rABC4624df9933f2: test: MiniWallet: skip mempool check if `mempool_valid=False`
Branches
Unknown
Tags
Unknown