Commit Graph

2107 Commits

Author SHA1 Message Date
Rusty Russell
cb5141ff25 clnrest: change utoipa to my GH branch with daywalker90's deterministic PR merged.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Build: release builds with tools/build-release.sh are deterministic again.
2025-10-26 20:31:45 +10:30
Rusty Russell
42f9361375 ccan: update to get improved grab_file API, and adapt code.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-26 12:37:58 +10:30
Sangbida Chaudhuri
bf508387a3 hsmtool: change hsm_secret struct to have length awareness
This commit is updating hsmtool and exposesecrets to use the new pattern for storing the secret, which is the secret_data and secret_len, to support both 64 byte and 32 byte seeds.
2025-10-26 12:37:58 +10:30
Sangbida Chaudhuri
de9c6305a1 exposesecret: Add support for mnemonic-based HSM secrets
Update the exposesecret plugin to work with the new unified HSM secret
format that supports BIP39 mnemonics.

Changelog-Added - exposesecret now has a mnemonic field
2025-10-26 12:37:58 +10:30
Rusty Russell
75616f6b77 common: add new_htable() macro to allocate, initialize and setup memleak coverage for any typed hash table.
You can now simply add per-tal-object helpers for memleak, but our older pattern required
calling memleak functions explicitly during memleak handling.  Hash tables in particular need
to be dynamically allocated (we override the allocators using htable_set_allocator and assume
this), so it makes sense to have a helper macro that does all three.

This eliminates a huge amount of code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-24 11:30:17 +10:30
Rusty Russell
bc4bb2b0ef libplugin: use jsonrpc_io logic for sync requests too.
It's a little overkill, but it's clear.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-24 11:28:57 +10:30
Rusty Russell
cbfd65f600 libplugin: use jsonrpc_io for stdin from lightningd.
This is also more efficient if there are many commands at once.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-24 11:28:57 +10:30
Rusty Russell
cb2cf034f3 libplugin: wean ld_command_handle off referncing plugin->buffer.
Hand it in as a parameter to reduce churn in next patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-24 11:28:57 +10:30
Rusty Russell
690f95ff1f libplugin: use jsonrpc_io for reading replies to our async commands.
This will also be more efficient than doing memmove every time.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-24 11:28:57 +10:30
Rusty Russell
dd7cc71b38 plugins: remove unused json_buffer / json_toks members from libplugin-pay.
They were never referenced, and saving the toks is questionable since their
lifetime is not guaranteed to live beyond this call (at least the buffer was
duplicated, but that also assumed it was at the start of the object).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-24 11:28:57 +10:30
Rusty Russell
7c9e016fb7 common: export helper membuf_tal_realloc.
We have to call it membuf_tal_resize() because the other on is
a ccan/json_out static function!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-24 11:28:57 +10:30
Rusty Russell
e28fed7504 plugins: make fatal errors neater.
Without this they get run together on stderr.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-24 11:28:57 +10:30
Rusty Russell
8f6d3d87bb plugins: fix %*.s typo.
And add a check for new uses creeping in, since it got cut & paste
everywhere.

This means "this is a valid string, but truncate it to this many characters"
vs "%.*s" which means "only read this many characters of string":

```
['lightningd-3 2025-10-23T02:31:40.890Z **BROKEN** plugin-funder: Plugin marked as important, shutting down lightningd!']
--------------------------- Captured stderr teardown ---------------------------
    #0 0x557da58ad1dc in printf_common(void*, char const*, __va_list_tag*) asan_interceptors.cpp.o
    #1 0x557da5aff814 in json_out_addv /home/runner/work/lightning/lightning/ccan/ccan/json_out/json_out.c:239:11
    #2 0x557da59740ce in plugin_logv /home/runner/work/lightning/lightning/plugins/libplugin.c:1777:2
    #3 0x557da5969b6f in plugin_log /home/runner/work/lightning/lightning/plugins/libplugin.c:1934:2
    #4 0x557da595c4f6 in datastore_del_success /home/runner/work/lightning/lightning/plugins/funder.c:161:2
    #5 0x557da598b837 in handle_rpc_reply /home/runner/work/lightning/lightning/plugins/libplugin.c:1072:10
    #6 0x557da598a4b0 in rpc_conn_read_response /home/runner/work/lightning/lightning/plugins/libplugin.c:1361:3
    #7 0x557da5adbea5 in next_plan /home/runner/work/lightning/lightning/ccan/ccan/io/io.c:60:9
    #8 0x557da5ae06ff in do_plan /home/runner/work/lightning/lightning/ccan/ccan/io/io.c:422:8
    #9 0x557da5adfb58 in io_ready /home/runner/work/lightning/lightning/ccan/ccan/io/io.c:439:10
    #10 0x557da5aec2ce in io_loop /home/runner/work/lightning/lightning/ccan/ccan/io/poll.c:455:5
    #11 0x557da59757ac in plugin_main /home/runner/work/lightning/lightning/plugins/libplugin.c:2409:3
    #12 0x557da594fe23 in main /home/runner/work/lightning/lightning/plugins/funder.c:1723:2
    #13 0x7f6572229d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #14 0x7f6572229e3f in __libc_start_main csu/../csu/libc-start.c:392:3
    #15 0x557da588b584 in _start (/home/runner/work/lightning/lightning/plugins/funder+0x10d584) (BuildId: 71ba63ab577fc6fa60573d3e8555f6db7d5c584d)

0x624000009d28 is located 0 bytes to the right of 7208-byte region [0x624000008100,0x624000009d28)
allocated by thread T0 here:
    #0 0x557da590e7f6 in __interceptor_realloc (/home/runner/work/lightning/lightning/plugins/funder+0x1907f6) (BuildId: 71ba63ab577fc6fa60573d3e8555f6db7d5c584d)
    #1 0x557da5b2149b in tal_resize_ /home/runner/work/lightning/lightning/ccan/ccan/tal/tal.c:755:13
    #2 0x557da59f2032 in membuf_tal_resize /home/runner/work/lightning/lightning/common/utils.c:203:2
    #3 0x557da5b03934 in membuf_prepare_space_ /home/runner/work/lightning/lightning/ccan/ccan/membuf/membuf.c:45:12
    #4 0x557da59d4289 in jsonrpc_io_read_ /home/runner/work/lightning/lightning/common/jsonrpc_io.c:127:2
    #5 0x557da598a635 in rpc_conn_read_response /home/runner/work/lightning/lightning/plugins/libplugin.c:1366:9
    #6 0x557da5adbea5 in next_plan /home/runner/work/lightning/lightning/ccan/ccan/io/io.c:60:9
    #7 0x557da5ae06ff in do_plan /home/runner/work/lightning/lightning/ccan/ccan/io/io.c:422:8
    #8 0x557da5adfb58 in io_ready /home/runner/work/lightning/lightning/ccan/ccan/io/io.c:439:10
    #9 0x557da5aec2ce in io_loop /home/runner/work/lightning/lightning/ccan/ccan/io/poll.c:455:5
    #10 0x557da59757ac in plugin_main /home/runner/work/lightning/lightning/plugins/libplugin.c:2409:3
    #11 0x557da594fe23 in main /home/runner/work/lightning/lightning/plugins/funder.c:1723:2
    #12 0x7f6572229d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16

SUMMARY: AddressSanitizer: heap-buffer-overflow asan_interceptors.cpp.o in printf_common(void*, char const*, __va_list_tag*)
Shadow bytes around the buggy address:
  0x0c487fff9350: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c487fff9360: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c487fff9370: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c487fff9380: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c487fff9390: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c487fff93a0: 00 00 00 00 00[fa]fa fa fa fa fa fa fa fa fa fa
  0x0c487fff93b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c487fff93c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c487fff93d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c487fff93e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c487fff93f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==26122==ABORTING
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-24 11:28:57 +10:30
Rusty Russell
6e5cb299dd global: remove unnecessary includes from C files.
Basically, `devtools/reduce-includes.sh */*.c`.

Build time from make clean (RUST=0) (includes building external libs):

Before:
	real    0m38.944000-40.416000(40.1131+/-0.4)s
	user    3m6.790000-17.159000(15.0571+/-2.8)s
	sys     0m35.304000-37.336000(36.8942+/-0.57)s
After:
	real    0m37.872000-39.974000(39.5466+/-0.59)s
	user    3m1.211000-14.968000(12.4556+/-3.9)s
	sys     0m35.008000-36.830000(36.4143+/-0.5)s

Build time after touch config.vars (RUST=0):

Before:
	real    0m19.831000-21.862000(21.5528+/-0.58)s
	user    2m15.361000-30.731000(28.4798+/-4.4)s
	sys     0m21.056000-22.339000(22.0346+/-0.35)s

After:
	real    0m18.384000-21.307000(20.8605+/-0.92)s
	user    2m5.585000-26.843000(23.6017+/-6.7)s
	sys     0m19.650000-22.003000(21.4943+/-0.69)s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-23 06:44:04 +10:30
Rusty Russell
f6a4e79420 global: remove unnecessary includes from headers.
Each header should only include the other headers it needs to compile;
`devtools/reduce-includes.sh */*.h` does this.  The C files then need
additional includes if they don't compile.

And remove the entirely useless wire/onion_wire.h, which only serves to include wire/onion_wiregen.h.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-23 06:44:04 +10:30
Rusty Russell
65d997842e Makefiles: remove redundant dependencies, and have objects depend on their Makefile.
1. $(JSMN_OBJS) is not set anywhere.
2. You don't need to depend on CCAN_HEADERS, COMMON_HEADERS or JSMN_HEADERS: the top level Makefile has all object depedning on it.
3. Similarly, CCAN_OBJS.
4. Every object file should be rebuilt if its Makefile changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-23 06:44:04 +10:30
Rusty Russell
e120f87083 Makefile: create a library containing common, wire and bitcoin objects.
This means we don't have to manually choose what to link against,
which is much of the complexity of our Makefiles: the compiler will
automatically use any object files it needs to link.

We already do this for ccan as libccan.a, now we have libcommon.a.

We don't link against it for *everything*, as some tests require their own
versions.

Notes:
1. I get rid of the weird plugins/test/Makefile2 (accidental commit?)
2. Many tests change due to update-mocks.
3. In some places I added the missing dependency on the Makefile itself, though most are in the next
   patch.

Before:
	Total program size:     221366528
	Total tests size:       364243856

After:
	Total program size:     190733656
	Total tests size:       337880888

Build time from make clean (RUST=0) (includes building external libs):

Before:
	real    0m38.227000-44.245000(41.8222+/-1.6)s
	user    3m2.105000-33.696000(23.1442+/-8.4)s
	sys     0m35.054000-42.269000(39.7231+/-2)s
After:
	real    0m38.944000-40.416000(40.1131+/-0.4)s
	user    3m6.790000-17.159000(15.0571+/-2.8)s
	sys     0m35.304000-37.336000(36.8942+/-0.57)s

Build time after touch config.vars (RUST=0):

Before:
	real    0m18.928000-22.776000(21.5084+/-1.1)s
	user    2m8.613000-36.567000(27.7281+/-7.7)s
	sys     0m20.458000-23.436000(22.3963+/-0.77)s

After:
	real    0m19.831000-21.862000(21.5528+/-0.58)s
	user    2m15.361000-30.731000(28.4798+/-4.4)s
	sys     0m21.056000-22.339000(22.0346+/-0.35)s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

rusty@rusty-Framework:~/devel/cvs/lightni
2025-10-23 06:44:04 +10:30
Rusty Russell
c758672ac0 bookkeeper: honor start and ent times when consolidating onchain fees.
Fixes: https://github.com/ElementsProject/lightning/issues/8318

Reported-by: Shahaha
Changelog-Fixed: Plugins: `bkpr_listincome` now honors `start_time` and `end_time` parameters for onchain fees.
2025-10-21 20:21:56 +10:30
Rusty Russell
2539b4f199 bookkeeper: save last timestamp to avoid another query in find_consolidated_fees.
If the fees are not *all* of the fees (as we do in next patch), the
query would be wrong.  Plus, as the FIXME suggests, we should just save
it as we're getting the fee_sums, not do a whole new query!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-21 20:21:56 +10:30
Rusty Russell
e522aedc94 bookkeeper: only read listchannelmoves 1000 entries at a time.
If we read all of them, we might get 1.6M at once (after initial
migration).  Then we submit a few hundred thousand simultaneous
requests to lightningd, and it gets upset, queueing them all on the
xpay command hook and running out of memory.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: plugins: bookkeeper first invocation after migration from prior to 25.09 with very large databases will not crash.
2025-10-20 11:19:22 +10:30
Rusty Russell
0c9a35e2d5 plugins/sql: add payment_hash index to channelmoves table.
This significantly speeds up the query which bookkeeper often does:

		      "SELECT created_index"
		      " FROM channelmoves"
		      " WHERE payment_hash = X'%s'"
		      "   AND credit_msat = %"PRIu64
		      "   AND created_index <= %"PRIu64,

On large databases this scan is expensive, and a payment_hash index
cuts it down a great deal.  It does take longer to load the channelmoves
in the first place though (about 3x).

Before:
	$ while sleep 10; do wc -l /tmp/bkpr-progress; done
	169505 /tmp/bkpr-progress
	196010 /tmp/bkpr-progress
	219370 /tmp/bkpr-progress
	235671 /tmp/bkpr-progress
	244242 /tmp/bkpr-progress
	255362 /tmp/bkpr-progress
	265636 /tmp/bkpr-progress
	276966 /tmp/bkpr-progress
	284451 /tmp/bkpr-progress
	288836 /tmp/bkpr-progress
	296578 /tmp/bkpr-progress
	304571 /tmp/bkpr-progress

After:
	$ while sleep 10; do wc -l /tmp/bkpr-progress; done
	161421 /tmp/bkpr-progress
	238273 /tmp/bkpr-progress
	281185 /tmp/bkpr-progress
	305787 /tmp/bkpr-progress

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: plugins: the sql plugin now keeps an index on `channelmoves` by `payment_hash`.
2025-10-20 11:19:22 +10:30
Rusty Russell
b7c2629d0e libplugin: remove redundant destructor which causes exponential slowdown on large numbers of requests.
Note that we create a destructor on the command to reset request->cmd
pointer if the cmd is freed (so we know not to call the callback).
But attaching hundreds of thousands of them is slow: it's a
single-linked list, which is iterated in several places.

But that's redundant: the request is now allocated off the cmd, so freeing the command
will free the request anyway.

Hacking in something to print progress to a file, here's the number of
requests processed every 10 seconds before and after:

Before:
	$ while sleep 10; do wc -l /tmp/bkpr-progress; done
	181529 /tmp/bkpr-progress
	195994 /tmp/bkpr-progress
	207083 /tmp/bkpr-progress
	226336 /tmp/bkpr-progress
	234319 /tmp/bkpr-progress
	241514 /tmp/bkpr-progress
	247421 /tmp/bkpr-progress
	255292 /tmp/bkpr-progress
	261367 /tmp/bkpr-progress
	269085 /tmp/bkpr-progress
	276953 /tmp/bkpr-progress
	282233 /tmp/bkpr-progress
	286193 /tmp/bkpr-progress
	290930 /tmp/bkpr-progress
	295276 /tmp/bkpr-progress
	301086 /tmp/bkpr-progress

After:
	169505 /tmp/bkpr-progress
	196010 /tmp/bkpr-progress
	219370 /tmp/bkpr-progress
	235671 /tmp/bkpr-progress
	244242 /tmp/bkpr-progress
	255362 /tmp/bkpr-progress
	265636 /tmp/bkpr-progress
	276966 /tmp/bkpr-progress
	284451 /tmp/bkpr-progress
	288836 /tmp/bkpr-progress
	296578 /tmp/bkpr-progress
	304571 /tmp/bkpr-progress

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-20 11:19:22 +10:30
Sangbida Chaudhuri
7b1c4874ed makefile: use SED from configure in most places.
Some simple cases are left alone, but anything called from make uses $SED.
2025-10-17 10:40:17 +10:30
Rusty Russell
343d30ae5b bookkeeper: fix reloading of rebalances.
Parse key correctly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: bookkeeper: failed reload of rebalances on restart.
2025-10-01 15:35:50 +09:30
Rusty Russell
ba75f7bcf1 offers: remove blinding from decode JSON-RPC.
Deprecated in 24.11, disabled in 25.05.

Changelog-Removed: JSON-RPC: `decode` field `blinding` (use `first_path_key` as per modern BOLT naming)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-01 15:32:54 +09:30
Rusty Russell
512f328730 wire: update to slight spec neating.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-01 15:31:30 +09:30
Rusty Russell
5e53af7d3f plugins/offers: handle invoice_request with invreq_recurrence_cancel
In this case, we make an immediately-expiring invoice.  This correctly blocks
any successive requests for invoices, as per the spec requirement.

This means we have to handle invoice_requests without reply_path, amounts
or quantity *if* they specify invreq_recurrence_cancel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-01 15:31:30 +09:30
Rusty Russell
0d18b82dae plugins: cancelrecurringinvoice command.
`fetchinvoice` variant, for setting invreq_recurrence_cancel instead.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: `cancelrecurringinvoice` command to send new "don't expect any more invoice requests" msg to recurring bolt12 invoices.
2025-10-01 15:31:30 +09:30
Rusty Russell
5a73bd34e5 plugins/fetchinvoice: allow send_message() to say "don't expect a reply"
We're going to want this for sending invreq_recurrence_cancel invoice_requests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-01 15:31:30 +09:30
Rusty Russell
4e7c2fcf32 plugins/fetchinvoice: extract bip353 parsing to param helper.
We're going to want this for cancelrecurringinvoice.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-01 15:31:30 +09:30
Rusty Russell
551ecdf7ab plugins/fetchinvoice: extract recurrence invreq_metadata routine.
We're going to want this for cancelrecurringinvoice.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-01 15:31:30 +09:30
Rusty Russell
b30e063432 plugins/fetchinvoice: allow use of expired offers *for recurrence*.
We added this to the recurrence spec: the offer expiration only applies to the
first request, not subsequent ones.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-01 15:31:30 +09:30
Rusty Russell
559e3fc447 common: fix bolt12 quotes to bring them up-to-date.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-01 15:31:30 +09:30
Rusty Russell
75e6c49989 offers: allow quantity_max = 1
If you're doing just-in-time stock management, it would be annoying to
discover this wasn't allowed!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-01 15:31:30 +09:30
Rusty Russell
6476347c79 offers: use param_check() for more thorough parameter validation.
And fix incorrect comment on its use in the header!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-01 15:31:30 +09:30
Rusty Russell
54444e4337 BOLT12: Update recurrence to latest spec draft.
Changes:
* Fields renumbered to their draft values + billion.
* offer_recurrence now comes in compulsory or optional (backwards compat) flavors.
* `proportional_amount` is now inside `offer_recurrence_base` not `offer_recurrence_paywindow`.
* New field `invreq_recurrence_cancel`.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: Draft specification for recurring offers changed: old recurring offers will no longer work.
2025-10-01 15:31:30 +09:30
Rusty Russell
e7ea57e130 BOLT12: Remove start_any_period from recurrence_base.
Offer_absolute_expiry should be used if you want to require starting at the start.

Changelog-EXPERIMENTAL: Protocol: BOLT 12 recurrence `start_any_period` removed, use expiry if you need to restrict when they can start using the offer.
2025-10-01 15:31:30 +09:30
Rusty Russell
05005475e3 BOLT12: Remove years from recurrence.
Use months instead.

Changelog-EXPERIMENTAL: Protocol: BOLT 12 recurrence `years` removed; use 12 x months.
2025-10-01 15:31:30 +09:30
Rusty Russell
907f7c6698 unit tests: update all the gossmaps to have the GOSSIP_STORE_COMPLETED_BIT set.
Mostly this meant running them, then running devtools/convert-gossmap and replacing the code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-01 13:29:33 +09:30
Rusty Russell
3c3788a241 pytest: fix test_xpay_fake_channeld flake
Also, resulting log was huge, so suppress log level (will probably speed test)

```
2025-09-02T06:01:39.4881086Z >       l1.rpc.plugin_start(os.path.join(os.getcwd(), 'plugins/cln-askrene'))
2025-09-02T06:01:39.4881090Z 
2025-09-02T06:01:39.4881174Z tests/test_xpay.py:279: 
...
2025-09-02T06:01:39.4883193Z >           self.sock.connect(str(self.path))
2025-09-02T06:01:39.4883340Z E           ConnectionRefusedError: [Errno 111] Connection refused
...
2025-09-02T06:01:41.7767610Z lightningd-1 2025-09-02T06:01:27.235Z **BROKEN** plugin-cln-xpay: askrene-age failed with {"code":-4, "message":"Plugin terminated before replying to RPC call."}
2025-09-02T06:01:41.7768127Z lightningd-1 2025-09-02T06:01:27.305Z INFO    plugin-cln-xpay: Killing plugin: exited during normal operation
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-09-30 11:37:31 +09:30
Rusty Russell
40a44d9aab build: fix build with no sqlite3 support.
Reported-by: whitslack
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: https://github.com/ElementsProject/lightning/issues/8473
Changelog-Fixed: build: we can now build without sqlite3 support.
2025-09-29 13:11:44 +09:30
Claudio Raimondi
13c5db51a9 Refactor Dockerfile, Add TODOs
all these changelogs only apply to the Docker image.

Changelog-Added: added verification of GPG keys for the bitcoin and litecoin tarballs.
Changelog-Fixed: fixed compilation on all target architectures; each had their own bugs (poetry, missing packages...).
Changelog-Fixed: fixed cargo cross compilation. it was mistakenly using QEMU before.
Changelog-Fixed: fixed CPU compatibility bug described in issue 8456
Changelog-Changed: improve build time by 8.8x
Changelog-Changed: improve image size by 2.07x

more detailed changelog can be found on the PR: https://github.com/ElementsProject/lightning/pull/8429
2025-09-28 20:56:07 +05:30
Chandra Pratap
a77aa50ae1 plugins/libplugin-pay: Add a check for NaN values
Changelog-Fixed: Due to the imprecision of `htlc_max`'s type (`fp16_t`),
`capacity_bias()` can return `NaN` in some cases. This leads to a
runtime error when compiled with UBSan. Add a check against it.
2025-09-22 10:52:59 +09:30
Chandra Pratap
5365b44e1b plugins/test: Add a test to trigger the bug
Add a test in `plugins/test/run-route-calc.c` that reproduces the
runtime error when the fix is not applied.
2025-09-22 10:52:59 +09:30
ShahanaFarooqui
9f75c99266 docker: Dockerfile fixes after poetry to uv migration
Cargo utilizes `git ls-remote` to resolve git dependencies specified by commit hashes. GitHub only advertises commits that are reachable from branches, tags, or PR references. The `bip353-plugin` was referencing an orphaned commit in the `bitcoin-payment-instructions` dependency that was unreachable through any advertised reference. This can be resolved by installing the tarball release v0.5.0.

Changelog-None.
2025-09-09 10:46:23 +09:30
Nishant Bansal
74489b52b3 plugins/bcli: use -rpcwait to simplify waiting for bitcoind to warm up
Replaced custom wait logic with the -rpcwait flag in bitcoin-cli to handle waiting for bitcoind to warm up. This simplifies the code and ensures that errors unrelated to warmup are passed up directly without additional checks.
Changelog-None

Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
2025-09-04 13:33:32 +09:30
Rusty Russell
3e4c922114 bkpr: don't leak event in fillin_apy_acct_details.
Now accounts are not transient, we can't use them as temporary parents:

```
lightningd-2 2025-08-28T02:36:35.629Z **BROKEN** plugin-bookkeeper: MEMLEAK: 0x5e3bf926ce28
lightningd-2 2025-08-28T02:36:35.629Z **BROKEN** plugin-bookkeeper:   label=plugins/bkpr/sql.c:109:struct chain_event
lightningd-2 2025-08-28T02:36:35.629Z **BROKEN** plugin-bookkeeper:   alloc:
lightningd-2 2025-08-28T02:36:35.629Z **BROKEN** plugin-bookkeeper:     ccan/ccan/tal/tal.c:488 (tal_alloc_)
lightningd-2 2025-08-28T02:36:35.629Z **BROKEN** plugin-bookkeeper:     plugins/bkpr/sql.c:109 (chain_events)
lightningd-2 2025-08-28T02:36:35.629Z **BROKEN** plugin-bookkeeper:     plugins/bkpr/sql.c:197 (chain_events_from_sql)
lightningd-2 2025-08-28T02:36:35.629Z **BROKEN** plugin-bookkeeper:     plugins/bkpr/recorder.c:352 (find_chain_event_by_id)
lightningd-2 2025-08-28T02:36:35.629Z **BROKEN** plugin-bookkeeper:     plugins/bkpr/channelsapy.c:120 (fillin_apy_acct_details)
lightningd-2 2025-08-28T02:36:35.629Z **BROKEN** plugin-bookkeeper:     plugins/bkpr/channelsapy.c:172 (compute_channel_apys)
lightningd-2 2025-08-28T02:36:35.629Z **BROKEN** plugin-bookkeeper:     plugins/bkpr/bookkeeper.c:220 (getblockheight_done)
lightningd-2 2025-08-28T02:36:35.629Z **BROKEN** plugin-bookkeeper:     plugins/libplugin.c:1134 (handle_rpc_reply)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/libplugin.c:1438 (rpc_read_response_one)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/libplugin.c:1462 (rpc_conn_read_response)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     ccan/ccan/io/io.c:60 (next_plan)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     ccan/ccan/io/io.c:422 (do_plan)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     ccan/ccan/io/io.c:439 (io_ready)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     ccan/ccan/io/poll.c:455 (io_loop)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/libplugin.c:2564 (plugin_main)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/bkpr/bookkeeper.c:1547 (main)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     ../sysdeps/nptl/libc_start_call_main.h:58 (__libc_start_call_main)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     ../csu/libc-start.c:360 (__libc_start_main_impl)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:   steal:
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     ccan/ccan/tal/tal.c:559 (tal_steal_)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/bkpr/recorder.c:361 (find_chain_event_by_id)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/bkpr/channelsapy.c:120 (fillin_apy_acct_details)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/bkpr/channelsapy.c:172 (compute_channel_apys)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/bkpr/bookkeeper.c:220 (getblockheight_done)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/libplugin.c:1134 (handle_rpc_reply)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/libplugin.c:1438 (rpc_read_response_one)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/libplugin.c:1462 (rpc_conn_read_response)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     ccan/ccan/io/io.c:60 (next_plan)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     ccan/ccan/io/io.c:422 (do_plan)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     ccan/ccan/io/io.c:439 (io_ready)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     ccan/ccan/io/poll.c:455 (io_loop)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/libplugin.c:2564 (plugin_main)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/bkpr/bookkeeper.c:1547 (main)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     ../sysdeps/nptl/libc_start_call_main.h:58 (__libc_start_call_main)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     ../csu/libc-start.c:360 (__libc_start_main_impl)
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:   parents:
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/bkpr/account.c:51:struct account
lightningd-2 2025-08-28T02:36:35.630Z **BROKEN** plugin-bookkeeper:     plugins/bkpr/bookkeeper.c:1546:struct bkpr
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-28 13:42:04 +09:30
Rusty Russell
22a5e9e7e6 common: reintroduce "ignored" primary tag.
Prior to 23.05, we used this tag to mark onchain to-self inputs we didn't
wait for (because they were too small).  This fixes migration if that happened
(and we are debating whether we should re-introduce this!).

```
lightningd: FATAL SIGNAL 6 (version v25.09rc2)                      
0x100c8683 send_backtrace                                           
        common/daemon.c:33                                          
0x100c876f crashdump                                                
        common/daemon.c:78                                          
0x7fffb2080493 ???                                                  
        ???:0                                                       
0x7fffb1ab0cac ???                                                  
        __pthread_kill_implementation+0x1bc:0
0x7fffb1a48a5b ???                                                  
        __GI_raise+0x2b:0                                           
0x7fffb1a2a3db ???                                                  
        __GI_abort+0x153:0                                          
0x100935b7 migrate_from_account_db
        wallet/account_migration.c:424
0x10093ff7 db_migrate                                               
        wallet/db.c:1139                                            
0x10096763 db_setup                                                 
        wallet/db.c:1185                                            
0x100a1bcb wallet_new                                               
        wallet/wallet.c:223                                         
0x1004485f main                                                     
        lightningd/lightningd.c:1311
0x7fffb1a2aba3 ???                                                  
        __libc_start_call_main+0x93:0
0x7fffb1a2adeb ???                                                  
        __libc_start_main_alias_1+0x1ab:0
0xffffffffffffffff ???                                              
        ???:0                                                       
lightningd: Died with signal 6                                  
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: https://github.com/ElementsProject/lightning/issues/8484
2025-08-28 13:41:44 +09:30
Rusty Russell
1c537c258e pay: fix uninitialized var in debug output.
@nepet noted that Valgrind complained.  Nobody really cares though?
TL;DR: if channel isn't enabled, estimate isn't set.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-None: CI only
2025-08-27 12:53:38 +09:30
Rusty Russell
afa7aead24 offers: loosen payment_constraints on invoices' blinded paths.
In practice, we were too strict.  Here's Phoenix paying my node via another node:

```
2025-08-25T13:57:53.311Z DEBUG   02...-chan#216: Failing HTLC because of an invalid payload (TLV 10 pos 103): cltv_expiry 911816 > payment_constraint 911721
```

We add 6 blocks, but this is supposed to be the *max* allowed.  Increase it to 1008, to allow shadow padding.  Here are the CLTV delays across advertized channels in the network: most are far less than this:

Count   Delay
      1 0
      1 4
      3 12
    899 18
    602 20
      1 22
      3 24
      1 25
      9 26
      5 29
     72 30
     54 32
   4352 34
      2 35
      6 36
     10 37
     27 38
      8 39
  15256 40
     94 42
    102 44
     13 45
     20 46
     87 48
    230 50
    100 51
     14 55
    316 60
     29 64
     30 65
     24 68
     82 69
      9 70
    779 72
     13 77
    243 78
      1 79
  26793 80
      1 82
      6 83
      1 84
     18 85
      1 86
      9 87
     16 88
    101 89
      2 90
     11 96
    113 99
   9527 100
     41 112
     34 118
    132 119
    403 120
     24 128
    232 140
    138 142
  14303 144
      2 145
     41 150
      6 160
      3 172
      8 174
     27 180
      4 190
    297 200
     99 210
     34 216
    219 222
     15 240
    105 288
     17 300
      7 336
      1 360
     19 400
     24 420
     26 432
     20 450
      1 480
     12 500
      1 720
      1 850
      1 1000
      1 1002
      1 1144
      1 1192
      5 1201
      1 1444
      1 1795
      1 1900
      1 2016

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Protocol: Offers on nodes with only private channels are now payable (i.e. no more blinded path errors!).
Fixes: https://github.com/ElementsProject/lightning/issues/7718
2025-08-27 12:09:20 +09:30