Commit Graph

2280 Commits

Author SHA1 Message Date
Rusty Russell
85c9179f77 askrene: expose additional_costs htable so child can access it.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-02-19 17:04:35 +10:30
Rusty Russell
0f575ac85a askrene: remove non child-friendly fields from struct route_query.
Notably no access to the struct command and struct plugin.

Note: we actually *do* mess with askrene->reserves, but the previous code
used cmd to get to it.  Now we need to include a non-const pointer in
struct route_query.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-02-19 17:04:35 +10:30
Rusty Russell
ac9aa975ad askrene: make children use child_log() instead of rq_log.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-02-19 17:04:35 +10:30
Rusty Russell
33e2f0a47b askrene: move fork() entry point into its own file.
Now there's only one file clearly shared by both parent and child.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-02-19 17:04:35 +10:30
Rusty Russell
395261fc30 askrene: move fmt_flow_full from askrene.c into flow.c.
Weird that it was in askrene.c

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-02-19 17:04:35 +10:30
Rusty Russell
8775b62871 askrene: move routines only accessed by the child process into child/.
We want to make it clear when future generations edit the code, which
routines are called in the child (i.e. all the routing), and which in
the parent.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-02-19 17:04:35 +10:30
Rusty Russell
da2f77767c askrene: add child_log function so child can do logging.
We just shim rq_log for now, but we'll be weaning the child process off
that soon.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-02-19 17:04:35 +10:30
Rusty Russell
0ede29b81f askrene: fork before calling the route solver.
This is fairly simple.  We do all the prep work, fire off the child,
and it continues all the way to producing JSON output (or an error).
The parent then forwards it.

Limitations (fixed in successive patches):

1. Child logging currently gets lost.
2. We wait for the child, so this code is not a speedup.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-02-19 17:04:35 +10:30
Rusty Russell
e397b12282 askrene: make minflow() static, and remove unused linear_flow_cost.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-02-19 17:04:35 +10:30
Rusty Russell
d9774e73dc bitcoin: hash_scid and hash_scidd public functions.
We reimplemented this redundantly: hash_scid was called
short_channel_id_hash, so I obviously missed it.

Rename, and implement hash_scidd helper too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-02-19 17:04:35 +10:30
Rusty Russell
9bcac63414 libplugin: add command_finish_rawstr() for when we're simply repeating an entore response.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-02-19 17:04:35 +10:30
dovgopoly
2b39fc0cb4 bcli: replace magic numbers with constants 2026-02-18 14:16:29 +10:00
dovgopoly
4126f3b1fe bcli: refactor wait_and_check_bitcoind and run_bitcoin_cli to use shared execution
Extract `execute_bitcoin_cli` as shared function used by both `run_bitcoin_cli` and `wait_and_check_bitcoind`.
2026-02-18 14:16:29 +10:00
dovgopoly
d727946b14 bcli: return "not found" on any getblockhash exit status
Return "not found" on any `getblockhash` exit status. Previously, only exit code 8 (block height doesn't exist) returned "not found", while other exit codes returned an error. Now any non-zero exit status returns "not found" since any failure means the block is unavailable.
2026-02-18 14:16:29 +10:00
dovgopoly
57d60c025b bcli: remove unused async code after sync refactor
Remove the asynchronous execution infrastructure no longer needed after converting all bcli commands to synchronous execution. This includes removing the async callbacks, the pending request queue, etc.

Fix missing `close(from)` file descriptor leak in `run_bitcoin_cliv`.

Changelog-Changed: bcli plugin now uses synchronous execution, simplifying bitcoin backend communication and improving error handling reliability.
2026-02-18 14:16:29 +10:00
dovgopoly
b5c300a82b bcli: convert getrawblockbyheight to synchronous execution
Also rename command_err_badjson to generic command_err helper, since error messages aren't always about bad JSON (e.g., "command failed" for non-zero exit).
2026-02-18 14:16:29 +10:00
dovgopoly
d06024cef7 bcli: convert estimatefees to synchronous execution
Add `command_err_badjson` helper for sync error handling, mirroring the async `command_err_bcli_badjson`. Store args string in `bcli_result` for consistent error messages.
2026-02-18 14:16:29 +10:00
dovgopoly
0de1350706 bcli: convert sendrawtransaction to synchronous execution 2026-02-18 14:16:29 +10:00
dovgopoly
a3e07f4f3a bcli: convert getutxout to synchronous execution 2026-02-18 14:16:29 +10:00
dovgopoly
f8c7a20403 bcli: convert getchaininfo to synchronous execution 2026-02-18 14:16:29 +10:00
dovgopoly
fad05200eb bcli: add synchronous run_bitcoin_cli for future refactor 2026-02-18 14:16:29 +10:00
Rusty Russell
29e0a1ddfe bkpr: limp along if we lost our db.
We can't really do decent bookkeeping any more, but don't crash!

```
bookkeeper: plugins/bkpr/recorder.c:178: find_txo_chain: Assertion `acct->open_event_db_id' failed.
bookkeeper: FATAL SIGNAL 6 (version v25.12)
0xaaaab7d51a7f send_backtrace
	common/daemon.c:38
0xaaaab7d51b2b crashdump
	common/daemon.c:83
0xffff8c0b07cf ???
	???:0
0xffff8bdf7608 __pthread_kill_implementation
	./nptl/pthread_kill.c:44
0xffff8bdacb3b __GI_raise
	../sysdeps/posix/raise.c:26
0xffff8bd97dff __GI_abort
	./stdlib/abort.c:79
0xffff8bda5cbf __assert_fail_base
	./assert/assert.c:96
0xffff8bda5d2f __assert_fail
	./assert/assert.c:105
0xaaaab7d41fd7 find_txo_chain
	plugins/bkpr/recorder.c:178
0xaaaab7d421fb account_onchain_closeheight
	plugins/bkpr/recorder.c:291
0xaaaab7d37687 do_account_close_checks
	plugins/bkpr/bookkeeper.c:884
0xaaaab7d38203 parse_and_log_chain_move
	plugins/bkpr/bookkeeper.c:1261
0xaaaab7d3871f listchainmoves_done
	plugins/bkpr/bookkeeper.c:171
0xaaaab7d4811f handle_rpc_reply
	plugins/libplugin.c:1073
0xaaaab7d4827b rpc_conn_read_response
	plugins/libplugin.c:1377
0xaaaab7d889a7 next_plan
	ccan/ccan/io/io.c:60
0xaaaab7d88f7b do_plan
	ccan/ccan/io/io.c:422
0xaaaab7d89053 io_ready
	ccan/ccan/io/io.c:439
```

Fixes: https://github.com/ElementsProject/lightning/issues/8854
Changelog-Fixed: Plugins: `bkpr_listbalances` no longer crashes if we lost our db, then do emergencyrecover and close a channel.
Reported-by: https://github.com/enaples
2026-02-17 12:10:26 +10:30
Rusty Russell
e8fd235d4e common: move gossip_store_wire.csv into common/ from gossipd/
It's used by common/gossip_store.c, which is used by many things other than
gossipd.  This file belongs in common.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-02-16 17:23:33 +10:30
Rusty Russell
6a937307b1 decode: don't treat every failure as a rune.
If we can't decode something, and it decodes as a rune (and all bech32
strings do!), then we would usually just complain it was a malformed
rune.  Be a big more useful, when the parameter looks like somthing else.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: JSON-RPC: `decode` is now more informative with malformed strings (won't claim everything is a malformed rune!).
2026-02-03 13:05:23 +10:30
Lagrang3
f1bf66c91f askrene: fixed a timeout corner case
Changelog-Fixed: askrene: fixed a class of corner cases that cause askrene main loop to timeout instead of quickly failing, thus wasting runtime.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2026-02-02 10:23:27 +10:30
Lagrang3
41a5c68aa8 askrene: consider fees during *explain failure*
We would try to explain a failure by simply finding a path between
source and destination and then checking the constraints.
However, we did not add fees.

Changelog-None

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2026-02-02 10:23:27 +10:30
Lagrang3
3822a67030 askrene: add auto.include_fees layer
Changelog-Added: askrene: add a new layer auto.include_fees thhat makes fees be deducted from the payment amount making in effect the receiver pay for routing fees.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2026-01-29 15:20:25 +10:30
Rusty Russell
a3946663ec askrene: speed up when using large number of layers.
Simple bench.

Before:
   Creating 20,000 layers:  20 seconds
   Creating 50,000 layers:  107 seconds

After:
   Creating 20,000 layers:  7 seconds
   Creating 50,000 layers:  15 seconds
   Creating 100,000 layers: 29 seconds

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-01-27 13:59:36 +10:30
Se7enZ
70fe02513c build: Replace PLUGIN_RENEPAY_HDRS json.c with json.h in Makefile. 2026-01-24 09:40:49 +10:00
Rusty Russell
d5f66ceabc plugins: don't try to fetch max-locktime-blocks.
It was removed in v25.09, so this code is useless.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-01-20 19:32:42 +10:30
Rusty Russell
9081499b0e libplugin: fix 'i-promise-to-fix-broken-api-user' parsing.
This is important for the first xpay deprecation end-of-life!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2026-01-20 19:32:42 +10:30
daywalker90
d03cf820a8 clnrest: add clnrest-register-path method for dynamic paths
Changelog-Added: clnrest: add clnrest-register-path rpc method to register dynamic paths
2026-01-19 12:55:57 +10:30
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