Repository navigation
channeld: enforce the channel reserve in splice negotiation - #111
Merged
Merged
Conversation
…serve Changelog-Fixed: Splicing refuses a splice that leaves a side which adds an output or takes funds out below the channel reserve for the new capacity.
Changelog-Changed: A splice script's percentage of a channel, such as `100%`, is now of the funds that can leave while keeping the channel reserve and, for the channel's opener, the commitment fee for one more HTLC, not of the whole balance.
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.
Summary
Splice negotiation never checked the channel reserve. A peer could splice its balance out to its wallet and keep almost nothing in the channel, leaving it with nothing to lose by broadcasting a revoked commitment. BOLT 2 requires the receiving node to send
tx_abortwhen a side that added an output other than the channel funding output ends below the reserve for the new capacity, and channeld only had a TODO there.check_balances()now aborts the splice when a side that adds an output, or takes funds out of the channel by any route (fees included), would keep less than the reserve for the new capacity. Both sides are checked, so we also refuse to send such a splice ourselves.channel_reserve_for_capacity()incommon/so both daemons share it.<channel> -> 100%still works rather than always aborting. As opener we also keep the commitment fee for one more HTLC at the marginal feerate, plus the anchors, which is what adding an HTLC already requires, so the channel stays usable after the splice. A smaller percentage is now a share of that amount, so<channel> -> 50%takes half of what100%would.Lightning Fork already enforces the same rule on both sides (an added output or a negative contribution, against 1% of the new capacity), so this matches what it sends and accepts.
Test plan
test_splice_out_below_reserve: l2 splices out keeping 5,049 sat of a 505,049 sat channel, one below the 5,050 sat reserve. Both l1 and l2 sendtx_aborton their own checks, no inflight is left, and keeping exactly 5,050 sat then splices, confirms and locks.test_splice_in_with_change_below_reserve: l2, with no channel balance, splices in 5,000 sat with a change output and is refused against the 10,050 sat reserve. 20,000 sat then goes through.test_splice_out_all_keeps_reserve:<channel> -> 100%leaves l2 exactly the 5,050 sat reserve of the 505,050 sat channel that remains, and locks.test_splice_out_all_opener_keeps_fee: the opener splicing out100%of its whole channel keeps 10,583 sat, which is the 546 sat dust-limit reserve, 9,377 sat of commitment fee and 660 sat for the anchors.test_script_two_chan_splice_outtook everything l2 held out of its channel with l1, leaving 0 against a 9,000 sat reserve. It now takes 90,000 sat, keeping 10,000 sat above the 9,100 sat reserve.test_script_two_chan_splice_n,_ooand_psplice out50%of the opener's 500,000 sat in a 1,000,000 sat channel.100%there would keep 15,201 sat (the 5,152 sat reserve plus 10,049 sat of fee headroom), so50%takes 242,399 sat.tests/test_splice.py,tests/test_splicing.py,tests/test_splicing_disconnect.py,tests/test_splicing_insane.pyandtests/test_opening.pypass locally, with and without dual funding.