Skip to content

Round LSPS2 JIT channel amounts up to whole sats - #1134

Open
tnull wants to merge 1 commit into
lightningdevkit:mainfrom
tnull:2026-10-fix-lsps2-channel-rounding
Open

tnull wants to merge 1 commit into
lightningdevkit:mainfrom
tnull:2026-10-fix-lsps2-channel-rounding

Conversation

@tnull

@tnull tnull commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

When acting as an LSPS2 service, the amount of a JIT channel was derived from the millisatoshi forward amount with integer division, i.e., it was rounded down. For forward amounts that aren't a whole number of satoshis the channel could end up too small to carry the intercepted HTLC. In the LSP-trusts-client flow the service has already paid the funding fee at that point, and any client can trigger this remotely.

We now round up to the next whole satoshi when converting, so the opened channel always has enough capacity for the forward.

Reported by Project Loupe.

Co-Authored-By: HAL 9000

When acting as an LSPS2 service, the amount of a JIT channel was derived
from the millisatoshi forward amount with integer division, i.e., it was
rounded down. For forward amounts that aren't a whole number of satoshis
the channel could end up too small to carry the intercepted HTLC. In the
LSP-trusts-client flow the service has already paid the funding fee at
that point, and any client can trigger this remotely.

We now round up to the next whole satoshi when converting, so the opened
channel always has enough capacity for the forward.

Reported by Project Loupe.

Co-Authored-By: HAL 9000
@ldk-reviews-bot

ldk-reviews-bot commented Oct 8, 2026 •

Copy link
Copy Markdown

I've assigned @tankyleo 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.

Comment on lines +451 to +452
let channel_amount_sats =
(amt_to_forward_msat + over_provisioning_msat).div_ceil(1000);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The div_ceil fix looks good, and I like that the funds check (L462) and create_channel use the same variable. One caveat: the channel isn't guaranteed to have enough usable capacity for the forward.

With channel_over_provisioning_ppm = 0, the channel is sized to exactly ceil(forward) sats and funded entirely by the LSP (push_msat = 0). The LSP still needs to account for the client's reserve (~1% by default), commitment fees, and anchor outputs, so the HTLC may not fit.

Could we either scope the PR description to fixing sub-sat truncation, or account for the reserve and fees explicitly and document the minimum sensible channel_over_provisioning_ppm?

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