Skip to content

Conversation

@tnull
Copy link
Contributor

@tnull tnull commented Dec 12, 2025

Closes #3480.

We 'refactor' (close to rewrite) the LSPS1ServiceHandler, add persistence for the service state, add some more critical API paths, add test coverage, and finally remove the cfg(lsps1_service) flag.

TODO:

  • Allow to update payment status
  • Improve API docs. In particular mention users need to monitor channel and payment status and update the tracked state whenever something changes.
  • Add test coverage for expired state pruning

Will be draft until these are done.

martinsaposnic and others added 3 commits December 11, 2025 13:37
We add the first LSPS1 integration test. This is based on the unfinished
work in lightningdevkit#3864, but
rebased to account for the new ways we now do integration test setup.
.. for which we got warnings
We previously considered tracking payment confirmations as part of the
handler. However, we can considerably simplify our logic if we stick
with the current approach of having the LSPs track the payment status
and update us when prompted through events.
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Dec 12, 2025

👋 Hi! This PR is now in draft status.
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!

@tnull tnull marked this pull request as draft December 12, 2025 15:28
@tnull tnull force-pushed the 2025-11-lsps1-refactor branch from bfda812 to 3cdd1c7 Compare December 12, 2025 15:37
tnull added 22 commits December 12, 2025 16:57
Now that we don't do on-chain tracking in LSPS1, we can drop quite a few
`LiquidityManager` parameters and generics, which were only added in
anticipation of tracking on-chain state.
We move the `PeerState` related types to a new module. In the following
commits we'll bit-by-bit drop the `pub(super)`s introduced here,
asserting better separation of state and logic going forward.
.. we will re-add a proper state machine in a later commit, but for now
we can just drop all of this half-baked logic that doesn't actually do
anything.
.. requiring less access to internals
Previously, we'd directly access the internal `outbound_` map of
`PeerState`. Here we refactor the code to avoid this.

Note this also highlighted a bug in that we currently don't actually
update/persist the order state in `update_order_state`. We don't fix
this here, but just improve isolation for now, as all state update
behavior will be reworked later.
We introduce two new methods on `PeerState` to avoid direct access to
the internal `pending_requests` map.
The `OutboundChannel` construct simply wrapped `ChannelOrder` which we
can now simply use directly.
We here remember and update the order state and channel details in
`ChannelOrder`
Since we by now have the `TimeProvider` trait, we might as well use it
in `LSPS1ServiceHandler` instead of requiring the user to provide a
`created_at` manually.
In the future we might want to inline the fields in `LSPS1ServiceConfig`
(especially once some are added that we'd want to always/never set for
the user), but for now we just make the `supported_options` field in
`LSPS1ServiceConfig` required, avoiding some dangerous `unwrap`s.
.. otherwise we'd keep the request around forever.
Previously, we'd use an event to have the user check the order status
and then call back in. As we already track the order status, we here
change that to a model where we respond immediately based on our state
and have the user/LSP update that state whenever it detects a change
(e.g., a received payment, reorg, etc.). In the next commmit we will
add/modify the corresponding API methods to do so.
We add the serializations for all types that will be persisted as part
of the `PeerState`.
We follow the model already employed in LSPS2/LSPS5 and implement
state pruning and persistence for `LSPS1ServiceHandler` state.
.. we read the persisted state in `LiquidityManager::new`
As per spec, we check that the user provides at least one payment detail
*and* that they don't provide onchain payment details if
`refund_onchain_address` is unset.
We add a method that allows the LSP to signal to the client the token
they used was invalid.

We use the `102` error code as proposed in
lightning/blips#68.
We test the just-added API.

Co-authored by Claude AI
@tnull tnull force-pushed the 2025-11-lsps1-refactor branch 2 times, most recently from ecddd6f to 773316a Compare December 12, 2025 16:06
@tnull tnull force-pushed the 2025-11-lsps1-refactor branch from 773316a to fb519ab Compare December 12, 2025 16:08
@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

❌ Patch coverage is 53.87674% with 232 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.45%. Comparing base (fd85279) to head (fb519ab).
⚠️ Report is 22 commits behind head on main.

Files with missing lines Patch % Lines
lightning-liquidity/src/lsps1/service.rs 43.10% 154 Missing and 11 partials ⚠️
lightning-liquidity/src/lsps1/peer_state.rs 64.13% 28 Missing and 5 partials ⚠️
lightning/src/util/ser.rs 48.27% 10 Missing and 5 partials ⚠️
lightning-liquidity/src/persist.rs 68.75% 6 Missing and 4 partials ⚠️
lightning-liquidity/src/manager.rs 79.48% 2 Missing and 6 partials ⚠️
lightning-liquidity/src/lsps1/msgs.rs 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4282      +/-   ##
==========================================
+ Coverage   89.37%   89.45%   +0.07%     
==========================================
  Files         180      182       +2     
  Lines      139395   140397    +1002     
  Branches   139395   140397    +1002     
==========================================
+ Hits       124591   125598    +1007     
+ Misses      12216    12165      -51     
- Partials     2588     2634      +46     
Flag Coverage Δ
fuzzing 36.00% <2.47%> (+0.81%) ⬆️
tests 88.79% <53.87%> (+0.08%) ⬆️

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

None yet

Development

Successfully merging this pull request may close these issues.

LSPS1 integration tracking issue

3 participants