sweep/wallet: consolidate small wallet UTXOs when fees are low

Open
#11,522 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
go
Domain
backend, payments

Research direction

Start by reading the sweeper changes in #11485 and how channel funding and SendCoins select wallet UTXOs. Compare the three proposed approaches, then trace how wallet coin selection, fee estimates, RBF, locked coins, and the anchor reserve are handled. Done means a chosen approach consolidates economical UTXOs at low fees while respecting the listed privacy, timing, and transaction-size constraints.

Written by the indexing model from the issue text.

Description

Background

With #11485 the sweeper selects wallet UTXOs for budget input sets in order
of value per weight unit, highest first, and only adds a UTXO if it raises
the fee rate the sweep can reach. Channel funding and SendCoins already use
coin-selection-strategy=largest by default.

As a result, nothing in lnd spends small wallet UTXOs on its own anymore.
Before #11485 the sweeper selected smallest first, which consolidated small
UTXOs as a side effect, but it did so during deadline-critical sweeps, which
is the most expensive time to do it.

Problem

Small UTXOs that are economical at low fee rates (say 5k–50k sats) now
accumulate over time: closes of small channels, swept outputs of small HTLCs,
small on-chain receives. They stay in the wallet until the larger UTXOs are
used up. By then, the wallet often has to spend them under fee pressure,
for example to fund an anchor CPFP before an HTLC deadline. They then add
weight and lower the fee rate the sweep can reach, or they don't pay for
themselves at all and can't be used.

Proposal

Consolidate small, economical wallet UTXOs into fewer outputs while fees are
low, so they are cheap to spend when they are needed. Possible approaches:

  1. Opportunistic, inside the sweeper. When sweeping inputs with no
    deadline pressure (e.g. to_local or second-level HTLC outputs) and the
    current estimate is below a configurable threshold, add small wallet
    UTXOs to the sweep as long as each one pays for its own input weight with
    a margin.
  2. Background consolidation. When the estimate for a long conf target
    (e.g. 144 or 1008 blocks) is below a threshold and the wallet holds more
    than N UTXOs under X sats, publish a low-fee, RBF-signalling self-send
    that merges them.
  3. Manual. An RPC / lncli wallet consolidate command with a fee rate,
    a value ceiling and a max input count, so operators can do it themselves.

Option 3 is the smallest step and is useful on its own; options 1 and 2 could
build on it.

Considerations

  • Uneconomical UTXOs. Only consolidate UTXOs that pay for their own input
    weight at the consolidation fee rate with a clear margin. UTXOs worth less
    than that should be left alone, including dust sent to the wallet by third
    parties.
  • Privacy. Merging UTXOs links them on-chain (common input ownership),
    e.g. outputs from different channels or receives. This should be opt-in or
    at least configurable.
  • Locked coins. An unconfirmed consolidation ties up its inputs and makes
    its output unconfirmed, which can block channel opens and wallet-funded
    sweeps that require confirmed inputs. Low fee rates make this window
    longer, so it should not run while time-sensitive sweeps are pending, and
    it must respect the anchor reserve.
  • Size. Cap the number of inputs per consolidation transaction, and stay
    well below the standardness weight limit.
Dominant language
Go
Stars
8.2k
Forks
2.3k
Avg merge
1d 11h
Merged PRs (30d)
103

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lightningnetwork/lnd

All issues in lightningnetwork/lnd

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.