Skip to content

Count the funding fee in the anchor reserve check for splice-ins - #1223

Open
shubhamkmr04 wants to merge 2 commits into
lightningdevkit:mainfrom
shubhamkmr04:splice-in-reserve-fees
Open

shubhamkmr04 wants to merge 2 commits into
lightningdevkit:mainfrom
shubhamkmr04:splice-in-reserve-fees

Conversation

@shubhamkmr04

@shubhamkmr04 shubhamkmr04 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1166.

When splicing in an exact amount, we checked that our on-chain funds cover the amount on top of the anchor reserve, but not the fee for our contribution to the splice transaction, which is paid from the same funds. Coin selection doesn't keep the reserve aside, so the fee could come out of it.

Changes

  • Prefactor: check_sufficient_onchain_funds now returns the spendable balance it checked the amount against.
  • Exact splice_in: once LDK has built the contribution, we check that what it takes from our wallet, its inputs minus its change, fits in that balance, and fail with InsufficientFunds otherwise. LDK runs coin selection with the shared input and output, so the change is net of the whole fee, and inputs minus change is exactly the amount plus our fee. Checking the built contribution also avoids estimating the fee up front, which Build splice_in_with_all from manually selected inputs #1176 moved away from for splice_in_with_all.
  • Since Fix wallet UTXO reuse for funding transactions and onchain spends #1037, coin selection locks the inputs it picks, which takes them off the spendable balance. So the check of the amount alone now runs right before coin selection and provides the balance from before it. A plain lack of funds still fails before coin selection. If the built contribution doesn't fit, we release what coin selection locked for it.
  • Docs for splice_in, and a CHANGELOG entry.

Testing

  • splice_in_fee_does_not_spend_anchor_reserve: node B holds 1,000,000 sats with a 25,000 sat anchor reserve. Splicing in 970,000 at 50 sat/vB fails with InsufficientFunds, because the ~12,500 sat fee would leave only ~17,500 for the reserve, and B's spendable balance is unchanged afterwards. The same amount at the regtest estimate splices in and keeps the reserve on-chain.

Fee bumps are left for a follow-up: the reserve check when a bump of an exact splice-in shrinks its change or re-runs coin selection, and when a bump of a splice-out 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 Nov 8, 2026 •

Copy link
Copy Markdown

👋 Thanks for assigning @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 November 8, 2026 06:49
@shubhamkmr04
shubhamkmr04 force-pushed the splice-in-reserve-fees branch 2 times, most recently from afede9a to 39ef2ad Compare November 11, 2026 08:57
@shubhamkmr04
shubhamkmr04 force-pushed the splice-in-reserve-fees branch from 39ef2ad to 0c1cba9 Compare November 17, 2026 12:15
@tnull tnull added this to the 0.8 milestone Nov 17, 2026

@tnull tnull left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase now #1204 is in.

@shubhamkmr04
shubhamkmr04 force-pushed the splice-in-reserve-fees branch from 0c1cba9 to 0689499 Compare November 17, 2026 13:23
Splicing in an exact amount is about to also check what its built
contribution takes from our wallet, fee included. Coin selection locks
the inputs it picks, which takes them off the spendable balance, so that
check needs the balance from before coin selection.

Have `check_sufficient_onchain_funds` return the spendable balance it
checked the amount against, so that the splice-in can reuse it.

Part of lightningdevkit#1166.

Developed with assistance from Claude Code.
Splicing in an exact amount only checked that our on-chain funds cover
the amount on top of the anchor reserve. The fee for our contribution to
the splice transaction is paid from the same funds, though, and coin
selection doesn't keep the reserve aside, so the fee could be taken
from it.

Once the contribution is built, also check that what it takes from our
wallet, its inputs minus its change, fits in the funds beyond the
reserve. Coin selection locks the inputs it picks, which takes them off
the spendable balance, so compare against the balance from before it:
the check of the amount alone now runs right before coin selection and
provides it. If the contribution doesn't fit, release what coin
selection locked for it and fail with `InsufficientFunds`. A plain lack
of funds still fails before coin selection.

Part of lightningdevkit#1166.

Developed with assistance from Claude Code.
@shubhamkmr04
shubhamkmr04 force-pushed the splice-in-reserve-fees branch from 0689499 to 915b7dd Compare November 17, 2026 13:40
@shubhamkmr04
shubhamkmr04 requested a review from tnull November 17, 2026 15:35
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.

3 participants