Commit Graph

36 Commits

Author SHA1 Message Date
Peter Neuroth
ab06508b57 lsp_plugin: use concrete type to avoid unwrap
This commit adds a custom request type for the on_openchannel hook to
avoid calling unwrap() during runtime. We now return cleanly from the
hook in any case.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
ec54d3486c lsp_plugin: add warning if extra_fee is wrong
The extra_fee tlv appended to the update_add_htlc message is set by the
LSP and should specify what was deducted from a single htlc. If it does
not match the expected amount, we log a warning message.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
0559ff1ab2 lsp_plugin: add hook helper to the client
We nearly always want to return `{"result":"continue"}` in case that
something went wrong. This commits adds two helper macros that help us
to cleanly return from a hook while logging necessary information.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
fcf1868d4e lsp_plugin: add cleanup on "on_invoice_payment"
The `on_invoice_payment` hook is called when core-lightning successfully
collected all parts to an invoice. We'll use this to clean up the the
datastore when an invoice completes.

Caveat: This will be called on every succesfull invoice payment, we may
improve this in the future.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
be015898ae lsp_plugin: add basic lsps2 mpp support to client
This includes a mocked lsps2 service plugin, tests and some changes on
the client side. The client now can accept mpp payments for a
jit-channel opening from a connected LSP.

Changelog-Added: Lsps2 `fixed-invoice-mpp` mode for the lsps2 client

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
33cd11cb1a lsp_plugin: remove anchor-type from jit channel
We use non-anchor channels for now and make this configurable in the
future. The reason for this decission is that elements does not support
anchors.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
c40f6ee9d3 lsp_plugin: remove feature flag temporarily to ...
please `connect` tests. We need to fix this in the future. Connectd
should not tell peers about features of disabled plugins.
We need to ensure that connectd only starts once the plugins have
returned from init.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
a8d122ba27 lsp_plugin: change extra_fee value type to u64
Blip25 https://github.com/lightning/blips/blob/master/blip-0025.md uses
u64 for the `amount_msat` in the `extra_fee`

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
d398c7fd5d lsp_plugin: add u64 getter and setter to tlvs
We found a situation where we need to set and get u64s rather than tu64s

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
9cd041a6f6 lsp_plugin: remove reserve from hook response
This slipped in during development but actually, we don't want to mess
with the channel reservere here.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
fa8d90f347 lsp_plugin: relax LSP feateture bit handling
Replace ensure_lsp_connected() by check_peer_lsp_status() which only
returns the status of the peer (connected, has_lsp_feature). This allows
us to be more tolearant about the LSP feature bit since it is only
optional according to the spec.

We still check for the feature but only return a warning in the logs.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
722c19ae93 lsp_plugin: add reversed feature-bit check
Core-Lightning returns the feature-bits in reversed order but we don't
want to rely on the caller to reverse the u8 slice themselfs. This
commit adds a convenience function that reverses the bitmap to avoid
hard to debug mistakes.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
9e301f0f9c lsp_plugin: rename cmds and opts to fit convention
We use `experimental-*` for documented commands instead of `dev-` which
are undocumented commands.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
ce0be9dc87 lsp_plugin: remove redundant config option
We don't need to separately enable lsp and lsps2 services. If lsps2 is
not enabled what can we do with just the messaging layer?

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
366ada7853 lsp_plugin: pass-through invoice params
Calling lsps_jitchannel we want to pass through the label and
description parameters used to call `invoice` to keep the api close to
Core-Lightning

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
e789b969ec lsp_plugin: add client side check for zero_conf
We only allow zero_conf channels if we approved the a jit-channel from
the LSP in advance.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
ffc0e42f7d lsp_plugin: add lsps-jitchannel handler
Adds the full roundtrip to request a jit channel from the LSP. It
approves the jit scid returned by the LSP and returns the invoice with
the corresponding route-hint.

Changelog-Added Experimental support for LSPS2 no-MPP,
Lsps-trusts-client mode. See
https://github.com/lightning/blips/blob/master/blip-0052.md for further
details.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
7f3789b624 lsp_plugin: add htlc_accepted handler for no-mpp
Adds the service side (LSP) for a simple no-mpp trusted jit channel
opening. This is only an intermediate step, we are going to add support
for multiple htlcs.
This is experimental and can drain on-chain fees from the LSP if used in
public.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
ecb1f4c7e7 lsp_plugin: add lsps2_buy request and handler
Adds the lsps2.buy request to the client and the lsps2.buy handler to
the LSP service.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
581eb3076f lsp_plugin: add lsps2_getinfo handler and call
This commit adds the lsps2_get_info call defined by BLIP052. It also
adds a test policy plugin that the LSP service plugin uses to fetch the
actual fee menu from to separate the concerns of providing a spec
compliant implementation of an LSP and making business decisions about
fee prices.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
17a9a928f5 lsp_plugin: add lsps2 models
Add models and options to enable lsps2 on the lsp

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
ef539dd52e lsp_plugin: refactor lsps0listprotocols handler
Move the handler to a separate file, and add lsps2_enabled flag to the
handler.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
bbcb51d98e lsp_plugin: check that featurebit is set and that
the client is connected to the lsp before sending a request

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
6c5c302c26 lsp_plugin: change listprotocols request
Using lsp_id instead of peer as identifier

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
e36fdeff81 lsp_plugin: add primitives for messages
Adds some primitives defined in lsps0 for other protocol messages.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
3606106c4f lsp_plugin: add dev-eneabled flag for client
While this is still experimental, we only want to enable the client when
explicitly defined!

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
511e61d784 lsp_plugin: add sane error to listprotocols
Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
c52da76a57 lsp_plugin: add fn to wrap payload with peer id
We need to somehow access the peer id in the jrpc server to know where
the response should go. This seems to be the most convenient way for
now. We may unclutter this in the future if this results in performance
issues.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
60174f73f8 lsp_plugin: change id type in jsonrpc
Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-13 10:58:49 +10:30
Peter Neuroth
ae226cbf7a lsps: Add additional documentation
Adds some additional documentation to the json-rpc v2.0 messages
and error types.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-05-02 13:34:21 -07:00
Peter Neuroth
e879f88eb0 lsps: Add service implementation for LSPS0
Implements the LSPS0 service plugin for core lightning

Changelog-Added: lsps-plugin: lsps0 service support

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-05-02 13:34:21 -07:00
Peter Neuroth
f3f222f39f lsps: Add client implementation of LSPS0
We want a working client to run some integration tests.

Changelog-Added: lsps-plugin: lsps0 client support
2025-05-02 13:34:21 -07:00
Peter Neuroth
4d9ed8e2fb lsps: Implement the transport layer for lsps0
For lsps0 we send JSON-RPC messages via custom messages over the
lightning network. This commit adds a basic implementation based
on custom messages.
2025-05-02 13:34:21 -07:00
Peter Neuroth
68ca86ca4f lsps: Add JSON-RPC V2 server 2025-05-02 13:34:21 -07:00
Peter Neuroth
203621a629 lsps: Implement JSON-RPC V2 client
Adds an async safe JSON-RPC V2 client for a generic transport layer. The
transport layer we will use later on are BOLT8 lightning messages.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-05-02 13:34:21 -07:00
Peter Neuroth
ea5635c4c8 lsps: Implement JSON-RPC message structure
Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-05-02 13:34:21 -07:00