sweep/wallet: consolidate small wallet UTXOs when fees are low
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
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:
- Opportunistic, inside the sweeper. When sweeping inputs with no
deadline pressure (e.g.to_localor 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. - 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. - Manual. An RPC /
lncli wallet consolidatecommand 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lightningnetwork/lnd
-
funding: failure logs print `<nil>` error and zero channel IDPossibly taken @litbot-9000 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
lightningnetwork/lnd#11676 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 85/100
lightningnetwork/lnd#11674 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
lightningnetwork/lnd#11672 ·
Maintainers usually reply within 1 day
-
test flake
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
lightningnetwork/lnd#11663 · 1 comment ·
Maintainers usually reply within 1 day
-
[flake]: lnwallet/test/bitcoind.TestLightningWalletBitcoindRPCPolling/spend_unconfirmed_outputsOpentest flake
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
lightningnetwork/lnd#11642 · 1 comment ·
Maintainers usually reply within 1 day
All issues in lightningnetwork/lnd
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
containers/gvisor-tap-vsock#796 ·
Maintainers usually reply within 2 days
-
external needs:triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
celestiaorg/celestia-node#5448 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
[Bug]: Azure SAS signing uses local time instead of UTC, shifting validity window on non-UTC hostsPossibly taken @huanghaoyuanhhy claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
zilliztech/milvus-backup#1418 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
projectdiscovery/nuclei#8423 ·
Maintainers usually reply within 1 day