Repository navigation
Check the anchor reserve when fee-bumping a splice - #1246
Closed
shubhamkmr04 wants to merge 4 commits into
Closed
shubhamkmr04 wants to merge 4 commits into
shubhamkmr04 wants to merge 4 commits into
Conversation
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.
|
I've assigned @tnull as a reviewer! |
Contributor
Author
|
Moved into #1223, as requested in its review. |
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. Builds on #1223, so only the last two commits are new here.
bump_channel_funding_feehad 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 asprior_contribution: Option<&FundingContribution>. When it rejects a contribution, it releases what LDK'sreserved_inputsandreserved_outputsreport: only what the contribution reserved for itself, never the inputs it inherited from the pending splice. A splice-in passesNone, 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 withInsufficientFunds. This mirrors the on-chainbump_fee_rbfcheck (spendable >= additional fee):Bumps of
splice_in_with_allare unaffected. An in-place bump takes nothing more from the wallet, and a rebuild already keeps the reserve as its own output (Buildsplice_in_with_allfrom manually selected inputs #1176).Docs for
bump_channel_funding_feeandsplice_out_max, and a CHANGELOG entry.Testing
splice_in_bump_fee_does_not_spend_anchor_reserve:InsufficientFunds, and the spendable balance is unchanged afterwards.splice_out_bump_fee_does_not_spend_anchor_reserve:InsufficientFunds, and the inputs coin selection locked are released.Open questions
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?
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:for_acceptor_at_feerate, when our contribution joins a concurrent splice by the counterparty;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_feerateup 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.