Skip to content

LSPS2: Support splice-in for JIT provisioning - #65

Open
martinsaposnic wants to merge 1 commit into
lightning:masterfrom
martinsaposnic:lsps2-splicing
Open

martinsaposnic wants to merge 1 commit into
lightning:masterfrom
martinsaposnic:lsps2-splicing

Conversation

@martinsaposnic

Copy link
Copy Markdown
Contributor

Adapts the current LSPS2 spec to also support splicing a channel instead of opening a channel If the LSP and client already share a channel that supports splicing.

Comment thread blip-0052.md
`payment_size_msat - opening_fee`, plus any reserve needed on the LSP
side.
The LSP determines the funding delta and resulting channel balances.
The LSP MUST ensure the resulting channel balances allow forwarding at least

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we discussed this elsewhere, but I do think it would be easier in terms of backwards compat., "no surprisees", etc, if we mandate that the LSP always splices in at least payment_size_msat. I.e., the open_channel flow would be untouched, and if the LSP splices it's required to add exactly the same liquidity to the channel as if it was opening a new channel.

You already solve this with the paragraph below, but here, we also need to clarify the new balance should be at least old_balance + payment_size_msat - opening_fee.

Comment thread blip-0052.md
the LSP MAY satisfy an LSPS2 buy by performing a splice-in instead of opening
a new channel. This choice does not change any LSPS2 messages or parameters
and is transparent to the client.
* When choosing splicing, the LSP SHOULD splice-in the full amount of the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's make this SHOULD a MUST, otherwise it might become very confusing to the client how to track balances/what to expect. If the LSP can use previously-paid liquidity to forward the payment, the client would either be doulby charged or would need to have a way to learn about this beforehand to be able to reevaluate which fee rate offering they deem acceptable. To keep it simple, we need to require splicing to be 1:1 the same contract as opening a new channel.

Comment thread blip-0052.md
* If satisfying an LSPS2 buy via splice-in, the LSP MUST forward only after the
channel is no longer quiescent, i.e., after both peers have exchanged the
`tx_signatures` message for the splice transaction per [Splicing][]. The LSP
MUST NOT require the `splice_locked` message before forwarding.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm why MUST NOT here?

Comment thread blip-0052.md

Timeouts and fallback:

* The `opening_fee_params.valid_until` also applies to splice negotiation. If a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we also need to clarify how the min_lifetime of the channel is changed during splice-in?

Note this might be an issue where we get to the limits of what is easily expressible with LSPS2: if the client already is close to the end of the lifetime of the original channel, the LSP probably doesn't want to renew the full channel for the opening fee of the new incoming payment.

So the LSP has three options:

  1. Price-in the TLV of the previously-provisioned liquidity into the offering for the new payment (although that is race-y, given the valid_until periods could overlap). That in turn means that the client sees higher rates from their LSP, without explicitly knowing why/what they're getting into.
  2. Still default to open_channel to keep the two flows independent.
  3. Decidedly splice-out the original balance some time after the min_lifetime. Maybe we should clarify that this is an option for the LSP here, which makes it all the more important that they MUST add the full payment_size_msat on top rather than 'merging' the channel balances.

Comment thread blip-0052.md

* If the LSP and client already share a channel that supports splicing (i.e.,
splicing was negotiated for that specific channel per [Splicing][]),
the LSP MAY satisfy an LSPS2 buy by performing a splice-in instead of opening

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SHOULD?

@tnull

tnull commented Dec 10, 2025

Copy link
Copy Markdown
Contributor

@martinsaposnic Do you still intend to move forward with this? Should I take this one over?

@Jolah1

Jolah1 commented Jul 20, 2026

Copy link
Copy Markdown

This would unblock lightningdevkit/ldk-node#763, which is gated on this PR. Since it's been inactive since Sep 2025, I'd be glad to help push it forward addressing @tnull's review and rebasing If its still open.

Happy to open a follow-up commit along those lines if that direction sounds right.

@tnull

tnull commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

This would unblock lightningdevkit/ldk-node#763, which is gated on this PR. Since it's been inactive since Sep 2025, I'd be glad to help push it forward addressing @tnull's review and rebasing If its still open.

Happy to open a follow-up commit along those lines if that direction sounds right.

Thanks for the offer, but we're in the middle of figuring out how exactly to integrate BOLT12 with bLIP-52 on the LDK side, which might or might not have implications on how splicing needs to be integrated. Once we've made progress there I'll take this PR over myself.

@Jolah1

Jolah1 commented Jul 20, 2026

Copy link
Copy Markdown

This would unblock lightningdevkit/ldk-node#763, which is gated on this PR. Since it's been inactive since Sep 2025, I'd be glad to help push it forward addressing @tnull's review and rebasing If its still open.
Happy to open a follow-up commit along those lines if that direction sounds right.

Thanks for the offer, but we're in the middle of figuring out how exactly to integrate BOLT12 with bLIP-52 on the LDK side, which might or might not have implications on how splicing needs to be integrated. Once we've made progress there I'll take this PR over myself.

Duly noted.

amackillop added a commit to amackillop/ldk-node that referenced this pull request Nov 23, 2026
The LSPS2 service opens a new channel for every buy, even to a client
it already has a channel with (lightningdevkit#763). lightning/blips#65 lets the LSP
splice into an existing channel instead and fall back to an open when
splicing is not possible. This adds the choice as a pure function, so
the rules are tested apart from the channel manager; the OpenChannel
handler does not act on it yet.

A client that cannot be spliced with gets a new channel, as today:

- one that did not signal option_splice, an init feature BOLT 2
  negotiates per connection rather than per channel;
- any client under the client-trusts-LSP model, which withholds the
  funding transaction until the client claims, while LDK broadcasts a
  splice once tx_signatures are exchanged.

Otherwise a buy is spliced into a usable channel with room for the
amount to forward. A channel that is not yet usable, because its
funding awaits channel_ready or the peer is reestablishing it, is
waited for rather than joined by a second channel, unless the client
already accepted it with too low a maximum. Among several channels the
largest wins and then the lowest channel id, for a splice and for a
wait alike. A buy opens a channel only when no channel exists or none
can carry it, now or once usable; a channel shutting down counts as
none.

Room is the channel's outbound_htlc_maximum_msat less the HTLCs already
in flight to the client. That maximum is the smaller of the client's
max_htlc_value_in_flight_msat, which LDK fixes when the channel opens
and no splice changes, and the channel's value less both reserves,
which a splice raises. LDK does not expose the first alone, so the
check is conservative: a payment above the maximum but within the
in-flight limit, as on a channel spliced out earlier, gets an open.

How long a wait may last is left to the handler, which holds the
intercepted HTLCs meanwhile. A channel with a splice already being
negotiated counts as usable here; serialising splices to one client is
also left to the handler. The open reasons are kept as a type so the
handler can log why it did not splice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
amackillop added a commit to amackillop/ldk-node that referenced this pull request Nov 25, 2026
lightning/blips#65 lets an LSPS2 service provide a buy's liquidity by
splicing it into a channel it already has with the client, instead of
opening another. 0109ab2 added the choice between the two; this serves
it.

On OpenChannel the service now plans the buy from the client's channels
and init features. For a splice it binds the buy to the channel through
lightning-liquidity's splice_initiated, then splices in the buy's amount
plus the configured over-provisioning, at the fee rate an open would use
and funded from the service's confirmed coins. SpliceNegotiated and
SpliceNegotiationFailed are forwarded to splice_negotiated and
splice_failed. The ChannelReady LDK emits once the splice locks serves
the buy, which then forwards its payment as an open's ChannelReady
would. A splice that can't be started unbinds the buy and fails the
payment back, as a failed open does.

A buy can't always be served on its OpenChannel event: its channel may
be pending or await another buy's splice, and a restart leaves buys
whose event was handled but which have no channel yet.
lightning-liquidity keeps such buys listed, so the service serves a
client's listed buys on its OpenChannel event, whenever the client
connects, whenever one of its channels becomes ready or closes, and
whenever a splice of one fails. A buy whose client is offline when it is
served is still failed back, as before. Each trigger queues the client,
and one task serves the queue, so a buy is never served twice at once.
It is a task of its own because a peer connection is handled
synchronously, and because the liquidity event loop's select! would drop
an event being handled there, a splice in the middle of being started
included.

The splice tests run both ends with zero-fee commitments and no client
reserve, as a client of this service would, and so with a bitcoind chain
source, as the test Esplora can't submit the packages zero-fee
commitments use. A splice spends confirmed coins only, so a test
confirms the service's change before each splice.

lsps2_client_service_integration now expects its variable-amount buy,
which fits the client's channels, to be spliced in unless the client
trusts the LSP.

Left for later: a channel that is briefly unable to take the splice, as
one of our own contributions or an RBF round is pending or its fee rate
is above ours, fails the buy back rather than deferring it, which needs
the splice-in steps to report why they failed; they also duplicate
Node::splice_in_inner. A buy whose binding was persisted but whose
splice was never started, after a crash or a failed persist, stays
bound, which needs the bindings reconciled with LDK's pending splices on
startup. An error recording a negotiated splice, a failed persist
included, is only logged, as lightning-liquidity reports it as it
reports a splice no buy awaits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
amackillop added a commit to amackillop/rust-lightning that referenced this pull request Nov 29, 2026
An integrator may defer a buy listed by buys_awaiting_channel, for
example while the client's only channel is still pending or its HTLCs
in flight leave no room for the payment, and serve it later by a
splice. lightning/blips#65 bounds that wait: "The
`opening_fee_params.valid_until` also applies to splice negotiation.
If a splice cannot complete before `valid_until`, the LSP MAY fail the
buy or fall back to opening a new channel." The listing gave the
integrator no way to know when that is, since it held only the buy's
amounts and SCIDs, and the opening_fee_params live in the service's
state.

BuyAwaitingChannel now carries the buy's valid_until, so an integrator
can bound how long it defers a listed buy. It changes no persisted
state and no behaviour of the service: what to do once the time has
passed stays the integrator's choice, as the bLIP leaves it. A buy
already bound to a splice is not listed; that splice ends through
splice_negotiated and channel_ready or through splice_failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
amackillop added a commit to amackillop/ldk-node that referenced this pull request Nov 29, 2026
A buy from a client that already has a channel is spliced into it.
When that is not possible, the service opens a new channel beside it
(0109ab2). That happens when the client lacks option_splice, when the
service uses the client-trusts-LSP model, or when no channel can carry
the payment. lightning/blips#65 allows this: "If splicing cannot be
negotiated or no splicing-capable channel exists with the client, the
LSP MAY open a new channel instead". That is a MAY, not a MUST, and
we read it as leaving failing the buy back open too.

Some LSPs give each client one channel, so the client sees one
balance. For them a second channel is the wrong answer to all three
cases. The last one is easy to hit. A client that requests two JIT
invoices before paying either gets a first channel sized for the
first payment. A splice does not raise the client's
max_htlc_value_in_flight_msat, which is fixed when the channel opens,
so a larger second payment can never fit, and the second buy opens a
second channel.

LSPS2ServiceConfig gains splice_fallback, an LSPS2SpliceFallback. With
OpenChannel, the service behaves as before; it is the enum's Default,
though callers building the config, in Rust or through the bindings,
must name it. With FailPayment, the buy's payment is failed back as
for a failed channel open, and the reason is logged at info. A retry
fails the same way unless the reason changed, such as a client that
reconnects signaling option_splice. Together with client_trusts_lsp it
fails every buy from a client that has a channel, which the field's
documentation says. A client with no channel, or with only ones
shutting down, still gets one opened under either setting. The
splice-or-wait choice does not change.

Refusing the buy request itself would tell the client before it hands
out an invoice, but it does not cover the case above: both buys are
made before the first channel exists.

JitLiquidityPlan now separates Open, for a client without a channel,
from OpenBeside and FailBack, which carry a NoSpliceReason (the old
OpenReason without NoChannel). The plan therefore cannot fail back a
buy from a client that has no channel. Adding the field breaks code
that builds LSPS2ServiceConfig with a struct literal.

Unit tests cover each NoSpliceReason under FailPayment, a client with
no channel still getting one opened, and splices and waits being
unaffected. An integration test opens the client's channel, then pays
a JIT invoice larger than that channel. The service logs the fail-back
for AboveHtlcMaximum, the payment fails, the client keeps one channel,
and the service emits no event. With FailPayment mapped to an open, the
test fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

4 participants