Repository navigation
Guard coin selection against inputs that don't cover their fee - #2165
Merged
nullPointerEnjoyer merged 5 commits intoNov 19, 2026
Merged
Conversation
get_effective_value expects an input's fee to be less than its value and panics otherwise, but select_coins relied on its caller to filter such inputs out. When fees are paid with the inputs' currency, select_coins now leaves them out itself before running any algorithm.
oliv3rdrt
requested review from
ImplOfAnImpl,
anyxem and
erubboli
as code owners
November 18, 2026 11:04
- cross-reference comments on both filter sites (select_coins guard is authoritative; the caller keeps a copy only for the conservative input-count estimate) - note the pre-existing silent omission of preselected dust inputs - seed the fee-coverage test per the file convention (assertions are shuffle-independent)
# Conflicts: # CHANGELOG.md
erubboli
approved these changes
Nov 19, 2026
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
OutputGroup::get_effective_valuesubtracts an input's fee from its value and panics viaexpectif the fee is larger. As nullPointerEnjoyer pointed out on #2094, nothing in the selector enforces that. Today the wallet builds its groups inutxo_output_groups_by_currency, which already drops coin inputs withvalue <= fee, so I don't think users can hit the panic right now. Butselect_coinsdepends on a filter in another module, so a new caller or a refactor could bring it back.Fix
When fees are paid with the inputs' currency,
select_coinsnow leaves out groups whose value doesn't exceed their fee before running any algorithm. It's the same rule the wallet already applies, so behaviour doesn't change, and it covers SRD, knapsack, BnB and preselected inputs. It also covers both pools inselect_coins_preferring_confirmedfrom #2095, since that goes throughselect_coins. Inputs whose fee is paid with another currency (tokens) are left alone, since their fee doesn't reduce their value.I kept the filter in
utxo_output_groups_by_currencybecause it also feeds the input count used for the fee estimate.Tests
test_select_coins_skips_inputs_not_covering_their_fee: a pool with one input worth less than its fee and one worth exactly its fee. Neither is selected with either algorithm. Panics without the fix.test_select_coins_no_inputs_covering_their_fee: a pool with only such inputs returnsNoUtxosinstead of panicking. Panics without the fix.test_select_coins_keeps_inputs_when_fee_paid_with_other_currency: checks the guard doesn't drop inputs when another currency pays the fee.cargo test -p wallet --lib,cargo fmt --checkand clippy with the CI flags pass locally.