Skip to content

Don't trim HTLCs when calculating the commit tx fee including the fee spike multiple#4574

Draft
tankyleo wants to merge 11 commits intolightningdevkit:mainfrom
tankyleo:2026-04-reserve-breach
Draft

Don't trim HTLCs when calculating the commit tx fee including the fee spike multiple#4574
tankyleo wants to merge 11 commits intolightningdevkit:mainfrom
tankyleo:2026-04-reserve-breach

Conversation

@tankyleo
Copy link
Copy Markdown
Contributor

Based on #4550, draft until that PR goes in, otherwise good for review

tankyleo added 11 commits April 22, 2026 02:32
As a result, we now validate that both commitments retain at least one
output under the new funding scope, which is crucial for zero-reserve
channels.
We previously determined this value by subtracting the htlcs, the
anchors, and the commitment transaction fee. This ignored the reserve,
as well as the at-least-one-output requirement in zero-reserve channels.

This new field now accounts for both of these constraints. It can be
seen as the total spliceable balance from the channel.
This is equivalent to the previous commit, see the debug assertions
added in the previous commit. We now also get to communicate the
exact maximum back to the user, instead of some "balance is lower
than our reserve" message, which is hard to react to.
As a channel fundee, we previously could send HTLCs such that a fee
spike in a legacy channel triggered the no-outputs case in zero-reserve
channels. We now also maintain a buffer from the no-outputs case when
we are the channel fundee.
We previously accounted for HTLC trims at the spiked feerate when
calculating the reserved commitment transaction fees.

This could cause an underestimate of the real current commitment fee at
the current channel feerate. This is because a 2x increase in the
feerate could trim enough HTLCs to result in a smaller commitment
transaction fee.

Also, the previous code only reserved the fee for an exact 2x increase
in the feerate, instead of reserving the fee for any increase in the
feerate between 1x to 2x.

Fixes lightningdevkit#4563.
Focus on reserved commitment transaction fees, and available capacity in
the 0-reserve, fundee case.
In the next commit, we will make changes to how the fee spike buffer is
calculated which require the real feerate to always be passed to
`tx_builder::get_next_commitment_stats`, even in the case where we
include a fee spike multiple.
We previously accounted for HTLC trims at the spiked feerate when
calculating the commitment transaction fee including the fee spike
multiple.

This only ensured that the funder of the channel could afford the
commitment transaction fee for an exact 2x increase in the feerate.

Now, we check that the funder can cover any increase in the feerate
between 1x to 2x.
Make sure it correctly does not trim HTLCs at the spiked feerate, see
the previous commit for further details.
@ldk-reviews-bot
Copy link
Copy Markdown

👋 Hi! I see this is a draft PR.
I'll wait to assign reviewers until you mark it as ready for review.
Just convert it out of draft status when you're ready for review!

@tankyleo tankyleo self-assigned this Apr 23, 2026
@tankyleo tankyleo moved this to Goal: Merge in Weekly Goals Apr 23, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 94.57831% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.09%. Comparing base (3278ece) to head (89ef026).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channel.rs 91.97% 10 Missing and 5 partials ⚠️
lightning/src/ln/channel_state.rs 66.66% 1 Missing ⚠️
lightning/src/ln/channelmanager.rs 0.00% 1 Missing ⚠️
lightning/src/routing/router.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4574      +/-   ##
==========================================
+ Coverage   87.07%   87.09%   +0.02%     
==========================================
  Files         161      161              
  Lines      109248   109332      +84     
  Branches   109248   109332      +84     
==========================================
+ Hits        95127    95228     +101     
+ Misses      11640    11621      -19     
- Partials     2481     2483       +2     
Flag Coverage Δ
fuzzing-fake-hashes 31.11% <73.24%> (+0.16%) ⬆️
fuzzing-real-hashes 22.80% <37.89%> (+0.19%) ⬆️
tests 86.18% <94.57%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Goal: Merge

Development

Successfully merging this pull request may close these issues.

2 participants