Commit Graph

2248 Commits

Author SHA1 Message Date
Rusty Russell
9c6430c076 plugins/pay: don't crash if erring index is past route array end.
I assume this happens with multi-hop routehints?

```
1768169599027	2026-01-11T22:13:19.027Z	pay: plugins/libplugin-pay.c:1199: payment_result_infer: Assertion `i <= len' failed.
1768169599027	2026-01-11T22:13:19.027Z	pay: FATAL SIGNAL 6 (version 25.12)
1768169599036	2026-01-11T22:13:19.036Z	0x5562816bcaa4 send_backtrace
1768169599036	2026-01-11T22:13:19.036Z		common/daemon.c:38
1768169599036	2026-01-11T22:13:19.036Z	0x5562816bcb40 crashdump
1768169599036	2026-01-11T22:13:19.036Z		common/daemon.c:83
1768169599036	2026-01-11T22:13:19.036Z	0x7f5fca29d32f ???
1768169599036	2026-01-11T22:13:19.036Z		???:0
1768169599036	2026-01-11T22:13:19.036Z	0x7f5fca2f6b2c ???
1768169599036	2026-01-11T22:13:19.036Z		pthread_kill+0x11c:0
1768169599036	2026-01-11T22:13:19.036Z	0x7f5fca29d27d ???
1768169599036	2026-01-11T22:13:19.036Z		gsignal+0x1d:0
1768169599036	2026-01-11T22:13:19.036Z	0x7f5fca2808fe ???
1768169599036	2026-01-11T22:13:19.036Z		abort+0xde:0
1768169599036	2026-01-11T22:13:19.036Z	0x7f5fca28081a ???
1768169599036	2026-01-11T22:13:19.036Z		???:0
1768169599036	2026-01-11T22:13:19.036Z	0x7f5fca293516 ???
1768169599036	2026-01-11T22:13:19.036Z		__assert_fail+0x46:0
1768169599037	2026-01-11T22:13:19.037Z	0x5562816ae9f6 payment_result_infer
1768169599037	2026-01-11T22:13:19.037Z		plugins/libplugin-pay.c:1199
1768169599037	2026-01-11T22:13:19.037Z	0x5562816b4acd payment_waitsendpay_finished
1768169599037	2026-01-11T22:13:19.037Z		plugins/libplugin-pay.c:1653
1768169599037	2026-01-11T22:13:19.037Z	0x5562816aca60 handle_rpc_reply
1768169599037	2026-01-11T22:13:19.037Z		plugins/libplugin.c:1062
1768169599037	2026-01-11T22:13:19.037Z	0x5562816acc86 rpc_conn_read_response
1768169599037	2026-01-11T22:13:19.037Z		plugins/libplugin.c:1377
1768169599037	2026-01-11T22:13:19.037Z	0x5562816f0e87 next_plan
1768169599037	2026-01-11T22:13:19.037Z		ccan/ccan/io/io.c:60
1768169599037	2026-01-11T22:13:19.037Z	0x5562816f1358 do_plan
1768169599037	2026-01-11T22:13:19.037Z		ccan/ccan/io/io.c:422
1768169599037	2026-01-11T22:13:19.037Z	0x5562816f1415 io_ready
1768169599037	2026-01-11T22:13:19.037Z		ccan/ccan/io/io.c:439
1768169599037	2026-01-11T22:13:19.037Z	0x5562816f2e23 io_loop
1768169599037	2026-01-11T22:13:19.037Z		ccan/ccan/io/poll.c:470
1768169599037	2026-01-11T22:13:19.037Z	0x5562816ae114 plugin_main
1768169599037	2026-01-11T22:13:19.037Z		plugins/libplugin.c:2429
1768169599037	2026-01-11T22:13:19.037Z	0x5562816a894c main
1768169599037	2026-01-11T22:13:19.037Z		plugins/pay.c:1581
1768169599037	2026-01-11T22:13:19.037Z	0x7f5fca2821c9 ???
1768169599037	2026-01-11T22:13:19.037Z		???:0
1768169599037	2026-01-11T22:13:19.037Z	0x7f5fca28228a ???
1768169599037	2026-01-11T22:13:19.037Z		__libc_start_main+0x8a:0
1768169599037	2026-01-11T22:13:19.037Z	0x5562816a4eb4 ???
1768169599037	2026-01-11T22:13:19.037Z		_start+0x24:0
1768169599037	2026-01-11T22:13:19.037Z	0xffffffffffffffff ???
1768169599037	2026-01-11T22:13:19.037Z		???:0
1768169599136	2026-01-11T22:13:19.136Z	2026-01-11T22:13:19.136Z INFO    plugin-pay: Killing plugin: exited during normal operation
69599136	2026-01-11T22:13:19.136Z	2026-01-11T22:13:19.136Z **BROKEN** plugin-pay: Plugin marked as important, shutting down lightningd!
```

Reported-by: michael1011
Fixes: https://github.com/ElementsProject/lightning/issues/8828
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: plugins: `pay` can crash on errors returned from deep inside routehints.
2026-01-14 17:06:02 +10:30
Rusty Russell
35e703bfe1 askrene: don't crash if refining flow which has capacity greaater than max it should have.
```
1767724611265   2026-01-06T18:36:51.265Z                plugins/libplugin.c:1073
1767724611265   2026-01-06T18:36:51.265Z        0x55fc0c1428ac handle_rpc_reply
1767724611264   2026-01-06T18:36:51.264Z                plugins/askrene/askrene.c:801
1767724611264   2026-01-06T18:36:51.264Z        0x55fc0c13174c listpeerchannels_done
1767724611264   2026-01-06T18:36:51.264Z                plugins/askrene/askrene.c:669
1767724611264   2026-01-06T18:36:51.264Z        0x55fc0c130f55 do_getroutes
1767724611264   2026-01-06T18:36:51.264Z                plugins/askrene/mcf.c:1636
1767724611264   2026-01-06T18:36:51.264Z        0x55fc0c138bd7 default_routes
1767724611264   2026-01-06T18:36:51.264Z                plugins/askrene/mcf.c:1415
1767724611264   2026-01-06T18:36:51.264Z        0x55fc0c1382ec linear_routes
1767724611264   2026-01-06T18:36:51.264Z                plugins/askrene/refine.c:510
1767724611264   2026-01-06T18:36:51.264Z        0x55fc0c13b110 refine_flows
1767724611264   2026-01-06T18:36:51.264Z                plugins/askrene/refine.c:449
1767724611264   2026-01-06T18:36:51.264Z        0x55fc0c13ac9f increase_flows
1767724611264   2026-01-06T18:36:51.264Z                abort+0xde:0
```

Fixes: #8823
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: plugins: `askrene` can crash on a corner case in increase_flows.
2026-01-14 17:06:02 +10:30
Lagrang3
118e474637 askrene: fix payment crash
Changelog-Fixed: askrene: fix a plugin crash triggered during single path payments when a channel fees doesn't fit u32.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2026-01-13 15:16:46 +10:30
Rusty Russell
03025469be pay: don't notify using uninitialized hint field.
Rather than break the API, use total capacity here.

```
Valgrind error file: valgrind-errors.5880
==5880== Use of uninitialised value of size 8
==5880==    at 0x4A390BB: _itoa_word (_itoa.c:183)
==5880==    by 0x4A43C9B: __printf_buffer (vfprintf-process-arg.c:155)
==5880==    by 0x4A69D90: vsnprintf (vsnprintf.c:96)
==5880==    by 0x1875E6: json_out_addv (json_out.c:239)
==5880==    by 0x14471E: json_add_primitive_fmt (json_stream.c:170)
==5880==    by 0x144BA2: json_add_u64 (json_stream.c:282)
==5880==    by 0x145E33: json_add_amount_msat (json_stream.c:619)
==5880==    by 0x11DDE2: channel_hint_to_json (channel_hint.c:33)
==5880==    by 0x11FE9F: channel_hint_notify_core (libplugin-pay.c:394)
==5880==    by 0x11FF7A: channel_hint_notify (libplugin-pay.c:412)
==5880==    by 0x1201EA: channel_hints_update (libplugin-pay.c:455)
==5880==    by 0x122DAF: handle_intermediate_failure (libplugin-pay.c:1437)
==5880== 
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-01-08 22:33:19 +10:30
Rusty Russell
241324aa09 gossipd: don't shortcut dying phase for local channels.
This means that we won't complain to peers which gossip about our
channels, but it does mean that our channel graph (like other nodes on
the network) will show two channels, not one, for the duration.

For this reason, we need askrene to omit local dying channels.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-01-08 22:33:19 +10:30
wqxoxo
bc3b9b4f11 pay: Enforce maxdelay for direct channel payments
When paying through a direct channel, direct_pay_override() creates a
route bypassing the normal routing path, which skips the CLTV budget
check in payment_getroute(). This allows payments to succeed even when
maxdelay is set below the required min_final_cltv_expiry.

Add a check in direct_pay_override() to verify the required CLTV
doesn't exceed cltv_budget before using the direct channel shortcut.
If it exceeds, skip the direct channel and let normal routing handle
the failure with a proper error message.

Fixes: #8609

Changelog-Fixed: pay: `maxdelay` parameter now enforced for direct channel payments
2025-12-19 12:41:17 +01:00
nazarevsky
bcdce8f40d cln-rpc: update schema, update proto for xpay payer_note field 2025-12-18 12:47:06 -08:00
nazarevsky
66ce41d584 xpay: add payer_note field
Changelog-Added: Add 'payer-note' field to the 'xpay' RPC call.
2025-12-18 12:47:06 -08:00
Peter Neuroth
4a1c922017 plugins: lsps: remove anyhow from tlvs
Remove anyhow as a dependency from the tlv module. This allows for a
cleaner error handling

Changelog-None

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
c7bbf84c83 plugins: lsps: remove cln dependencies from core module and clean up service
The core module shouldn't depend on anything from the cln_adapters
module. This ensures that we can switch out interfaces in the future
(e.g a different database than cln's datastore).

This change made it necessary to refactor the service plugin which
allowed us to clean it up on the go

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
30268ad945 plugins: lsps: move feature helpers to core module
This removes the util.rs module and leaves us with proto, core and
cln_adapters

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
f678a70610 plugins: lsps: remove lsps2 module
Separate concerns of the lsps2 modules into their respective layers:
core for tlv, as it is lightning related, not specifically
core-lightning. cln_adapters for core-lightning related types.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
fa62c64de7 plugins: lsps: split up handlers
This commit separates the business logic from core-lighting behaviour
and moves the core-lightning related implementations into the
cln_adapters module.

Splits up tests as well

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
e001652ab1 plugins: lsps: add own trait for lightning provider
Clean up the CLN interface

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
a05c2c9c2c plugins: lsps: add own trait for datastore provider
This now only makes it easier to test, but also more modular. It allows
us to use any kind of storage, not only the datastore.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
38c84be25e plugins: lsps: add own trait for blockheight provider
The ClnApi trait is way overloaded. We break things down to make it more
modular on the service side.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
38b3d14eb9 plugins: lsps: add own trait for lsps offer provider
The cln api trait is really cluttered, we try to clean it up a little
bit.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
e50f5ee863 plugins: lsps: refactor service hook
We have some shared behavior and can use the MessageSender for the
service hook as well

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
462ca844dd plugins: lsps: replace heavy transport
We replace the legacy transport by a slim custommsg hook that makes use
of the lightweight multiplexed transport and avoids deserialization and
serialization through this extra layer

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
d5bcde09ae plugins: lsps: implement ClnSender for bolt8 transport
Implement the MessageSender trait for Bolt8 transport via core-lightning

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
3cf99c358b plugins: lsps: add slim multiplexing transport
We can separate concerns here by adding a lightweight multiplexing
transport client. This helps us to clean up any direct dependencies on
CLN

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
7401585088 plugins: lsps: move client transport to cln_adapters
cln_adapters is the layer that holds concrete implementations that are
related to core-lightning.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
9adc8cdfed plugins: lsps: slim down lsps service
This commit replaces the lsps service. Therefore we add the cln_adapters
module that handles the communication with core-lightning. We add a
lightweight LspsService that wraps the router and allows handlers to
register themselves to the service/router.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
461065aff7 plugins: lsps: add router compatible lsps2 service handler
This commit copys and adapts the lsps2 service handlers to match the
slim router handlers

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
ffc05ddcf0 plugins: lsps: add slim generic json-rpc router
This router is very lightweight and can handle routing for the lsps
service. It avoids allocations by just borrowing from the request. This
is much cleaner than what we have now and reduces the amount of
serializations by a lot.

Also it supports typed handlers which will remove serialization overhead
from the handlers in future commits

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
1159adb0e2 plugin: lsps: move json-rpc server to core module
This removes the jsonrpc module

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
b9172239d0 plugins: lsps: switch to typed transport
There is no need to communicate via a generic JsonRpcClient if all
messages are well defined and we can use the typed transport to remove a
whole lot of overhead and just pass the ResponseObjects directly to the
Transport layer

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
1bb76f84e2 plugins: lsps: add request to transport trait
Introducing "request" to the transport trait that uses the RequestObject
and JsonRpcResponse directly reduces some overhead and unnecessary
conversions. Why do we implement a generic transport over &str when we
already know that we are dealing with JSON-RPC 2.0 here.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
2546642c32 plugins: lsps: move id generation into jsonrpcrequest
There is no need to generate the id in some client when we can actually
generate it on a lower layer as we know by LSPS0 how we have to generate
it.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
5ed743e10d plugins: lsps: add lsps0 encoding and decoding
In order to seperate concerns, this adds the basic encoding of an lsps0
frame to the proto module.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
0927179fe1 plugins: lsps: replace owned types by references
Improves flexibility in transport implementations.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
e08756cd57 plugins: lsps: use transport specific error
instead of using std::error, this is more specific and keeps the errors
"type-safe"

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
e591323ac8 plugins: lsps: remove peer_id from transport
As we pass the peer_id through the transport methods, there is no need
to store the peer_id in the Bolt8Transport struct anymore

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
0f624ed67f plugins: lsps: add peer_id to transport
Frankly, transport without a target doesn't make sense, so this commit
adds a PublicKey (from secp256k1) as the target to the Transport trait.
It can easily be replaced by a common PeerId without changing the api
for external implementations if needed in the future

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
6e868443e2 plugins: lsps: move transport to core module
This commit is part of a series of commits to make the lsps plugin crate
layered and modular for efficient reuse in external projects.

The core module is responsible for common business logic and interfaces
and acts as the intermediate layer for an actual implementation

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
5274556518 plugins: lsps: refactor client to use jsonrpcresponse
This makes it easier for client implementations to separate transport or
parser related issues from actuall json-rpc error responses. Also this
helps to segregate the individual responsibilities of the crates
further.

This further alows us to remove the error enum from proto/jsonrpc
completely as this now only deals as a from/to-wire module

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
bad42c711b plugin: lsps: simplify json-rpc response object
We can use an enum as a more idiomatic rust style to create and retreive
json-rpc responses. The actual response data is kept in the body enum
while the surrounding only holds the identifier.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
67f11b62e6 plugins: lsps: refactor jsonrpc error
In order to create a sane dependecy structure for this crate, this
commit cleans up the jsonrpc error enum and shifts responsibilities
towards the transport client

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
9c474a6d5c plugins: lsps: move transport error to client module
The error belongs to the transport definition, not into the
wire/protocol module.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
a51f6e1ebb plugins: lsps: remove debug print from library module
This commit is part of a series that refactor the lsp plugin crate into
a modularized crate with the goal to separate the actual plugin runtime
as much as possible from library code to make it accessible for 3rd
party plugin implementations.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
b7be5ef3a2 plugins: lsps: refactor lsps2 and lsps0 error enums
Split them up how they are actually defined.

This commit is part of a series that refactor the lsp plugin crate into
a modularized crate with the goal to separate the actual plugin runtime
as much as possible from library code to make it accessible for 3rd
party plugin implementations.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
b88dc5972f plugins: lsps: move lsps2 model to proto module
This commit is part of a series that refactor the lsp plugin crate into
a modularized crate with the goal to separate the actual plugin runtime
as much as possible from library code to make it accessible for 3rd
party plugin implementations.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
ba93a7ca62 plugins: lsps: move primitives into lsps0
Those primitives are actually defined in lsps0

This commit is part of a series that refactor the lsp plugin crate into
a modularized crate with the goal to separate the actual plugin runtime
as much as possible from library code to make it accessible for 3rd
party plugin implementations.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
5847cd443f plugins: lsps: move jsonrpc into proto module
This commit is part of a series that refactor the lsp plugin crate into
a modularized crate with the goal to separate the actual plugin runtime
as much as possible from library code to make it accessible for 3rd
party plugin implementations.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
bd9fd581f1 plugins: lsps: move feature types into proto module
This commit is part of a series that refactor the lsp plugin crate into
a modularized crate with the goal to separate the actual plugin runtime
as much as possible from library code to make it accessible for 3rd
party plugin implementations.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
a94885ba7f plugins: lsps: move errors into proto module
This commit is part of a series that refactor the lsp plugin crate into
a modularized crate with the goal to separate the actual plugin runtime
as much as possible from library code to make it accessible for 3rd
party plugin implementations.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
39c36a03dd plugins: lsps: move lsps0 model into proto module
This commit is part of a series that refactor the lsp plugin crate into
a modularized crate with the goal to separate the actual plugin runtime
as much as possible from library code to make it accessible for 3rd
party plugin implementations.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
Peter Neuroth
06fe54c467 plugins: lsps: move primitives into proto module
This commit is part of a series that refactor the lsp plugin crate into
a modularized crate with the goal to separate the actual plugin runtime
as much as possible from library code to make it accessible for 3rd
party plugin implementations.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-12-17 05:56:01 +10:30
wqxoxo
3c08a8bdb9 xpay: fix misleading "route hint" label in error messages
describe_scidd() was labeling any channel as "the invoice's route hint"
when there was a single-hop route hint, even if the error occurred on
an unrelated intermediate channel.

Now we check the channel actually matches the route hint's
short_channel_id before using that label.

Fixes: #8252
Changelog-Fixed: xpay: error messages no longer incorrectly label intermediate channels as "the invoice's route hint".
2025-11-29 08:33:37 +10:30
Rusty Russell
eb83a205b9 askrene: move datastore wire functions into separate file for lightning-downgrade to use.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-28 09:16:53 +10:30