Skip to content

fix(wallet): filter uneconomical inputs from BnB fallback - #575

Open
j-kon wants to merge 1 commit into
bitcoindevkit:masterfrom
j-kon:fix/bnb-fallback-effective-value
Open

j-kon wants to merge 1 commit into
bitcoindevkit:masterfrom
j-kon:fix/bnb-fallback-effective-value

Conversation

@j-kon

@j-kon j-kon commented Sep 27, 2026

Copy link
Copy Markdown

Description

Fixes #553.

Branch-and-bound excludes optional UTXOs whose spending fee is at least their value, but previously passed the original, unfiltered candidates to its fallback. When no changeless selection exists, this can increase fees unnecessarily or report insufficient funds despite an economical selection being available.

For example, with a 49,000-sat target at 10 sat/vB, a 50,000-sat input covers the target and its 680-sat input fee. If the fallback first selects an older 300-sat input, the resulting 50,300 sats cannot cover the target plus 1,360 sats of input fees.

Build the fallback candidates and BnB output groups from the same filtered sequence. Required inputs remain eligible regardless of effective value; standalone coin-selection algorithms are unchanged.

Notes to the reviewers

The regression uses the real OldestFirstCoinSelection fallback to make selection deterministic. Both targets exceed the BnB changeless window, so the test exercises fallback rather than the existing preflight insufficient-funds path. Coverage includes negative and zero effective values, the one-satoshi positive boundary, and explicitly required negative-effective-value inputs.

Confirmed the regression fails before the fix and passes afterward. No competing open PR or cross-reference for #553 was found when selecting the issue.

Validation

  • Regression fails on upstream master and passes with the fix.
  • Stable API suite: 421 passed, 3 existing ignores.
  • Unstable API/all-features suite: 449 passed, 3 existing ignores.
  • Pre-push checks passed: formatting, stable/unstable all-target checks, no-std checks, Clippy with warnings denied, both test suites, and documentation with warnings denied.
  • Signed commit verified locally; independent code review found no actionable issues.

Formatting note: the current floating nightly (2026-09-27) rewrites existing descriptor macros with unsupported trailing commas, causing compilation failures in src/descriptor/policy.rs. I restored those unrelated edits and ran the pre-push recipes using a temporary copy of the justfile with nightly-2026-08-01, matching the pin proposed in #537. No formatter or unrelated policy changes are included in this PR.

Changelog notice

Fixed excess fees and false insufficient-funds errors when branch-and-bound falls back with optional UTXOs whose effective value is non-positive.

Before submitting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Coin selection fallback selects UTXOs with negative effective value

1 participant