Commit Graph

17025 Commits

Author SHA1 Message Date
Rusty Russell
815ac7e309 fuzz: fix compilation.
Header changes in master broke this upon rebase :(

```
In file included from ./channeld/full_channel.h:5,
                 from tests/fuzz/fuzz-full_channel.c:7:
./channeld/channeld_htlc.h:13:28: error: field ‘amount’ has incomplete type
   13 |         struct amount_msat amount;
      |                            ^~~~~~
./channeld/channeld_htlc.h:17:23: error: field ‘rhash’ has incomplete type
   17 |         struct sha256 rhash;
      |                       ^~~~~
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-10 17:09:08 +10:30
Chandra Pratap
fa28e07355 fuzz-tests: Add coverage-increasing inputs to seed corpora
Change in the fuzzing scheme of fuzz-hsm_encryption led to the
discovery of test inputs that result in greater in code coverage.
Add these inputs to the test's seed corpus.

[ Changed from fuzz-hsm_encryption to fuzz-hsm_secret --RR ]
2025-11-10 16:59:01 +10:30
Chandra Pratap
9be3eeea34 fuzz-tests: get rid of magic numbers in fuzz-hsm_encryption.c
Changelog-None: `fuzz-hsm_encryption.c` hard codes the lengths
sizeof(struct secret) as 32 and crypto_pwhash_argon2id_PASSWD_MAX
as 4294967295. Replace the latter with the former to improve
readability and maintainability.

While at it, replace the `tal_free()` call on our secret key with
`discard_key()`. This has the benefit of testing `discard_key()`.

[ Changed from fuzz-hsm_encryption to fuzz-hsm_secret --RR ]
2025-11-10 16:59:01 +10:30
Rusty Russell
b33f86bbb5 fuzz/fuzz-handle_onion_message.c: fix header order.
We check this now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-10 16:59:01 +10:30
Chandra Pratap
7bbaecd30e fuzz-tests: Add a seed corpus for the new test
Add a minimal input set as a seed corpus for the newly introduced
test. This leads to discovery of interesting code paths faster.
2025-11-10 15:36:36 +10:30
Chandra Pratap
76a7781cc3 fuzz-tests: Add a test for full_channel operations
Changelog-None: Functions defined in `channeld/full_channel.h`
contain channel operations like `ADD_HTLC`, `FULFILL_HTLC`,
`UPDATE_FEERATE`, etc.

Since they are a critical part of the HTLC state machine and may
be influenced by external agents, add a stateful test for them.
2025-11-10 15:36:36 +10:30
Chandra Pratap
df3043c4ef fuzz-tests: Add a seed corpus for the new test
Add a minimal input set as a seed corpus for the newly introduced
test. This leads to discovery of interesting code paths faster.
2025-11-10 15:14:31 +10:30
Chandra Pratap
c684e350f0 fuzz-tests: Add a test for the onion message handler
Changelog-None: `handle_onion_message()` in `connectd/onion_message.c`
is responsible for handling incoming onion messages from a peer.
Since it deals with external input, add a test for it.
2025-11-10 15:14:31 +10:30
ShahanaFarooqui
d723337af3 meta: Update version 25.09.3 and CHANGELOG
Changelog-None.
2025-11-10 15:08:08 +10:30
Peter Neuroth
21fb7600f3 lightningd: add invoice_amt to the htlc_accepted hook
This commit introduces a new field `invoice_msat` to the htlc_accepted
hook. If this field is specified it will replace the amount of the
invoice that belongs to the payment_hash of the HTLC on internal checks.

This is useful in scenarios where we actually expect a smaller amount
than initially specified in an invoice.

Changelog-Changed: Plugins: `htlc_accepted` hook can now override the
expected total amount of the invoice that belongs to the HTLC.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-10 15:05:27 +10:30
Peter Neuroth
572c4553a2 lightningd: add override amt to invoice_check_payment
Adds `expected_msat_override` to the `invoice_check_payment` check. If
it's set, it will be used to override the invoice amount as the expected
amount of the payment check.

This enables us to charge a different amount for a payment than the
amount stated on the invoice.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-10 15:05:27 +10:30
ShahanaFarooqui
193f24a039 docker: Install missing lowdown and libsodium dependencies 2025-11-07 07:12:12 +05:30
ShahanaFarooqui
2ee3f45247 docker: Install arch independent libraries separately 2025-11-07 07:12:12 +05:30
ShahanaFarooqui
cbefbf2a04 docker: Add missing sqlite library in final stage
Changelog-Fixed: Restored sqlite library dependency that was missing after Docker refactoring in v25.09.1 and v25.09.2
2025-11-07 07:12:12 +05:30
Sangbida Chaudhuri
f485eab855 makefile: Change hardcoded homebrew paths
We're removing the hardcoded homebrew paths for openssl and sqlite as those folder paths may not be correct for all macOS users. Instead we are now calling brew --prefix to get the correct path and use that to populate the LDFLAGS and CPPFLAGS
2025-11-07 11:03:45 +10:30
daywalker90
9d897b07f4 crates: bump cln-grpc-plugin to v0.5.0
Changelog-None
2025-11-07 11:01:50 +10:30
Rusty Russell
c9fdf60ac1 wallet: make p2tr the default address for newaddr.
Of course we still have to return a `bech32` for the deprecation period.

Changelog-Added: JSON-RPC: `newaddr` will now return a `p2tr` field by default.
Changelog-Deprecated: JSON-RPC: `newaddr` returning a `bech32` field if `addresstype` is not specified (use `p2tr`).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-07 10:51:04 +10:30
Rusty Russell
1e7ffeb89d tests: don't assume newaddr returns bech32 by default.
Either use p2tr (if not elements) or explicitly ask for a bech32 address.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-07 10:51:04 +10:30
Rusty Russell
fc2fb7cd70 sql: only create sql indices after initial load of data.
This makes a big difference for large tables.  Consider 1.6M channelmoves,
which took 82 seconds to populate, now takes 17 seconds:

Before:
	plugin-sql: Time to call listchannelmoves: 10.380341485 seconds
	plugin-sql: Time to refresh channelmoves: 82.311287310 seconds

After:

	plugin-sql: Time to call listchannelmoves: 9.962815480 seconds
	plugin-sql: Time to refresh channelmoves: 15.711549299 seconds
	plugin-sql: Time to refresh + create indices for channelmoves: 17.100151235 seconds

tests/test_coinmoves.py::test_generate_coinmoves (50,000):
	Time (from start to end of l2 node):	27 seconds
	Worst latency:				16.0 seconds

Changelog-Changed: Plugins: `sql` initial load for tables is much faster (e.g 82 to 17 seconds for very large channelmoves table).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-04 12:47:37 +10:30
Rusty Russell
1dda0c0753 bookkeeper: don't flood logs if we have many channelmoves all at once.
Since we're synchronous, these only reach lightningd after we're done:
in the case of 1.6M channelmoves, that can give it major heartburn.

In practice, this reduces the first bkpr command on a fresh upgrade
from 349 to 235 seconds (but this was before other improvements we did
this release).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Plugins: `bookkeeper` reduced logging for large imports to increase speed.
2025-11-04 12:47:37 +10:30
Rusty Russell
ac60568398 lightningd: fix case where injectpaymentonion failure results in listsendpays "pending".
If we failed after we register (e.g. channeld not available), we don't
mark it failed.  We shouldn't register until we've definitely created
the htlc.

Changelog-Fixed: `xpay` would sometimes leave payment parts status `pending` in failure cases (as seen in listpays or listsendpays).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: https://github.com/ElementsProject/lightning/issues/8629
2025-11-04 11:06:50 +10:30
Rusty Russell
350578d767 pytest: test that we correctly mark a payment part failed if we cannot queue it to the channeld for the peer.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-04 11:06:50 +10:30
Rusty Russell
43d7db7581 plugins/bcli: use -stdin to feed arguments, in case we have a giant tx.
```
lightningd-1 2025-10-27T11:26:04.285Z **BROKEN** plugin-bcli: bitcoin-cli exec failed: Argument list too long
```

Use -stdin to bitcoin-cli: we can then handle arguments of arbitrary length.

Fixes: https://github.com/ElementsProject/lightning/issues/8634
Changelog-Fixed: plugins: `bcli` would fail with "Argument list too long" when sending a giant tx.
2025-11-03 14:49:33 +10:30
Rusty Russell
5d64eb9ac4 pytest: test for bcli crash with huge PSBTs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-03 14:49:33 +10:30
Rusty Russell
48c3df9175 common: remove tal_check() call on libwally allocations.
We call it once at the end, but calling on each allocation is
excessive, and it shows when dealing with large PSBTS.  Testing a
700-input PSBT was unusably slow without this: after this the entire
test ran in 9 seconds.

Changelog-Fixed: JSON-RPC: Dealing with giant PSBTs (700 inputs!) is now much faster.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-03 14:49:33 +10:30
Rusty Russell
bd1798323a bookkeeper: fix assert() which happens with parallel queries.
```
bookkeeper: plugins/bkpr/bookkeeper.c:1226: parse_and_log_chain_move: Assertion `e->db_id > bkpr->chainmoves_index' failed.
bookkeeper: FATAL SIGNAL 6 (version v25.09-245-g901714b-modded)
0x5d7d8718b40f send_backtrace
        common/daemon.c:36
0x5d7d8718b4ab crashdump
        common/daemon.c:81
0x7a6086c4532f ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x7a6086c9eb2c __pthread_kill_implementation
        ./nptl/pthread_kill.c:44
0x7a6086c9eb2c __pthread_kill_internal
        ./nptl/pthread_kill.c:78
0x7a6086c9eb2c __GI___pthread_kill
        ./nptl/pthread_kill.c:89
0x7a6086c4527d __GI_raise
        ../sysdeps/posix/raise.c:26
0x7a6086c288fe __GI_abort
        ./stdlib/abort.c:79
0x7a6086c2881a __assert_fail_base
        ./assert/assert.c:96
0x7a6086c3b516 __assert_fail
        ./assert/assert.c:105
0x5d7d8717505d parse_and_log_chain_move
        plugins/bkpr/bookkeeper.c:1226
0x5d7d871754f4 listchainmoves_done
        plugins/bkpr/bookkeeper.c:169
0x5d7d87182a4b handle_rpc_reply
        plugins/libplugin.c:1072
0x5d7d87182b5c rpc_conn_read_response
        plugins/libplugin.c:1361
0x5d7d871ba660 next_plan
        ccan/ccan/io/io.c:60
0x5d7d871bab31 do_plan
        ccan/ccan/io/io.c:422
0x5d7d871babee io_ready
        ccan/ccan/io/io.c:439
```

Reported-by: @michael1011
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: plugins: assertion crash in bookkeeper when fresh records arrive while multiple queries in progress.
2025-11-03 14:03:25 +10:30
Rusty Russell
c38699559d pytest: test for parallel bookkeeper queries.
If both refresh new events, we will get an assertion:

```
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-03 14:03:25 +10:30
Rusty Russell
07c57b6015 askrene: implement 10-second deadline.
We have another report of looping.  This maxparts code is being completely
rewritten, but it's good to have a catchall for any other cases which might
emerge.

I had to make it customizable since our tests under valgrind are SLOW!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-03 12:54:37 +10:30
Rusty Russell
03d38b612d askrene: fix infinite loop if refine_flows() cuts down our last flow with 1 remaining before maxparts.
1. We would find a flow.
2. refine_flow would reduce it so it doesn't deliver enough.
3. So we need to find another, but we are at the limit.
4. So we remove the flow we found.
5. Goto 1.

This can be fixed by disabling a channel which we caused us to reduce the flow,
so we should always make forward progress.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Plugins: `askrene` could enter an infinite loop when maxparts is restricted.
2025-11-03 12:54:37 +10:30
Rusty Russell
6b480c74f8 pytest: test for askrene infinite loop with maxparts set.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-03 12:54:37 +10:30
Rusty Russell
5106440c32 bookkeeper: fix restoration of derived wallet blockheights on restart.
We complain:
```
lightningd-1 2025-10-31T00:55:00.377Z **BROKEN** plugin-bookkeeper: Unparsable blockheight datastore entry: {"key":["bookkeeper","blockheights","756999f870a7a7c97f5c143f12b9096a50d1b1acd74aeb9ab2dc251a5c361494"],"generation":0,"hex":"00000067"}
```

And we don't have the blockheight:

```
                   {
                       'account': 'external',
         -             'blockheight': 103,
         ?                            - -
         +             'blockheight': 0,
                       'credit_msat': 555555000,
                       'currency': 'bcrt',
                       'debit_msat': 0,
                       'origin': 'wallet',
                       'outpoint': '756999f870a7a7c97f5c143f12b9096a50d1b1acd74aeb9ab2dc251a5c361494:0',
                       'tag': 'deposit',
                       'timestamp': 1761872097,
                       'type': 'chain',
                   },
```

Reported-by: @michael1011
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Plugins: `bookkeeper` now correctly restores chain event blockheights it has derived.
2025-11-03 12:36:38 +10:30
Rusty Russell
5f2e3248af pytest: test for blockheight entries in bookkeeper being saved across restart.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-03 12:36:38 +10:30
Erick Cestari
c70b70b636 Remove libsodium and lowdown submodules to fix recursive clone
These submodules were causing failures during recursive git clone
operations. The submodule entries were still registered in the git
tree even though they were removed from .gitmodules, causing:
"fatal: No url found for submodule path 'external/lightning/external/libsodium'"
and similar errors for lowdown.

This removes both submodule references from the git index to resolve
recursive submodule initialization failures (exit code 128).

Changelog-None
2025-11-01 08:19:54 +10:30
ShahanaFarooqui
57663bb380 docker: install lowdown and libsodium-dev for reproducible builds
After external lowdown and libsodium-dev removal with PR #8536, we need to explicitly install them in Dockerfiles.
2025-10-31 12:04:01 +10:30
ShahanaFarooqui
7170fe225a tests: check openssl version compatibility for fuzz tests
This check will exclude fuzz tests for Ubuntu Focal as it supports OpenSSL v1.1.1f while CLN requires ≥ v3.0.
2025-10-31 12:04:01 +10:30
Rusty Russell
4f9e13c000 GitHub: add --durations=10 to pytest runs.
This allows us to show what tests are slowest, by showing the duration for anything
which took 10 seconds or longer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-28 11:03:33 +10:30
Rusty Russell
82fff3c74b Remove litecoin support.
No idea if it works, we don't test it and nobody runs it.  I guess not.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: Config: non-functioning litecoin support (who knew we even had that?)
2025-10-26 20:31:45 +10:30
Rusty Russell
f3b227f8af external/libsodium: remove
We shipped our own because Ubuntu xenial (16.4) had an ancient one.

Changelog-Changed: Build: libsodium version >= 1.0.4 now required (released 2015-06-11)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-26 20:31:45 +10:30
Rusty Russell
226533958a external/lowdown: remove.
Every distribution we have packages this now.

Changelog-Changed: Build: lowdown is now required (we no longer bundle our own).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-26 20:31:45 +10:30
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
6a84fc2d47 pytest: don't ask for p2tr addresses on liquid.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-26 12:37:58 +10:30
Sangbida Chaudhuri
32bb0ed20e hsmd_wire: remove hsmd_derive_bip86_key and add it to hsmd_init_reply_v4
Instead of having a separate field to derive the bip86 base key, we return it in the hsmd init reply once we know that the hsm_secret is of mnemonic type
2025-10-26 12:37:58 +10:30
Rusty Russell
16ae5a4b50 common: trivial changes from review.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-26 12:37:58 +10:30
Rusty Russell
6c15f1e364 common/hsm_secret: remove grab_file_contents now it has inspired grab_file_raw!
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-26 12:37:58 +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
b676171f86 hsm_secret: fixup! make read_line tidier 2025-10-26 12:37:58 +10:30
Sangbida Chaudhuri
a289cd4ff5 hsm_control: fixup! old comment 2025-10-26 12:37:58 +10:30
Sangbida Chaudhuri
463712f3b7 utils: add a generic mlock function with a destructor
Introduces a generic utility function to replace the repeated pattern of
sodium_mlock() + tal_add_destructor()
2025-10-26 12:37:58 +10:30
Sangbida Chaudhuri
310405761a schema: update schema to remove bip86 and add mnemonic to expose secret
This schema change updates newaddr to remove bip86 which was previously added, since don't want to make unnecessary schema changes this is being removed.

The generated files for the exposesecret schema change are also being added
2025-10-26 12:37:58 +10:30
Sangbida Chaudhuri
5f67e7dd9d doc: change encrypted-hsm to hsm-passphrase 2025-10-26 12:37:58 +10:30