Skip to content

Count the funding fee in anchor reserve checks for channel opens - #1204

Open
shubhamkmr04 wants to merge 2 commits into
lightningdevkit:mainfrom
shubhamkmr04:channel-open-reserve-fees
Open

shubhamkmr04 wants to merge 2 commits into
lightningdevkit:mainfrom
shubhamkmr04:channel-open-reserve-fees

Conversation

@shubhamkmr04

Copy link
Copy Markdown
Contributor

Part of #1166.

When opening a channel with an exact amount, we checked that our on-chain funds cover the amount plus the anchor reserve, but not the fee of the funding transaction, which is paid from the same funds. Since #1099 lets the caller choose the fee rate, a high one could spend part of the reserve. The LSPS2 service's check before opening a JIT channel has the same gap.

Changes

  • Channel opens: with an exact amount, all open_channel variants now also fail with InsufficientFunds if the amount exceeds what the corresponding _with_all variant would fund at the same fee rate. That's Wallet::get_max_funding_amount, which already deducts the fee and the anchor reserves, including the new channel's. Previously, an amount that fit next to the reserve but not next to the fee was accepted. The funding transaction then either spent part of the reserve or, without a reserve, failed to build after the counterparty had accepted the channel.
  • LSPS2 service: before opening a JIT channel, the service now does the same check at the ChannelFunding estimate, which is the rate the funding transaction pays. The service gets the fee estimator for this.
  • Docs for the exact-amount variants, and CHANGELOG entries.

The maximum assumes all UTXOs are spent, so near the limit it's slightly conservative for wallets with many small UTXOs.

Testing

  • open_channel_fee_does_not_spend_anchor_reserve: the wallet holds 1,000,000 sats. Opening 970,000 at 100 sat/vB fails with InsufficientFunds, because the ~15,250 sat fee would leave only 14,750 for the 25,000 reserve. The same amount at the regtest estimate opens and keeps the reserve on-chain. On main, the first open succeeds.
  • lsps2_service_funding_fee_does_not_spend_anchor_reserve: the service holds the JIT channel amount plus both anchor reserves plus 100 sats. The existing check passes, but the funding fee doesn't fit, so the service doesn't open the channel and keeps its funds.

Splices are left for a follow-up once #1176 lands, since it reworks the same code. The follow-up covers exact splice_in, and the reserve check when a fee bump falls back to the wallet, as discussed in #1181.

This change was developed with the assistance of Claude Code.

@ldk-reviews-bot

ldk-reviews-bot commented Oct 23, 2026 •

Copy link
Copy Markdown

I've assigned @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-reviews-bot
ldk-reviews-bot requested a review from tnull October 23, 2026 13:38
Opening a channel with an exact amount only checked that our on-chain
funds cover the amount plus the anchor reserve, leaving out the fee of
the funding transaction, which is paid from the same funds. Since the
fee rate can now be chosen freely (lightningdevkit#1099), a high one could spend part
of the reserve, or leave too little to build the funding transaction
once the counterparty had accepted the channel.

Also check that the amount doesn't exceed what opening the channel with
all funds would add at the same fee rate, which already accounts for
the fee and the reserve, and fail with `InsufficientFunds` otherwise.

Part of lightningdevkit#1166.

Developed with assistance from Claude Code.
When acting as an LSPS2 service, we open a JIT channel once its payment
arrives, after checking that our on-chain funds cover the channel amount
plus the anchor reserve. As for exact-amount opens, this left out the fee
of the funding transaction, which is built later at our fee estimate and
paid from the same funds, so it could spend part of the reserve.

Also check that the channel amount doesn't exceed what funding with all
our funds would add at that estimate, and don't open the channel
otherwise. To do so, the LSPS2 service now has access to the fee
estimator.

Part of lightningdevkit#1166.

Developed with assistance from Claude Code.
@shubhamkmr04
shubhamkmr04 force-pushed the channel-open-reserve-fees branch from 8b47d00 to d0a665b Compare October 23, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants