Skip to content

Avoid dust coin selection in transactions - #548

Merged
Jossec101 merged 7 commits into
mainfrom
avoid-dust-coin-selection
Jul 30, 2026
Merged

Avoid dust coin selection in transactions#548
Jossec101 merged 7 commits into
mainfrom
avoid-dust-coin-selection

Conversation

@Jossec101

@Jossec101 Jossec101 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Implement logic to prevent the selection of dust coins during transaction creation, this shall prevent dust attacks.

Dust UTXOs are tagged accordinly and cannot be frozen/unfrozen.

image

Add MINIMUM_UTXO_VALUE_SATS constant (default 546 sats, configurable via
environment variable) and use it to filter dust UTXOs out of coin
selection both server-side in NodeGuardService and in the Wallets UI.

- Introduce MINIMUM_UTXO_VALUE_SATS in Constants with env-var override
- Server-side: append dust outpoints to ignoreOutpoints so selection
  strategies don't count them toward requested amounts (which would
  otherwise result in short selections after local stripping)
- UI: mark dust UTXOs with a warning "dust" badge and disable the
  freeze toggle for them, since they are auto-excluded
@Jossec101
Jossec101 enabled auto-merge (squash) July 30, 2026 11:50
When `NBXPLORER_ENABLE_CUSTOM_BACKEND` is enabled, locked, frozen and
dust UTXOs were counted by the backend towards the requested amount and
only stripped by the local filter afterwards, producing selections that
fell short of the target.

- Extract `GetLockedFrozenOutpoints` from `FilterLockedFrozenUTXOs` so
  the outpoint list can be reused.
- Fetch all UTXOs, compute dust outpoints (<= `MINIMUM_UTXO_VALUE_SATS`)
  and merge them with locked/frozen outpoints, then forward the combined
  list to `GetUTXOsByLimitAsync` as `ignoreOutpoints`.
- Make `Constants.NBXPLORER_ENABLE_CUSTOM_BACKEND` mutable so tests can
  toggle the custom-backend path.
Comment thread src/Services/CoinSelectionService.cs Outdated
@Jossec101
Jossec101 requested a review from RodriFS July 30, 2026 12:12
@Jossec101
Jossec101 disabled auto-merge July 30, 2026 13:33
…ern of maximum amount of ignored outpoints.

When `NBXPLORER_ENABLE_CUSTOM_BACKEND` is enabled and the custom UTXO
selection endpoint throws, callers previously got a hard failure. Wrap
the custom-backend path in a try/catch and degrade to the plain
`GetUTXOsAsync` listing on error, matching the code path used when the
custom backend is disabled. The local filter still strips locked,
frozen and dust UTXOs, so none can leak through. A warning is logged
with the requested strategy for observability.

Adds a unit test covering the failure path to ensure the fallback
returns only the available UTXO and excludes locked and dust ones.
Restore the previous GetAvailableUtxos behavior where a failing custom
NBXplorer backend yields an empty UTXO selection instead of surfacing an
error to the caller. NBXplorerService.GetUTXOsByLimitAsync now correctly
throws on non-success responses (replacing the unreachable empty return
and fixing `throw e` stack rewrite), so NodeGuardService wraps the call
in try/catch, logs a warning, and falls back to an empty UTXOChanges.

Adds a unit test covering the custom-backend failure path.
Comment thread src/Helpers/Constants.cs Outdated
Comment thread src/Services/CoinSelectionService.cs Outdated
Comment thread src/Rpc/NodeGuardService.cs Outdated
Comment thread src/Rpc/NodeGuardService.cs Outdated
… redundant RPC dust filter

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Jossec101
Jossec101 requested a review from markettes July 30, 2026 14:49
@Jossec101
Jossec101 merged commit 4af7dee into main Jul 30, 2026
5 checks passed
@Jossec101
Jossec101 deleted the avoid-dust-coin-selection branch July 30, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants