Skip to content

Check the anchor reserve when fee-bumping a splice - #1246

Closed
shubhamkmr04 wants to merge 4 commits into
lightningdevkit:mainfrom
shubhamkmr04:splice-bump-reserve-fees
Closed

shubhamkmr04 wants to merge 4 commits into
lightningdevkit:mainfrom
shubhamkmr04:splice-bump-reserve-fees

Conversation

@shubhamkmr04

Copy link
Copy Markdown
Contributor

Part of #1166. Builds on #1223, so only the last two commits are new here.

bump_channel_funding_fee had no anchor reserve check. A bump of an exact splice-in pays the higher fee from our wallet: LDK shrinks the pending contribution's change or, past its maximum feerate, re-runs coin selection. A bump of a splice-out whose channel balance can't cover the higher fee falls back to funding the whole withdrawal and fees from our wallet, as discussed in #1181. Neither keeps the reserve aside.

Changes

  • Prefactor: Count the funding fee in the anchor reserve check for splice-ins and fee bumps #1223's check of a built splice contribution moves into check_sufficient_onchain_funds_for_contribution, which takes the contribution it replaces as prior_contribution: Option<&FundingContribution>. When it rejects a contribution, it releases what LDK's reserved_inputs and reserved_outputs report: only what the contribution reserved for itself, never the inputs it inherited from the pending splice. A splice-in passes None, so its behavior is unchanged.

  • bump_channel_funding_fee: reads the spendable balance before LDK builds the replacement, then checks that what the replacement takes from our wallet beyond the pending contribution fits in it. Otherwise it fails with InsufficientFunds. This mirrors the on-chain bump_fee_rbf check (spendable >= additional fee):

    • an in-place adjustment counts the extra fee taken from the change;
    • a splice-out funded from the wallet counts the whole withdrawal plus fees, since the pending one took nothing from the wallet.

    Bumps of splice_in_with_all are unaffected. An in-place bump takes nothing more from the wallet, and a rebuild already keeps the reserve as its own output (Build splice_in_with_all from manually selected inputs #1176).

  • Docs for bump_channel_funding_fee and splice_out_max, and a CHANGELOG entry.

Testing

  • splice_in_bump_fee_does_not_spend_anchor_reserve:
    • Node B splices in at 50 sat/vB, which leaves about 3,000 sats of the splice's change spendable next to the 25,000 sat reserve.
    • A bump to 1.5 times the feerate costs about 6,000 sats more. It fails with InsufficientFunds, and the spendable balance is unchanged afterwards.
    • A bump to the RBF minimum costs about 500 more. It succeeds, in place on the same inputs.
  • splice_out_bump_fee_does_not_spend_anchor_reserve:
    • Node A withdraws its full splice-out maximum, so a bump has to be funded from its wallet. The wallet holds the withdrawal plus fees only together with half of the reserve.
    • The bump fails with InsufficientFunds, and the inputs coin selection locked are released.
    • Another coin then confirms while the splice stays in the mempool. The same bump now succeeds, with the withdrawal output unchanged.

Open questions

  1. Locked inputs while a replacement is pending. When a bump of a splice-in re-runs coin selection, the replacement can't reuse the pending splice's inputs, and those stay locked until one candidate confirms. The check here makes sure the reserve holds whichever candidate confirms, but until then part of it can be tied up in those locked inputs. Counting the replacement's whole outflow in that case would be stricter, but still not enough, because the pending splice's change also goes away once it is replaced. Should we be stricter here, or is this window acceptable?

  2. Fee adjustments LDK makes after Count the funding fee in the anchor reserve check for splice-ins and fee bumps #1223's check. LDK can still raise an exact splice-in's fee up to its max_feerate (1.5x) by shrinking its change:

    • via for_acceptor_at_feerate, when our contribution joins a concurrent splice by the counterparty;
    • via for_initiator_at_feerate, at a higher RBF minimum.

    Both happen inside LDK after our check. The only fix I see on our side is checking the fee at max_feerate up front, which is stricter than needed in the common case. As acceptor we don't pay for the shared input and output, so the fee only ends up above what we checked when our contribution has several inputs. Worth handling, or fine as is?

With this, the cases in #1166 are covered, apart from the questions above.

This change was developed with the assistance of Claude Code.

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.
Fee bumps of a pending splice are about to need the check that
`splice_in_inner` runs once LDK has built our contribution: that what
it takes from our wallet, fee included, leaves the anchor reserve in
place. A bump's contribution replaces the pending one, though, so only
what it takes beyond that one should count.

Move the check into `check_sufficient_onchain_funds_for_contribution`,
which takes the replaced contribution as `prior_contribution`. On
rejection it releases what LDK reports through `reserved_inputs` and
`reserved_outputs`, i.e. only what the contribution reserved for
itself, never what it inherited from the pending splice. A splice-in
has no prior contribution and inherits nothing, so its behavior is
unchanged.

Part of lightningdevkit#1166.

Developed with assistance from Claude Code.
`bump_channel_funding_fee` didn't check the anchor reserve at all. A
bump of an exact splice-in pays the higher fee from our wallet: LDK
shrinks the pending contribution's change or, past its maximum
feerate, re-runs coin selection. A bump of a splice-out whose channel
balance can't cover the higher fee falls back to funding the whole
withdrawal and fees from our wallet. Neither keeps the reserve aside.

Read the spendable balance before LDK builds the replacement, as
coin selection locks the inputs it picks. Then check that what the
replacement takes from our wallet beyond the pending contribution fits
in it, as the on-chain `bump_fee_rbf` does for its additional fee. If
it doesn't, release what the replacement reserved and fail with
`InsufficientFunds`. Bumps of `splice_in_with_all` are unaffected: an
in-place bump takes nothing more from the wallet, and a rebuild already
keeps the reserve as its own output.

Part of lightningdevkit#1166.

Developed with assistance from Claude Code.
@ldk-reviews-bot

ldk-reviews-bot commented Nov 18, 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.

@shubhamkmr04

Copy link
Copy Markdown
Contributor Author

Moved into #1223, as requested in its review.

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