Repository navigation
Prefer confirmed utxos during coin selection - #2095
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.
b495cc0 to
61273bc
Compare
|
Automated review — OpenCodeReview model ( Overall: Sound change implementing the issue #2066 mitigation already sketched in the TODO at Findings:
|
70bd008 to
3b3867e
Compare
The confirmed-only UTXO query filters by the state of the producing transaction, and the same state mask decides whether a UTXO has already been consumed. On its own, the confirmed-only mask therefore re-admits UTXOs of confirmed transactions that the wallet has already spent in its own pending or evicted transactions, and selecting one would build a conflicting transaction. Intersect the confirmed-only set with the full set so such UTXOs stay excluded. Also document that the confirmed preference deliberately ignores waste, add CHANGELOG entries for the preference and the fix, and cover the weight-cap and empty-bucket fallback paths with tests.
|
One correctness issue found while reviewing the confirmed-preference wiring — the confirmed-only UTXO query filters by the state of the producing transaction, but its state mask is also what decides whether a UTXO has already been consumed. With the confirmed-only mask, UTXOs of confirmed transactions that the wallet has already spent in its own pending or evicted transactions slip back into the pool — an automatic send could then pick the same outpoint its own unconfirmed tx spends, producing a conflicting transaction the mempool rejects (or, under RBF, replacing the user's earlier payment). The pushed commit intersects the confirmed-only set with the full pool's outpoints, making the confirmed pool a subset of the full pool by construction, so anything the full pool excludes stays excluded. It also documents the deliberate waste trade-off, adds CHANGELOG entries, and covers the weight-cap and empty-bucket fallback paths with tests (the weight-cap one verified to fail if the fallback is removed). Suggested follow-ups (not addressed here): an account-level regression test with a pending send (needs output-cache seeding); the |
…d-pool-subset # Conflicts: # CHANGELOG.md # wallet/src/account/mod.rs # wallet/src/account/utxo_selector/tests.rs
|
@nullPointerEnjoyer Good catch on the UTXOs already spent by pending txs, thanks for the fix. Merged master in and resolved the conflicts. Happy to do the account-level pending send test as a follow-up. |
The previous merge resolution removed the unreleased Node and Node CLI entries and the 1.4.5, 1.4.4 and 1.4.1 sections. Bring them back and keep the confirmed UTXOs entry under Wallet.
|
@erubboli The master merge here dropped ~98 lines of CHANGELOG (Node/Node CLI unreleased entries and the 1.4.5, 1.4.4, 1.4.1 sections), so I've pushed a commit putting them back. Code is unchanged. |
|
@erubboli CI failures here look unrelated: macOS build was cancelled, clang crashed building secp256k1-sys in the wasm job, and static checks hit the chrono advisory that's failing on master too. Could you re-run the failed jobs? |
…d-pool-subset # Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
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