Repository navigation
Count the funding fee in anchor reserve checks for channel opens - #1204
Open
shubhamkmr04 wants to merge 2 commits into
Open
shubhamkmr04 wants to merge 2 commits into
shubhamkmr04 wants to merge 2 commits into
Conversation
|
I've assigned @tnull as a reviewer! |
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
force-pushed
the
channel-open-reserve-fees
branch
from
October 23, 2026 14:54
8b47d00 to
d0a665b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
open_channelvariants now also fail withInsufficientFundsif the amount exceeds what the corresponding_with_allvariant would fund at the same fee rate. That'sWallet::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.ChannelFundingestimate, which is the rate the funding transaction pays. The service gets the fee estimator for this.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 withInsufficientFunds, 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. Onmain, 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.