Skip to content

LSP-Plugin: Add MPP support#8948

Open
nepet wants to merge 11 commits intoElementsProject:masterfrom
nepet:plugins/lsps2/mpp-fsm
Open

LSP-Plugin: Add MPP support#8948
nepet wants to merge 11 commits intoElementsProject:masterfrom
nepet:plugins/lsps2/mpp-fsm

Conversation

@nepet
Copy link
Member

@nepet nepet commented Mar 18, 2026

Important

26.04 FREEZE March 11th: Non-bugfix PRs not ready by this date will wait for 26.06.

RC1 is scheduled on March 23rd

The final release is scheduled for April 15th.

Checklist

Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:

  • The changelog has been updated in the relevant commit(s) according to the guidelines.
  • Tests have been added or modified to reflect the changes.
  • Documentation has been reviewed and updated as needed.
  • Related issues have been listed and linked, including any that this PR closes.
  • Important All PRs must consider how to reverse any persistent changes for tools/lightning-downgrade

Introduces a state-machine-based approach to managing LSPS2 JIT channel sessions, replacing the previous ad-hoc state tracking with a structured FSM that tracks payment collection from initial channel open through HTLC forwarding to completion.

@nepet nepet force-pushed the plugins/lsps2/mpp-fsm branch from dc5b671 to 44f666d Compare March 18, 2026 23:33
@nepet nepet requested a review from cdecker March 18, 2026 23:36
nepet added 9 commits March 19, 2026 11:33
Introduce a state-machine-based approach to managing LSPS2 JIT channel
sessions. The FSM tracks payment collection from initial channel open
through HTLC forwarding to completion, replacing the previous ad-hoc
state tracking.

Also adds Sum trait for Msat and PartialEq for protocol types needed
by the FSM.

Changelog-Experimental: LSPS2 session state machine for JIT channels
Introduce a session actor that runs the FSM in an async task and
communicates side effects through an ActionExecutor trait. This
separates state machine logic from I/O concerns like RPC calls and
datastore writes.
Add SessionManager that routes incoming HTLCs to the correct session
actor by payment hash, replacing the previous handler-based approach.

Reworks the policy plugin API and integrates the CLN RPC executor,
unifies HTLC handling into the session FSM, and removes the now
deprecated handler.rs.
Add integration tests covering the full session lifecycle: channel
opening, HTLC forwarding, payment collection, and session completion.
Implement crash recovery for LSPS2 sessions so that in-progress JIT
channel sessions survive plugin restarts.

Adds recovery traits and datastore methods, a RecoveryProvider
implementation for ClnApiRpc, forward monitoring for recovered
sessions, and integration tests for recovery scenarios. Makes
broadcast_tx and abandon_session idempotent to handle replayed
actions safely.
Reduce DatastoreProvider from many methods to 5, with the actor
owning the DatastoreEntry and driving all writes through the actor
loop. This makes the datastore boundary simpler and testable.
Add an EventSink trait that decouples session event reporting from the
transport layer. Includes a composite sink and a channel-based
implementation. Wires EventSink through SessionActor and
SessionManager, and persists payment_hash in DatastoreEntry.
Replace CLN-specific types (cln_rpc PublicKey, ShortChannelId alias)
with standalone alternatives, feature-gate CLN dependencies behind a
"cln" feature flag, split ClnApiRpc into focused adapter structs, and
refactor Lsps2ServiceHandler generics for cleaner trait boundaries.

This makes the lsps2 core reusable outside of CLN.
Merge BlockheightProvider into Lsps2PolicyProvider, extract
check_cltv_timeout helper in the session FSM, flatten recovery
branching in SessionManager, simplify the actor loop with
convert_input and tokio::select!, and remove the unused
CollectTimeout ActorInput variant.
@nepet nepet force-pushed the plugins/lsps2/mpp-fsm branch from 44f666d to df7c132 Compare March 19, 2026 10:33
nepet added 2 commits March 19, 2026 14:55
We actually only use this in tests

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
After restart, recovered session actors were stored in a separate
recovery_handles Vec, unreachable by the forward_event notification
path that routes via the sessions HashMap. This caused intermittent
CI failures where on_payment_settled could not find the session and
the internal forward-monitoring loop failed to detect settlement.

Register recovered sessions in the sessions HashMap keyed by
payment_hash so forward_event notifications reach them directly.
For already-settled forwards, recover into Broadcasting state so
the actor self-drives to completion without needing forward_event
re-delivery. Remove the now-redundant internal polling loop
(get_forward_activity + wait_for_forward_resolution).
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.

1 participant