Skip to content

Prefer confirmed utxos during coin selection#2095

Open
oliv3rdrt wants to merge 1 commit into
mintlayer:masterfrom
oliv3rdrt:prefer_confirmed_utxos
Open

Prefer confirmed utxos during coin selection#2095
oliv3rdrt wants to merge 1 commit into
mintlayer:masterfrom
oliv3rdrt:prefer_confirmed_utxos

Conversation

@oliv3rdrt

Copy link
Copy Markdown

Problem

Since #2063 the mempool limits how many transactions a cluster may contain and how big it may be. A transaction that spends unconfirmed (in-mempool) utxos joins the cluster of the transactions that produced them, so a wallet that builds on top of unconfirmed utxos can create a transaction that the mempool then rejects because the cluster grew too large.

Change

This is the first step of #2066: prefer confirmed utxos during selection.

select_inputs_for_send_request now also gathers the confirmed-only utxos, and a new select_coins_preferring_confirmed helper tries to reach the target from the confirmed set first, falling back to the full set (which also contains the unconfirmed utxos) only when the confirmed ones are not enough. The fallback is exactly the call that was made before, so behaviour is unchanged whenever confirmed utxos can't cover the amount. The preference is only applied when the caller did not select the inputs explicitly.

Not included here

The rest of #2066 is left for follow-ups:

  • Querying the node/mempool for the resulting cluster's tx count and byte size and retrying with a different utxo combination (needs new node RPC methods).
  • Handling non-utxo cluster relations once the mempool tracks them.

Tests

Added unit tests for select_coins_preferring_confirmed: it uses the confirmed set when it is sufficient, falls back to the full set when it is not, and uses the full set directly when there is no preference. The existing selection tests still pass.

Addresses #2066

Since the mempool started limiting the size of transaction clusters, a wallet
that builds a transaction on top of unconfirmed (in-mempool) utxos can produce
a transaction that the mempool then rejects because the resulting cluster is
too big.

As a first step towards taking cluster limits into account, prefer confirmed
utxos during selection. select_inputs_for_send_request now also gathers the
confirmed-only utxos and select_coins_preferring_confirmed tries to satisfy the
target from those first, falling back to the full set (which also includes the
unconfirmed utxos) only when the confirmed ones are not enough. The fallback
path is identical to the previous behaviour, so nothing regresses when confirmed
utxos can't cover the amount.

This addresses the first item of mintlayer#2066; querying the mempool for the resulting
cluster size and retrying is left for a follow-up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant