Commit Graph

16915 Commits

Author SHA1 Message Date
Rusty Russell
abe09ec03e common/node_id: runtime assertion override, not separate compile time for fuzzing.
This makes it trivial to run the fuzz tests as unit tests in non-fuzzing mode.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-23 06:44:04 +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
bc44d3c629 devtools/reduce-includes.sh: don't remove our own .h from .c file includes.
Even if we would currently include it indirectly, we must include it directly.

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
6b50994420 Makefile: helper to print the binary sizes.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-23 06:44:04 +10:30
Rusty Russell
2114e617ad lightningd: fix scb remote_to_self_delay information.
This was changing all the time when I tried to make
autogenerate-rpc-examples.py reproducible.  Turns out it was being
corrupted (it does suspicious things with pointers); rather than try
to diagnose it, I simply rewrote the code to create it only when we
need it.

```
Valgrind error file: valgrind-errors.34506
==34506== Uninitialised byte(s) found during client check request
==34506==    at 0x241732: memcheck_ (mem.h:247)
==34506==    by 0x2417BC: towire (towire.c:17)
==34506==    by 0x24185C: towire_u16 (towire.c:28)
==34506==    by 0x20C8E4: towire_tlv_scb_tlvs_remote_to_self_delay (scb_wiregen.c:213)
==34506==    by 0x240E78: towire_tlv (tlvstream.c:342)
==34506==    by 0x20C99F: towire_tlv_scb_tlvs (scb_wiregen.c:234)
==34506==    by 0x20C298: towire_modern_scb_chan (scb_wiregen.c:89)
==34506==    by 0x1A6CF3: json_add_scb (peer_control.c:2488)
==34506==    by 0x1A6E0C: json_staticbackup (peer_control.c:2519)
==34506==    by 0x177E3F: command_exec (jsonrpc.c:799)
==34506==    by 0x1785AE: rpc_command_hook_final (jsonrpc.c:945)
==34506==    by 0x1BEC2D: plugin_hook_call_next (plugin_hook.c:199)
==34506==  Address 0x1ffeffe736 is on thread 1's stack
==34506==  in frame #2, created by towire_u16 (towire.c:26)
==34506== 
{
   <insert_a_suppression_name_here>
   Memcheck:User
   fun:memcheck_
   fun:towire
   fun:towire_u16
   fun:towire_tlv_scb_tlvs_remote_to_self_delay
   fun:towire_tlv
   fun:towire_tlv_scb_tlvs
   fun:towire_modern_scb_chan
   fun:json_add_scb
   fun:json_staticbackup
   fun:command_exec
   fun:rpc_command_hook_final
   fun:plugin_hook_call_next
}
==34506== Uninitialised byte(s) found during client check request
==34506==    at 0x241732: memcheck_ (mem.h:247)
==34506==    by 0x2417BC: towire (towire.c:17)
==34506==    by 0x240EF0: towire_tlv (tlvstream.c:354)
==34506==    by 0x20C99F: towire_tlv_scb_tlvs (scb_wiregen.c:234)
==34506==    by 0x20C298: towire_modern_scb_chan (scb_wiregen.c:89)
==34506==    by 0x1A6CF3: json_add_scb (peer_control.c:2488)
==34506==    by 0x1A6E0C: json_staticbackup (peer_control.c:2519)
==34506==    by 0x177E3F: command_exec (jsonrpc.c:799)
==34506==    by 0x1785AE: rpc_command_hook_final (jsonrpc.c:945)
==34506==    by 0x1BEC2D: plugin_hook_call_next (plugin_hook.c:199)
==34506==    by 0x1BEBA8: plugin_hook_callback (plugin_hook.c:186)
==34506==    by 0x1B771E: plugin_response_handle (plugin.c:705)
==34506==  Address 0x7bd1d08 is 40 bytes inside a block of size 42 alloc'd
==34506==    at 0x484DCD3: realloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==34506==    by 0x3C8614: tal_resize_ (tal.c:755)
==34506==    by 0x2417A2: towire (towire.c:14)
==34506==    by 0x24185C: towire_u16 (towire.c:28)
==34506==    by 0x20C8E4: towire_tlv_scb_tlvs_remote_to_self_delay (scb_wiregen.c:213)
==34506==    by 0x240E78: towire_tlv (tlvstream.c:342)
==34506==    by 0x20C99F: towire_tlv_scb_tlvs (scb_wiregen.c:234)
==34506==    by 0x20C298: towire_modern_scb_chan (scb_wiregen.c:89)
==34506==    by 0x1A6CF3: json_add_scb (peer_control.c:2488)
==34506==    by 0x1A6E0C: json_staticbackup (peer_control.c:2519)
==34506==    by 0x177E3F: command_exec (jsonrpc.c:799)
==34506==    by 0x1785AE: rpc_command_hook_final (jsonrpc.c:945)
==34506==
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-23 06:44:04 +10:30
Rusty Russell
5bf5f3b3ae pytest: print useful information if we don't get our channelmoves/chainmoves
The equality check will fail, but it will show is what is missing, rather than:

FAILED tests/test_coinmoves.py::test_coinmoves_unilateral_htlc_fulfill - ValueError: Timeout while waiting for <function check_chain_moves.<locals>.<lambda> at 0x7f7800941ab0>

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-22 19:43:24 +10:30
Rusty Russell
e0c60cf9e1 pytest: more flakes with "lucky sigs" in coinmoves.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-22 19:43:24 +10:30
Sangbida Chaudhuri
ad0c7318c1 makefile: fix glob expansion for macOS
when bash expands bitcoin/*.h, it returns the files in lexicographically sorted order by default this is not necessarily the case for macOS so it has be explicitly sorted. I get a fairly uninformative error like this:

make: *** [check-bitcoin-makefile] Error 1

The error is now more informative and does not error on a clean branch on macOS:

BITCOIN_HEADERS missing: bitcoin/signature.h bitcoin/tx_parts.h bitcoin/tx.h bitcoin/varint.h
make: *** [check-bitcoin-makefile] Error 1
2025-10-22 11:44:02 +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
2c02f6d140 pytest: test (failing) for bkpr-listincome filtering times on onchain events.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-21 20:21:56 +10:30
ShahanaFarooqui
9255c255cf gpg: Updating Shahana's expired keys
Also added Madeline's missing keys on security-policy  page.

Changelog-None.
2025-10-21 11:19:46 +05:30
Madeline Vibes
766db61370 Meta: Adding changelog and version update for 25.09.1 2025-10-21 08:17:35 +05:30
ShahanaFarooqui
aa86e13745 doc: Add step for point release checklist to merge updates from update-versions and CHANGELOG.md into master
Changelog-None.
2025-10-21 08:16:59 +05:30
Peter Neuroth
51e6387c8d test: refactor plugin to use parameter not envvar
Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-10-20 17:15:44 +10:30
Peter Neuroth
5932d3b766 test: check that features get removed when ...
a plugin is disabled during init.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-10-20 17:15:44 +10:30
Peter Neuroth
652b3c2bef plugin: fix feature_set allocation
Using `tal_dup_or_null` does not set the tal context to the included
bytes array. Luckily we already have a function tha deeply duplicates
a `feature_set`: `feature_set_dup`

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-10-20 17:15:44 +10:30
ShahanaFarooqui
ea2f7607b8 tools: Read the correct default-key from gpgconf
Workflow error `gpg: using "4129A994AA7E9852" is thrown due to incorrect gpg parsing. Update the awk parsing logic to properly locate and extract the key fingerprint within the gpgconf --list-options output structure, ensuring automated signing uses the correct key.

Changelog-None.
2025-10-20 16:07:29 +10:30
Sangbida Chaudhuri
8578d6cd1b makefile: enable fuzzing support on macOS
Enable fuzzing support on macOS by configuring the build system to use Homebrew LLVM toolchain and handle macOS-specific linking requirements.

The `make check-fuzz` command was failing on macOS because:
- System clang lacks fuzzer runtime library support
- Linking issues with fuzzer targets
- Test script attempts to execute debug symbol files

This PR adds macOS-specific configuration to:
- Use Homebrew LLVM toolchain for fuzzer support
- Explicitly link fuzzer libraries
- Exclude `.dSYM` directories from test discovery

All 76 fuzzer targets now build and pass on macOS.
2025-10-20 14:34:20 +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
23784a4ebd configure: set SED to gsed (MacOS et al) or sed (GNU).
We use some GNU sed features and it's easier to require gsed than fix
them all (and keep noticing when they break).  MacOS comes with gsed
already!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-17 10:40:17 +10:30
Rusty Russell
992771bbdf pytest: fix flakes in feerates.
Sometimes we get a shorter signature than expected, and we're supposed
to disable the feerate tests in that case.  But we didn't catch all the
cases where we make signatures.

```
2025-10-13T02:36:24.1901527Z ____________________________ test_peer_anchor_push _____________________________
2025-10-13T02:36:24.1902251Z [gw5] linux -- Python 3.10.18 /home/runner/work/lightning/lightning/.venv/bin/python
2025-10-13T02:36:24.1902731Z 
2025-10-13T02:36:24.1903045Z node_factory = <pyln.testing.utils.NodeFactory object at 0x7f17fdffd6f0>
2025-10-13T02:36:24.1903740Z bitcoind = <pyln.testing.utils.BitcoinD object at 0x7f17fdffe830>
2025-10-13T02:36:24.1904495Z executor = <concurrent.futures.thread.ThreadPoolExecutor object at 0x7f17fdffcbb0>
2025-10-13T02:36:24.1906158Z chainparams = {'bip173_prefix': 'bcrt', 'chain_hash': '06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f', 'elements': False, 'example_addr': 'bcrt1qeyyk6sl5pr49ycpqyckvmttus5ttj25pd0zpvg', ...}
2025-10-13T02:36:24.1907285Z 
2025-10-13T02:36:24.1907600Z     @unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd anchors not supportd')
2025-10-13T02:36:24.1908344Z     def test_peer_anchor_push(node_factory, bitcoind, executor, chainparams):
2025-10-13T02:36:24.1909033Z         """Test that we use anchor on peer's commit to CPFP tx"""
2025-10-13T02:36:24.1909853Z         l1, l2, l3 = node_factory.line_graph(3, opts=[{},
2025-10-13T02:36:24.1910334Z                                                       {'min-emergency-msat': 546000,
2025-10-13T02:36:24.1910825Z                                                        'dev-warn-on-overgrind': None,
2025-10-13T02:36:24.1911313Z                                                        'broken_log': 'overgrind: short signature length'},
2025-10-13T02:36:24.1911662Z                                                       {'disconnect': ['-WIRE_UPDATE_FULFILL_HTLC'],
2025-10-13T02:36:24.1911976Z                                                        'dev-warn-on-overgrind': None,
2025-10-13T02:36:24.1912304Z                                                        'broken_log': 'overgrind: short signature length'}],
2025-10-13T02:36:24.1912790Z                                              wait_for_announce=True)
2025-10-13T02:36:24.1913041Z     
2025-10-13T02:36:24.1913305Z         # We splinter l2's funds so it's forced to use more than one UTXO to push.
2025-10-13T02:36:24.1914043Z         fundsats = int(Millisatoshi(only_one(l2.rpc.listfunds()['outputs'])['amount_msat']).to_satoshi())
2025-10-13T02:36:24.1914443Z         OUTPUT_SAT = 10000
2025-10-13T02:36:24.1914647Z         NUM_OUTPUTS = 10
2025-10-13T02:36:24.1914903Z         psbt = l2.rpc.fundpsbt("all", "1000perkw", 1000)['psbt']
2025-10-13T02:36:24.1915520Z         # Pay 5k sats in fees.
2025-10-13T02:36:24.1916329Z         psbt = l2.rpc.addpsbtoutput(fundsats - OUTPUT_SAT * NUM_OUTPUTS - 5000, psbt, destination=l3.rpc.newaddr()['bech32'])['psbt']
2025-10-13T02:36:24.1917156Z         for _ in range(NUM_OUTPUTS):
2025-10-13T02:36:24.1917638Z             psbt = l2.rpc.addpsbtoutput(OUTPUT_SAT, psbt)['psbt']
2025-10-13T02:36:24.1918194Z         l2.rpc.sendpsbt(l2.rpc.signpsbt(psbt)['signed_psbt'])
2025-10-13T02:36:24.1918731Z         bitcoind.generate_block(1, wait_for_mempool=1)
2025-10-13T02:36:24.1919232Z         sync_blockheight(bitcoind, [l1, l2])
2025-10-13T02:36:24.1919634Z     
2025-10-13T02:36:24.1919847Z         # Make sure all amounts are below OUTPUT_SAT sats!
2025-10-13T02:36:24.1920318Z         assert [x for x in l2.rpc.listfunds()['outputs'] if x['amount_msat'] > Millisatoshi(str(OUTPUT_SAT) + "sat")] == []
2025-10-13T02:36:24.1920735Z     
2025-10-13T02:36:24.1920957Z         # Get HTLC stuck, so l2 has reason to push commitment tx.
2025-10-13T02:36:24.1921244Z         amt = 100_000_000
2025-10-13T02:36:24.1921517Z         sticky_inv = l3.rpc.invoice(amt, 'sticky', 'sticky')
2025-10-13T02:36:24.1921842Z         route = l1.rpc.getroute(l3.info['id'], amt, 1)['route']
2025-10-13T02:36:24.1922277Z         l1.rpc.sendpay(route, sticky_inv['payment_hash'], payment_secret=sticky_inv['payment_secret'])
2025-10-13T02:36:24.1922751Z         l3.daemon.wait_for_log('dev_disconnect: -WIRE_UPDATE_FULFILL_HTLC')
2025-10-13T02:36:24.1923060Z     
2025-10-13T02:36:24.1923241Z         # Make sure HTLC expiry is what we expect!
2025-10-13T02:36:24.1923637Z         l2.daemon.wait_for_log('Adding HTLC 0 amount=100000000msat cltv=119 gave CHANNEL_ERR_ADD_OK')
2025-10-13T02:36:24.1923998Z     
2025-10-13T02:36:24.1924229Z         # l3 drops to chain, but make sure it doesn't CPFP its own anchor.
2025-10-13T02:36:24.1924685Z         wait_for(lambda: only_one(l3.rpc.listpeerchannels(l2.info['id'])['channels'])['htlcs'] != [])
2025-10-13T02:36:24.1925688Z         closetx = l3.rpc.dev_sign_last_tx(l2.info['id'])['tx']
2025-10-13T02:36:24.1926132Z         l3.stop()
2025-10-13T02:36:24.1926337Z         # We don't care about l1 any more, either
2025-10-13T02:36:24.1926579Z         l1.stop()
2025-10-13T02:36:24.1926739Z     
2025-10-13T02:36:24.1926941Z         # We put l3's tx in the mempool, but won't mine it.
2025-10-13T02:36:24.1927316Z         bitcoind.rpc.sendrawtransaction(closetx)
2025-10-13T02:36:24.1927754Z     
2025-10-13T02:36:24.1928139Z         # We aim for feerate ~3750, so this won't mine l3's unilateral close.
2025-10-13T02:36:24.1928991Z         # HTLC's going to time out at block 120 (we give one block grace)
2025-10-13T02:36:24.1929527Z         for block in range(110, 120):
2025-10-13T02:36:24.1929989Z             bitcoind.generate_block(1, needfeerate=5000)
2025-10-13T02:36:24.1930510Z             assert bitcoind.rpc.getblockcount() == block
2025-10-13T02:36:24.1931014Z             sync_blockheight(bitcoind, [l2])
2025-10-13T02:36:24.1931715Z         assert only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['state'] == 'CHANNELD_NORMAL'
2025-10-13T02:36:24.1932368Z     
2025-10-13T02:36:24.1932642Z         # Drops to chain
2025-10-13T02:36:24.1933030Z         bitcoind.generate_block(1, needfeerate=5000)
2025-10-13T02:36:24.1933824Z         wait_for(lambda: only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['state'] == 'AWAITING_UNILATERAL')
2025-10-13T02:36:24.1934522Z     
2025-10-13T02:36:24.1935254Z         # But, l3's tx already there, and identical feerate will not RBF.
2025-10-13T02:36:24.1935839Z         l2.daemon.wait_for_log("rejecting replacement")
2025-10-13T02:36:24.1936357Z         wait_for(lambda: len(bitcoind.rpc.getrawmempool()) == 2)
2025-10-13T02:36:24.1936801Z     
2025-10-13T02:36:24.1937127Z         # As blocks pass, we will use anchor to boost l3's tx.
2025-10-13T02:36:24.1937666Z         for block, feerate in zip(range(120, 124), (12000, 13000, 14000, 15000)):
2025-10-13T02:36:24.1938560Z             l2.daemon.wait_for_log(fr"Worth fee [0-9]*sat for remote commit tx to get 100000000msat at block 125 \(\+{125 - block}\) at feerate {feerate}perkw")
2025-10-13T02:36:24.1939369Z             l2.daemon.wait_for_log("sendrawtx exit 0")
2025-10-13T02:36:24.1939902Z             # Check feerate for entire package (commitment tx + anchor) is ~ correct
2025-10-13T02:36:24.1940473Z             details = bitcoind.rpc.getrawmempool(True).values()
2025-10-13T02:36:24.1940920Z             print(f"mempool = {details}")
2025-10-13T02:36:24.1941347Z             total_weight = sum([d['weight'] for d in details])
2025-10-13T02:36:24.1941903Z             total_fees = sum([float(d['fees']['base']) * 100_000_000 for d in details])
2025-10-13T02:36:24.1942467Z             total_feerate_perkw = total_fees / total_weight * 1000
2025-10-13T02:36:24.1942972Z >           check_feerate([l3, l2], total_feerate_perkw, feerate)
2025-10-13T02:36:24.1943279Z 
2025-10-13T02:36:24.1943411Z tests/test_closing.py:4064: 
2025-10-13T02:36:24.1943813Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2025-10-13T02:36:24.1944170Z 
2025-10-13T02:36:24.1944685Z nodes = [<fixtures.LightningNode object at 0x7f17fdf684f0>, <fixtures.LightningNode object at 0x7f17fdf6af50>]
2025-10-13T02:36:24.1945708Z actual_feerate = 13005.66942869603, expected_feerate = 13000
2025-10-13T02:36:24.1946091Z 
2025-10-13T02:36:24.1946247Z     def check_feerate(nodes, actual_feerate, expected_feerate):
2025-10-13T02:36:24.1946558Z         # Feerate can't be lower.
2025-10-13T02:36:24.1946870Z         assert actual_feerate > expected_feerate - 2
2025-10-13T02:36:24.1947365Z         if actual_feerate >= expected_feerate + 2:
2025-10-13T02:36:24.1947830Z             if any([did_short_sig(n) for n in nodes]):
2025-10-13T02:36:24.1948239Z                 return
2025-10-13T02:36:24.1948589Z         # Use assert as it shows the actual values on failure
2025-10-13T02:36:24.1949043Z >       assert actual_feerate < expected_feerate + 2
2025-10-13T02:36:24.1949489Z E       AssertionError
2025-10-13T02:36:24.1949704Z 
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-14 09:48:02 +10:30
Rusty Russell
fc6bee8950 connectd: close connection properly after dev-disconnect +.
We need to drain subds too, otherwise if timing is correct we never close.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-14 09:48:02 +10:30
Rusty Russell
af340a6817 ccan: update to latest.
We fix the configure test which was bogus, and breaks on 32-bit gcc with optimization:

```
checking for unaligned access to int... ccan/tools/configurator/configurator: Test for HAVE_UNALIGNED_ACCESS did not compile:
configuratortest.c: In function 'main':
configuratortest.c:8:22: error: array subscript 'int[0]' is partly outside array bounds of 'char[4]' [-Werror=array-bounds]
     8 |         return *x == *y;
        |                      ^~
configuratortest.c:5:11: note: at offset 1 into object 'pad' of size 4
     5 |      char pad[sizeof(int *) * 1];
        |           ^~~
cc1: all warnings being treated as errors
```

And also removes sprintf() calls, which apparently MacOS no longer likes:

Environment: Sequoia 15.6.1 (24G90)
SDK Version: MacOSX15.sdk

```
ccan/ccan/closefrom/closefrom.c:83:2: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations]
   83 |         sprintf(dnam, "/proc/%ld/fd", (long) getpid());
      |         ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:278:1: note: 'sprintf' has been explicitly marked deprecated here
  278 | deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
      | ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:218:48: note: expanded from macro 'deprecated_msg'
  218 |         #define deprecated_msg(_msg) attribute((deprecated(_msg)))
      |                                                       ^
ccan/ccan/closefrom/closefrom.c:162:2: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations]
  162 |         sprintf(dnam, "/proc/%ld/fd", (long) getpid());
      |         ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:278:1: note: 'sprintf' has been explicitly marked deprecated here
  278 | deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
      | ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:218:48: note: expanded from macro 'deprecated_msg'
  218 |         #define deprecated_msg(_msg) attribute((deprecated(_msg)))
      |                                                       ^
2 errors generated.
make: *** [ccan-closefrom.o] Error 1
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reported-by: Sangbida
Fixes: https://github.com/ElementsProject/lightning/issues/8581
Reported-by: https://github.com/Raimo33
Fixes: https://github.com/ElementsProject/lightning/issues/8501
Changelog-Fixed: build: we now build on MacOS without errors on the latest Command Line Tools (macOS 15 SDK).
Changelog-Fixes: build: fix build with -O2 on 32 bit arm (armhf)
2025-10-14 09:17:29 +10:30
Rusty Russell
9f2e6de69c wallet: fix migration speed for postgres.
Testing a large db shows Postgres slowing down exponentially as
it inserts the channel_events.  Rather than updating the index in the
db every time, do it at the end, for spectacular speedup:

```
lightningd-1 2025-10-08T05:39:44.333Z INFO    lightningd: Creating database
lightningd-1 2025-10-08T05:39:47.581Z DEBUG   lightningd: Transferring 6166 chain_events
lightningd-1 2025-10-08T05:39:48.455Z DEBUG   lightningd: Transferring 1660043 channel_events
lightningd-1 2025-10-08T05:39:54.390Z INFO    lightningd: Inserted 103100/1660043 channel_events
lightningd-1 2025-10-08T05:40:04.390Z INFO    lightningd: Inserted 283280/1660043 channel_events
lightningd-1 2025-10-08T05:40:14.390Z INFO    lightningd: Inserted 464065/1660043 channel_events
lightningd-1 2025-10-08T05:40:24.390Z INFO    lightningd: Inserted 629559/1660043 channel_events
lightningd-1 2025-10-08T05:40:34.390Z INFO    lightningd: Inserted 800659/1660043 channel_events
lightningd-1 2025-10-08T05:40:44.390Z INFO    lightningd: Inserted 975433/1660043 channel_events
lightningd-1 2025-10-08T05:40:54.390Z INFO    lightningd: Inserted 1134719/1660043 channel_events
lightningd-1 2025-10-08T05:41:04.390Z INFO    lightningd: Inserted 1290549/1660043 channel_events
lightningd-1 2025-10-08T05:41:14.390Z INFO    lightningd: Inserted 1443304/1660043 channel_events
lightningd-1 2025-10-08T05:41:24.390Z INFO    lightningd: Inserted 1590013/1660043 channel_events
lightningd-1 2025-10-08T05:41:29.148Z INFO    lightningd: bookkeeper migration complete: migrated 6166 chainmoves, 1660043 channelmoves, 132481 descriptions
```

Now we complete the entire migration in 1 minute 45 seconds.

Thanks to @michael1101 for reporting this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: db: migration from v25.09 on a reasonable size account database could take almost infinite time.
2025-10-13 14:15:32 +10:30
Rusty Russell
2f80305b91 lightningd: explicit db arg to wait_index_increase so we can use it in migrations.
Before db is complete, ld->wallet->db is NULL.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-13 14:15:32 +10:30
Rusty Russell
b260ec2f21 wallet: print progress reports for large account migration.
Show the work we're doing (at debug level) and every 10 seconds print
progress (at INFO level):x

```
lightningd-1 2025-10-08T05:13:07.973Z INFO    lightningd: Creating database
lightningd-1 2025-10-08T05:13:10.987Z DEBUG   lightningd: Transferring 6166 chain_events
lightningd-1 2025-10-08T05:13:11.780Z DEBUG   lightningd: Transferring 1660043 channel_events
```

It's the inserting channel_events which takes a long time, slowing
down exponentially:

```
lightningd-1 2025-10-08T05:13:18.034Z INFO    lightningd: Inserted 26690/1660043 channel_events
lightningd-1 2025-10-08T05:13:28.034Z INFO    lightningd: Inserted 47086/1660043 channel_events
lightningd-1 2025-10-08T05:13:38.035Z INFO    lightningd: Inserted 61699/1660043 channel_events
lightningd-1 2025-10-08T05:13:48.035Z INFO    lightningd: Inserted 73743/1660043 channel_events
lightningd-1 2025-10-08T05:13:58.035Z INFO    lightningd: Inserted 83244/1660043 channel_events
...
lightningd-1 2025-10-08T05:35:18.286Z INFO    lightningd: Inserted 466720/1660043 channel_events
lightningd-1 2025-10-08T05:35:29.074Z INFO    lightningd: Inserted 468437/1660043 channel_events
lightningd-1 2025-10-08T05:35:39.079Z INFO    lightningd: Inserted 470130/1660043 channel_events
lightningd-1 2025-10-08T05:35:49.081Z INFO    lightningd: Inserted 471871/1660043 channel_events
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-13 14:15:32 +10:30
Rusty Russell
01e83b7637 lightningd: handle unparsable onion from first hop when using injectonionmessage.
In this case we have a failmsg, so we should use that.  Otherwise we can have
both failmsg and failonion NULL in the call to injectonion_fail, which is not
valid.

```
DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-chan#1: Removing out HTLC 1 state RCVD_REMOVE_ACK_REVOCATION WIRE_INVALID_ONION_HMAC
**BROKEN** lightningd: FATAL SIGNAL 11 (version v25.09-135-g19a3bbc-modded)
**BROKEN** lightningd: backtrace: common/daemon.c:41 (send_backtrace) 0x6220e8fe0080
**BROKEN** lightningd: backtrace: common/daemon.c:78 (crashdump) 0x6220e8fe00cf
**BROKEN** lightningd: backtrace: ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0 ((null)) 0x73614bc4532f
**BROKEN** lightningd: backtrace: lightningd/pay.c:1701 (injectonion_fail) 0x6220e8f951c0
**BROKEN** lightningd: backtrace: lightningd/pay.c:330 (tell_waiters_failed) 0x6220e8f943be
**BROKEN** lightningd: backtrace: lightningd/pay.c:656 (payment_failed) 0x6220e8f98db1
**BROKEN** lightningd: backtrace: lightningd/peer_htlcs.c:313 (fail_out_htlc) 0x6220e8fa1d04
**BROKEN** lightningd: backtrace: lightningd/peer_htlcs.c:1988 (remove_htlc_out) 0x6220e8fa271b
**BROKEN** lightningd: backtrace: lightningd/peer_htlcs.c:2086 (update_out_htlc) 0x6220e8fa2904
**BROKEN** lightningd: backtrace: lightningd/peer_htlcs.c:2095 (changed_htlc) 0x6220e8fa2c24
**BROKEN** lightningd: backtrace: lightningd/peer_htlcs.c:2608 (peer_got_revoke) 0x6220e8fa6e5a
**BROKEN** lightningd: backtrace: lightningd/channel_control.c:1555 (channel_msg) 0x6220e8f62725
**BROKEN** lightningd: backtrace: lightningd/subd.c:560 (sd_msg_read) 0x6220e8fb2eed
**BROKEN** lightningd: backtrace: ccan/ccan/io/io.c:60 (next_plan) 0x6220e90a3335
**BROKEN** lightningd: backtrace: ccan/ccan/io/io.c:422 (do_plan) 0x6220e90a3806
**BROKEN** lightningd: backtrace: ccan/ccan/io/io.c:439 (io_ready) 0x6220e90a38c3
**BROKEN** lightningd: backtrace: ccan/ccan/io/poll.c:455 (io_loop) 0x6220e90a524f
**BROKEN** lightningd: backtrace: lightningd/io_loop_with_timers.c:22 (io_loop_with_timers) 0x6220e8f7d1c7
**BROKEN** lightningd: backtrace: lightningd/lightningd.c:1496 (main) 0x6220e8f82db2
**BROKEN** lightningd: backtrace: ../sysdeps/nptl/libc_start_call_main.h:58 (__libc_start_call_main) 0x73614bc2a1c9
**BROKEN** lightningd: backtrace: ../csu/libc-start.c:360 (__libc_start_main_impl) 0x73614bc2a28a
**BROKEN** lightningd: backtrace: (null):0 ((null)) 0x6220e8f53b64
**BROKEN** lightningd: backtrace: (null):0 ((null)) 0xffffffffffffffff
```

Reported-by: @michael1011
Changelog-Fixed: lightningd: potential crash when we receive a malformed onion complain from our first peer when using sendonion / injectpaymentonion.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-13 14:13:57 +10:30
Rusty Russell
5c71ba2210 pytest: test for malformed reply from first hop when using injectpaymentonion.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-13 14:13:57 +10:30
Alex Myers
8a0e473ec8 bump minimum python to 3.9.2 and downgrade coincurve
This allows compatibility with python 3.14.0 which coincurve 21.0.0 did
not support.  The next coincurve release should restore compatibility.

Fixes: #8591

Changelog-changed: pyln-testing requires python>=3.9.2
2025-10-10 15:54:37 +10:30
Lakshya Singh
ad040d0db8 docs: add frozen for uv sync
prevent updates to lock file which might leave working directory dirty 
resulting in a modded cln version build
2025-10-10 15:47:39 +10:30
Lakshya Singh
2879ef121e chore: remove uv sources defined at workspace level
duplicate definition isn’t required as we already defined them at 
workspace level sources
2025-10-10 15:47:39 +10:30
Lakshya Singh
d05a8ee70b chore: remove __init__.py for package extension
for python 3.3+ we don’t need an __init__.py at namespace package to 
allow extensions instead we can just get rid of them
2025-10-10 15:47:39 +10:30
Peter Neuroth
c7531b0f8f plugin: remove features when plugin is disabled
We need to remove the feature bits set via a plugins get_manifest
response when the init response disables the plugin.

Changelog-Fixed Remove feature bits set by a plugin when the plugin
disables itself during init.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-10-08 06:04:32 +10:30
Rusty Russell
8895ca2982 Revert "update makefile to remove hsm_encryption"
This reverts commit 084b03375c.
2025-10-02 11:08:35 +09:30
Matt Whitlock
f7db14408f pyln-testing: pass timeout to BitcoinProxy
The bitcoin.rpc.DEFAULT_HTTP_TIMEOUT of 30 seconds may not be enough
time to generate a block when the test machine is under load. Pass
pyln.testing.utils.TIMEOUT to bitcoin.rpc.RawProxy to allow extra time:
currently 60 seconds by default or 180 seconds if SLOW_MACHINE is set.

Changelog-None
2025-10-02 10:44:16 +09:30
Rusty Russell
5b06e65325 wallet: unit test the migration dedup code.
This is based on a real database, which values changed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-02 10:21:06 +09:30
Rusty Russell
fb973fea05 wallet: find and remove any duplicates from the bug we just fixed.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-02 10:21:06 +09:30
Rusty Russell
7631ce635e wallet: unit test for duplicate detection in wallet_save_chain_mvt.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-02 10:21:06 +09:30
Rusty Russell
bd1ba16440 wallet: don't insert duplicate chain_moves entries after accounts.db migration.
When we migrate from accounts.db, we use the `account_nonchannel_id`
field.  But we can replay the block chain and the channel involved is
still open, we will use the `account_channel_id` field, and our duplicate
detection fails.

As a result, we can end up with duplicate entries in the database, which
make accounting incorrect.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: JSON-RPC: `listchainmoves` could contain bogus duplicate entries after 25.09 bookkeeper migration.
2025-10-02 10:21:06 +09:30
Rusty Russell
aa8d858c1d pytest: test that we don't delete htlcs as soon as channel closed, wait for restart.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-02 10:19:55 +09:30
Rusty Russell
cb2849d03f wallet: don't delete old htlcs when we forget a channel, do it on startup.
For old channels, this can take a while, and it stops everything.  But
we are only doing this to save space; it's not a *functional* necessity.

A quick and dirty test with 50,000 htlcs shows the htlc deletion took
450msec.  I tried adding an index, and changing it to set hstate to
HTLC_STATE_INVALID instead of deleting entries, but it still took about 350ms.

Whereas the "COUNT(*)" only took 1.7msec, so it's worth keeping.

Reported-by: @michael1011
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: lightningd: we defer deletion of old htlcs on channel close, to avoid pausing for a long time (we clean them on startup)
Fixes: https://github.com/ElementsProject/lightning/issues/7962
2025-10-02 10:19:55 +09:30
Rusty Russell
bee54f0ef6 wallet: don't show htlcs from closed channels in listhtlcs.
This doesn't happen yet, since we delete all HTLCs when we close a channel.  But we're
about to change that, so update the wallet_htlcs_first() code to avoid them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-02 10:19:55 +09:30
Matt Whitlock
a05a3748d3 tests: skip certain tests if RUST is not enabled
* tests/test_cln_lsps.py::test_lsps0_listprotocols
 * tests/test_clnrest.py
 * tests/test_connection.py::test_wss_proxy

Changelog-Fixed: pytest: Tests that require Rust no longer fail if Rust is disabled.
2025-10-02 10:19:27 +09:30