Prefer confirmed utxos during coin selection#2095
Open
oliv3rdrt wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_requestnow also gathers the confirmed-only utxos, and a newselect_coins_preferring_confirmedhelper 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:
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