Commit Graph

3448 Commits

Author SHA1 Message Date
Rusty Russell
a12c02b1d0 pytest: fix race in test_zeroconf_forget
fundwallet() actually mines a block, putting our count out.  If we see
both blocks at once, we will say "52" blocks instead of "51":

```
2025-05-02T05:28:40.5315155Z         have_forgotten = l2.daemon.is_in_log(
2025-05-02T05:28:40.5315650Z             r"UNUSUAL {}-chan#1: Forgetting channel: It has been 51 blocks without the funding transaction ".format(l1.info['id'])
2025-05-02T05:28:40.5316105Z         )
2025-05-02T05:28:40.5316263Z     
2025-05-02T05:28:40.5316417Z         if dopay:
2025-05-02T05:28:40.5316616Z             assert not have_forgotten
2025-05-02T05:28:40.5317056Z             assert set([c['peer_id'] for c in l2.rpc.listpeerchannels()["channels"]]) == set([l1.info['id'], l3.info['id']])
2025-05-02T05:28:40.5317477Z         else:
2025-05-02T05:28:40.5317662Z >           assert have_forgotten
2025-05-02T05:28:40.5317887Z E           assert None
```

```
0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-chan#1: Forgetting channel: It has been 52 blocks without the funding transaction 0bb0579df6b1d983dda49dad47513afc71696c9d5bea3c8b955ba4b76bb053de getting deeply confirmed. We are fundee and can forget channel without loss of funds.
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-02 13:25:11 -07:00
Rusty Russell
f054600723 pytest: fix flake in test_setconfig_access.
We were supposed to put the sqlite db in a different directory, but
the test was wrong!  So occasionally we would crash with:

```
Failed to commit DB transaction: Failed to commit a transaction: disk I/O error
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-02 13:25:11 -07:00
Rusty Russell
fb0f62e402 CI: fix flake in test_penalty_htlc_tx_timeout
Make sure l1 sees the l5 channel!

```
2025-04-29T02:39:42.1086397Z         # now we send two 'sticky' htlcs, l1->l5 + l4->l1
2025-04-29T02:39:42.1086837Z         amt = 10**8 // 2
2025-04-29T02:39:42.1087231Z         sticky_inv_1 = l5.rpc.invoice(amt, '2', 'sticky')
2025-04-29T02:39:42.1087767Z >       route = l1.rpc.getroute(l5.info['id'], amt, 1)['route']
2025-04-29T02:39:42.1088126Z 
2025-04-29T02:39:42.1088279Z tests/test_closing.py:1432: 
...
2025-04-29T02:39:42.1111693Z         elif "error" in resp:
2025-04-29T02:39:42.1111976Z >           raise RpcError(method, payload, resp['error'])
2025-04-29T02:39:42.1113258Z E           pyln.client.lightning.RpcError: RPC call failed: method: getroute, payload: {'id': '032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e', 'amount_msat': 50000000, 'riskfactor': 1, 'cltv': 9}, error: {'code': -32602, 'message': '032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e: unknown destination node_id (no public channels?)'}
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-02 13:25:11 -07:00
Rusty Russell
099a7ecab6 pytest: fix flake in test_xpay_twohop_bug
CLTV can be one less if l1 hasn't seen block yet:

```
2025-04-24T05:38:12.8587408Z >       l1.daemon.wait_for_log(f'Adding HTLC 0 amount=15002msat cltv={110 + 1 + 100 + 200 + 400}')
2025-04-24T05:38:12.8587715Z 
2025-04-24T05:38:12.8587804Z tests/test_xpay.py:824: 
...
2025-04-24T05:38:12.9889506Z lightningd-1 2025-04-24T05:30:45.255Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-channeld-chan#1: Adding HTLC 0 amount=15002msat cltv=812 gave CHANNEL_ERR_ADD_OK
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-02 13:25:11 -07:00
Rusty Russell
8d54a82d2d pytest: fix CI hang.
This finally happened on my local build machine, so I tracked it down using
py-spy, `apt-get install python3-dbg` and `py-local`.

Turns out the dev-memleak command was hanging, and the processes were stuck in
SIGSTOP.  There are only two places we send that, and sure enough, this was
the test which was running at the time.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-02 12:15:18 +09:30
Rusty Russell
43b09e73f7 lightningd: respond with channel_reestablish if contacted about long-closed channels.
This may be useful for their recovery, though they should see the spend onchain.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: We now reply to `channel_reestablish` even on long-closed channels.
2025-04-29 13:31:23 +09:30
Rusty Russell
6e4fb1eb56 channeld: remove never-used "reestablish_only" option.
This was always false.  peer_start_channeld was called in various places
with the argument "NULL" instead of "false", which unfortunately compilers
didn't complain about :(

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-04-29 13:31:23 +09:30
Rusty Russell
3b80a81031 lightningd: allow up to 100 "slow open" channels before forgetting them.
Michael of Boltz told me this long ago, that when fees spiked some of their clients' opens got stuck.  After two weeks their node forgot them, and when fees came back down the opens still failed.  Unfortunately, I can't see an issue for this!

We can give some grace: we don't want to waste too many resources, but 100 channels is nothing.

The test needs to be adjusted to have *two* slow open channels, now.

Changelog-Changed: Protocol: we won't forget still-opening channels after 2016 blocks, unless there are more than 100.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-04-29 13:31:23 +09:30
Rusty Russell
6bf36915fd lightningd: support index/start/end pagination for listhtlcs.
Changelog-Added: JSON-RPC: `listhtlcs` supports `index`, `start` and `end` parameters for pagination support.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-04-29 09:38:20 +09:30
Rusty Russell
7ba6263c48 lightningd: add created_index and updated_index to listhtlcs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `listhtlcs` has `created_index` and `updated_index` fields.
2025-04-29 09:38:20 +09:30
Rusty Russell
07c495e7fb lightningd: keep indexes updated for channel_htlcs table (aka listhtlcs).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-04-29 09:38:20 +09:30
Rusty Russell
db104aae92 lightningd: improve wait API by making details fields per-subsystem.
It makes the schema simpler, and indeed, expressable by GRPC.

Changelog-Added: JSON-RPC: `wait` now has separate `invoices`, `forwards` and `sendpays` objects for each subsystem.
Changelog-Deprecated: JSON-RPC: `wait` reply `details` object: use subsytem specific object instead.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-04-29 09:38:20 +09:30
Rusty Russell
8974375de8 lightningd: add short_channel_id option to listpeerchannels.
Requested-by: @whitslack
Closes: https://github.com/ElementsProject/lightning/issues/8233
Changelog-Added: JSON-RPC: `listpeerchannels` now has a `short_channel_id` parameter for just listing a specific channel.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-04-28 14:13:12 +09:30
Rusty Russell
e951155002 trace: fix parent handling (and test it!).
Testing parenting handling revealed several issues:

1. By calling "trace_span_start" when CLN_TRACEPARENT is set produces a bogus
   entry, for which the span_id is overwritten so we never end it.
2. We don't need to close the remote parent when we close the first child: in
   fact, this causes the remaining traces to be detached from the parent!
3. Suspension should return current to the parent, not to NULL.

Now the traces balance as we expect.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-04-23 13:45:18 +09:30
Rusty Russell
924f28adcb pytest: add test hooks so we can test tracing.
Suggested-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-04-23 13:45:18 +09:30
Rusty Russell
139d21173b pytest: fix test_recover_plugin flake
It can try to reconnect while we're explicitly connecting:

```
2025-04-15T03:40:53.9184103Z >       l2.rpc.connect(l1.info['id'], 'localhost', l1.port)
2025-04-15T03:40:53.9184311Z 
2025-04-15T03:40:53.9184401Z tests/test_misc.py:3078:
...
2025-04-15T03:40:53.9206302Z >           raise RpcError(method, payload, resp['error'])
2025-04-15T03:40:53.9207225Z E           pyln.client.lightning.RpcError: RPC call failed: method: connect, payload: {'id': '0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518', 'host': 'localhost', 'port': 45219}, error: {'code': 402, 'message': 'disconnected during connection'}
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-04-16 08:02:14 +09:30
Rusty Russell
afa8875c8a pytest: fix race in test_renepay where we didn't wait for all channels.
get_channel_scid() returns the *first* channel, and we want all the channels.
So they may not actually be all visible in gossip.

```
    @unittest.skipIf(TEST_NETWORK == 'liquid-regtest', "broken for some reason")
    def test_hardmpp2(node_factory, bitcoind):
        """Credits to @daywalker90 for this test case."""
        opts = {"disable-mpp": None, "fee-base": 0, "fee-per-satoshi": 10}
        l1, l2, l3 = node_factory.get_nodes(3, opts=opts)
        start_channels(
            [
                (l1, l2, 100_000),
                (l1, l2, 200_000),
                (l1, l2, 300_000),
                (l1, l2, 400_000),
                (l2, l3, 100_000),
                (l2, l3, 200_000),
                (l2, l3, 300_000),
                (l2, l3, 600_000),
            ]
        )
        # FIXME: changing the last channel from 600k to 400k will fail the test due
        # to l2 not accepting to forward any amount above 200k with error:
        # CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED, still investigating
        inv = l3.rpc.invoice("800000sat", "inv", "description")
>       l1.rpc.call("renepay", {"invstring": inv["bolt11"]})

tests/test_renepay.py:797: 
...
        elif "error" in resp:
>           raise RpcError(method, payload, resp['error'])
E           pyln.client.lightning.RpcError: RPC call failed: method: renepay, payload: {'invstring': 'lnbcrt8m1pnl3zfksp54n6vhkrcj0nkn2uqhf232v62539048u2ree4g9ssytm47gasgctspp58twj5xf4h57s4h0rhy55p5q6nry36glummjexsf4lc446je7y27qdqjv3jhxcmjd9c8g6t0dcxqyjw5qcqp9rzjqgkjyd3q5dv6gllh77kygly9c3kfy0d9xwyjyxsq2nq3c83u5vw4jqqqvuqqqzqqqqqqqqqqqqqqqzsqqcrzjqgkjyd3q5dv6gllh77kygly9c3kfy0d9xwyjyxsq2nq3c83u5vw4jqqqvuqqqpcqqqqqqqqqqqqqqzsqqcrzjqgkjyd3q5dv6gllh77kygly9c3kfy0d9xwyjyxsq2nq3c83u5vw4jqqqvuqqqqgqqqqqqqqqqqqqqzsqqcrzjqgkjyd3q5dv6gllh77kygly9c3kfy0d9xwyjyxsq2nq3c83u5vw4jqqqvuqqqpqqqqqqqqqqqqqqqzsqqc9qxpqysgqtgxcneu0u7xvetgh2kqmey86jssweneat5vx3fppuaphl9v9jweqa2ymczg9klau9jmsm6pm7m3cd28pggp7avuukjqxg63wy2vuvtcpggz4vt'}, error: {'code': 205, 'message': "minflow couldn't find a feasible flow: failed to find a feasible flow: find_admissible_path failed"}
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-04-16 08:02:14 +09:30
Matt Morehouse
2811614c37 fuzz: don't fail when fuzzer generates valid Act 1 or 2 packets
The handshake targets were based on a false premise: that it is
impossible for any fuzzer to generate valid Act 1 or 2 packets. Niklas
Gogge proved this premise incorrect using AFL++ with the CMPLOG feature,
which enabled AFL++ to generate such valid packets.

We modify the targets to allow the scenario where the fuzzer finds these
valid packets and add the inputs AFL++ found to the corpus.
2025-04-15 19:53:47 +09:30
Matt Morehouse
2b5140fbcd fuzz: don't fail when fuzzer generates valid MAC
The cryptofuzz target was based on a false premise: that it is
impossible for any fuzzer to generate a valid ciphertext+MAC for the
decrypt function. Niklas Gogge proved this premise incorrect using AFL++
with the CMPLOG feature, which enabled AFL++ to generate such valid
messages.

We remove the assertions requiring decryption to fail and add the inputs
AFL++ found to the corpus.
2025-04-15 19:53:47 +09:30
ShahanaFarooqui
bf3783c6d2 tests: removed lightning- prefix from autogenerate example 2025-04-15 15:17:14 +09:30
Rusty Russell
7c6270d051 lightningd: rescan for missing p2wkph for closed channels.
This can happen with 24.11 and later.  We scan back to exposed channel
opens, or that release.

The BROKEN log messages cause some tests to fail, so we fix those.

Fixes: https://github.com/ElementsProject/lightning/issues/8169
Changelog-Fixed: wallet: rescan for missing close outputs (can happen if peer doesn't support option_shutdown_anysegwit)
2025-04-02 11:22:54 +10:30
Rusty Russell
d40da2b671 lightningd: make sure we register all addresses at opening if peer doesn't support OPT_SHUTDOWN_ANYSEGWIT.
We select the close key index at opening time, but the non-DF code didn't correctly register the
address as possibly used for P2WPKH for older nodes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: wallet: we could miss our own returned outputs on mutual closes if peer doesn't support option_shutdown_anysegwit (you will still need to rescan after update, if this happened to you!)
Reported-by: Grubles
2025-04-02 11:22:54 +10:30
Rusty Russell
46690cb2a6 pytest: replicate error where we could miss our returned funds on mutual close.
1. Peer has to not support option_shutdown_anysegwit.
2. We have to restart between opening and closing the channel.
3. We won't see the to-us output, since it's p2wpkh not p2tr.

This bug was introduced in 24.11.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-04-02 11:22:54 +10:30
Rusty Russell
462e59823e pytest: generate broken db examples now, before we fix them.
We'll need these for our migration tests, so we need to generate "bad" dbs
now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-04-02 11:22:54 +10:30
Rusty Russell
8dae8be5fb common: fix crash when we have a localmod with unrepresentable fee values.
We handed NULL as the logcb, resulting in a very uninformative crash:

```
2025-03-14T03:46:36.447Z INFO    lightningd: Server started with public key 03d67f36c4f81789e2fe425028bacc96b199813eae426c517f589a45f1136c1fe5, alias Jubilee (color #dc42f4) and lightningd v25.02
topology: FATAL SIGNAL 11 (version v25.02)
0x560037f64aad send_backtrace
        common/daemon.c:33
0x560037f64b49 crashdump
        common/daemon.c:78
0x7f6c41ff351f ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x0 ???
        ???:0
```

Changelog-Fixed: `topology` crash on invoice creation if a peer had a really high feerate.
Fixes: https://github.com/ElementsProject/lightning/issues/8156
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-04-01 16:33:23 +10:30
Rusty Russell
6a9fd02d93 pytest: fix flake in test_blindedpath_privchan.
We reconnect from l3->l2, but l2 is also trying to reconnect and
we can race:

```
        # Now try when l3 uses scid for entry point of blinded path.
        l3.stop()
        l3.daemon.opts['dev-invoice-bpath-scid'] = None
        l3.start()
>       l3.rpc.connect(l2.info['id'], 'localhost', l2.port)

tests/test_pay.py:5667:
...
>           raise RpcError(method, payload, resp['error'])
E           pyln.client.lightning.RpcError: RPC call failed: method: connect, payload: {'id': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'host': 'localhost', 'port': 33557}, error: {'code': 402, 'message': 'disconnected during connection'}
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-03-24 13:59:58 +10:30
Rusty Russell
922d78e89b pytest: fix flake in test_onionmessage_ratelimit.
By submitting them all at once, rather than serially, we should *definitely* hit the
ratelimit.  We can also reduce the timeout (from 60 seconds) to speed the test up.

```
    @pytest.mark.slow_test
    def test_onionmessage_ratelimit(node_factory):
        l1, l2 = node_factory.line_graph(2, fundchannel=False,
                                         opts={'allow_warning': True})

        offer = l2.rpc.call('offer', {'amount': '2msat',
                                      'description': 'simple test'})

        # Hopefully we can do this fast enough to reach ratelimit!
>       with pytest.raises(RpcError, match="Timeout waiting for response"):
E       Failed: DID NOT RAISE <class 'pyln.client.lightning.RpcError'>

tests/test_pay.py:5825: Failed
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-03-24 13:59:58 +10:30
Rusty Russell
2050f9afd9 pytest: fix flake in test_setconfig_access.
We play with directory permissions, but sqlites needs that, and sometimes (due to a timer, perhaps?)
it gets really upset about it:

```
lightningd-1 2025-03-16T23:29:58.506Z INFO    lightningd: Server started with public key 0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518, alias JUNIORBEAM-f91eb11-modded (color #0266e4) and lightningd f91eb11-modded
lightningd-1 2025-03-16T23:29:58.617Z DEBUG   lightningd: Adding block 101: 55af171ade598f8c4f9a494eaaffe6b9f5ea64c7b0f3b273694148adf7ad7385
lightningd-1 2025-03-16T23:29:58.752Z TRACE   lightningd: Calling rpc_command hook of plugin cln-xpay
lightningd-1 2025-03-16T23:29:58.764Z TRACE   lightningd: Plugin cln-xpay returned from rpc_command hook call
lightningd-1 2025-03-16T23:29:58.784Z TRACE   lightningd: Calling rpc_command hook of plugin cln-xpay
lightningd-1 2025-03-16T23:29:58.840Z TRACE   lightningd: Plugin cln-xpay returned from rpc_command hook call
lightningd-1 2025-03-16T23:29:58.854Z TRACE   lightningd: Calling rpc_command hook of plugin cln-xpay
lightningd-1 2025-03-16T23:29:58.865Z DEBUG   gossipd: REPLY WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY with 0 fds
lightningd-1 2025-03-16T23:29:58.901Z **BROKEN** lightningd: Error executing statement: db/exec.c:108: UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?: attempt to write a readonly database
lightningd-1 2025-03-16T23:29:58.916Z **BROKEN** lightningd: Error executing statement: db/exec.c:108: UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?: attempt to write a readonly database
lightningd-1 2025-03-16T23:29:58.941Z **BROKEN** lightningd: FATAL SIGNAL 6 (version f91eb11-modded)
{'github_repository': 'ElementsProject/lightning', 'github_sha': 'f91eb118388dc1455c67d16079168fd0267ba248', 'github_ref': 'refs/pull/8112/merge', 'github_ref_name': 'HEAD', 'github_run_id': 13888173501, 'github_head_ref': 'flake-memleak', 'github_run_number': 12573, 'github_base_ref': 'master', 'github_run_attempt': '1', 'testname': 'test_setconfig_access', 'start_time': 1742167762, 'end_time': 1742167800, 'outcome': 'fail'}
----------------------------- Captured stderr call -----------------------------
Error executing statement: db/exec.c:108: UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?: attempt to write a readonly database
lightningd: FATAL SIGNAL 6 (version f91eb11-modded)
Log dumped in /tmp/lightning-crash.log.20250316232958
Lost connection to the RPC socket.Lost connection to the RPC socket.
=========================== short test summary info ============================
FAILED tests/test_misc.py::test_setconfig_access - AssertionError: Regex pattern did not match.
 Regex: 'Cannot write to config file /tmp/ltests-22a5dz1j/test_setconfig_access_1/lightning-1/regtest/config'
 Input: "RPC call failed: method: check, payload: {'command_to_check': 'setconfig', 'config': 'min-capacity-sat', 'val': 1000000}, error: Connection to RPC server lost."
ERROR tests/test_misc.py::test_setconfig_access - ValueError:
Node errors:
 - lightningd-1: had BROKEN messages
 - lightningd-1: Node exited with return code -6
```

So we move the db file for sqlite.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-03-24 13:59:58 +10:30
Rusty Russell
248677d78c pytest: fix flake in test_last_stable_connection.
```
>       assert only_one(l1.rpc.listpeerchannels()['channels'])['last_stable_connection'] > recon_time + STABLE_TIME
E       assert 1742167762 > (1742167702.0235627 + 60)

tests/test_connection.py:4545: AssertionError
```

Indeed, the > should be >=.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-03-24 13:59:58 +10:30
Rusty Russell
8cbb2457d9 pytest: fix flake in splice gossip test.
We can in fact see the new channel before this line is called:

```
2025-03-15T12:31:04.1472196Z     @pytest.mark.openchannel('v1')
2025-03-15T12:31:04.1472616Z     @pytest.mark.openchannel('v2')
2025-03-15T12:31:04.1473317Z     @unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
2025-03-15T12:31:04.1474271Z     def test_splice_gossip(node_factory, bitcoind):
2025-03-15T12:31:04.1475078Z         l1, l2, l3 = node_factory.line_graph(3, fundamount=1000000, wait_for_announce=True, opts={'experimental-splicing': None})
2025-03-15T12:31:04.1475781Z
2025-03-15T12:31:04.1476052Z         chan_id = l1.get_channel_id(l2)
2025-03-15T12:31:04.1476460Z         pre_splice_scid = first_scid(l1, l2)
2025-03-15T12:31:04.1476844Z
2025-03-15T12:31:04.1477134Z         # add extra sats to pay fee
2025-03-15T12:31:04.1477741Z         funds_result = l1.rpc.fundpsbt("109000sat", "slow", 166, excess_as_change=True)
2025-03-15T12:31:04.1478345Z
2025-03-15T12:31:04.1478765Z         result = l1.rpc.splice_init(chan_id, 100000, funds_result['psbt'])
2025-03-15T12:31:04.1479432Z         result = l1.rpc.splice_update(chan_id, result['psbt'])
2025-03-15T12:31:04.1479994Z         assert(result['commitments_secured'] is False)
2025-03-15T12:31:04.1480584Z         result = l1.rpc.splice_update(chan_id, result['psbt'])
2025-03-15T12:31:04.1481089Z         assert(result['commitments_secured'] is True)
2025-03-15T12:31:04.1481386Z         result = l1.rpc.signpsbt(result['psbt'])
2025-03-15T12:31:04.1481860Z         result = l1.rpc.splice_signed(chan_id, result['signed_psbt'])
2025-03-15T12:31:04.1482403Z
2025-03-15T12:31:04.1485960Z         wait_for(lambda: only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['state'] == 'CHANNELD_AWAITING_SPLICE')
2025-03-15T12:31:04.1489978Z         wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['state'] == 'CHANNELD_AWAITING_SPLICE')
2025-03-15T12:31:04.1490796Z
2025-03-15T12:31:04.1491223Z         bitcoind.generate_block(6, wait_for_mempool=result['txid'])
2025-03-15T12:31:04.1491767Z
2025-03-15T12:31:04.1492213Z         # l3 will see channel dying, but still consider it OK for 12 blocks.
2025-03-15T12:31:04.1493174Z         l3.daemon.wait_for_log(f'gossipd: channel {pre_splice_scid} closing soon due to the funding outpoint being spent')
2025-03-15T12:31:04.1494422Z         assert len(l3.rpc.listchannels(short_channel_id=pre_splice_scid)['channels']) == 2
2025-03-15T12:31:04.1495293Z >       assert len(l3.rpc.listchannels(source=l1.info['id'])['channels']) == 1
2025-03-15T12:31:04.1495937Z E       AssertionError: assert 2 == 1
2025-03-15T12:31:04.1503185Z E        +  where 2 = len([{'active': True, 'amount_msat': 1000000000, 'base_fee_millisatoshi': 1, 'channel_flags': 1, ...}, {'active': True, 'amount_msat': 1100000000, 'base_fee_millisatoshi': 1, 'channel_flags': 1, ...}])
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-03-24 13:59:58 +10:30
Rusty Russell
5ba5546192 pytest: fix flake in test_fetchinvoice
The sleep was simply allowing gossip to propagate, so (sometimes) l4 can connect to l3/l1.
We really want to suppress the blinded path on l2:

```
2025-03-03T05:25:16.6928072Z >       l4.rpc.call('fetchinvoice', {'offer': offer3['bolt12']})
2025-03-03T05:25:16.6928280Z
2025-03-03T05:25:16.6928367Z tests/test_pay.py:4540:
2025-03-03T05:25:16.6928609Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2025-03-03T05:25:16.6928929Z contrib/pyln-testing/pyln/testing/utils.py:760: in call
...
2025-03-03T05:25:16.6956050Z E           pyln.client.lightning.RpcError: RPC call failed: method: fetchinvoice, payload: {'offer': 'lno1qgsqvgnwgcg35z6ee2h3yczraddm72xrfua9uve2rlrm9deu7xyfzrcgqyqs5pn0venx2u3nzrhqxhftzxfdlwsnfcgw2sy8t5mxa0ytcdfat2nkdwqvpy9nnsa9mzzaqfwys22njn0v5g3jswhdh684hnlnkvd5pme28q5hgyyhshhmntd6qqsz40a4renm8a94r9xf5eez73ygcmendmd9utwmx0kzlp0lwd9sq98sqvutrneuljglxekynj2wdhpsa36ra3ae7uql9g79w9qqc0rqrunkystxgsz2reyay8hdtzwjew38w2u4xavpq2fm360hd75pkyuhpar0adgu93z8gn0jsyxganyhelch7savw6vrgqpj80cdc5qkwkaz0dk65cwyatgmhszpv72axqz6ldvcjq9crzevzpd3aeet607hq7sk0fvz0musdn7r96w6zcssytfzxcs2xkdy0lml0tzy0jzugmyj8kjn8zfzrgq9fsgurc72x82e'}, error: {'code': 1003, 'message': 'Failed: could not route or connect directly to blinded path at 035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d: {"code":400,"message":"Unable to connect, no address known for peer"}'}
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-03-24 13:59:58 +10:30
Christian Decker
2b761b00b8 pytest: Test that we don't forget zeroconf channels
Modified by Rusty:
- Simplify (we only need to suppress l1's txs, since it opens)
- Use synchronize_blockheight instead of log messages to ensure l2 has processed the block
- Use listpeerchannels instead of log messages for balance (should be more robust against changes)
- Open-code assertions for better debugging if they're wrong.
2025-03-19 17:32:26 +01:00
Rusty Russell
67c91a7e5c BOLTs: Update to version with peer storage merged.
Unfortunately a spec typo means the data fields are missing (PR pending),
so we still patch those in.

The message "your_peer_storage" got renamed to "peer_storage_retrieval",
and the option "want_peer_backup_storage" was removed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: `experimental-peer-storage` now only advertizes feature 43, not 41.
2025-03-18 14:30:58 +10:30
Rusty Russell
0e7615b1b7 plugins/topology: remove local channels from listchannels.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: RPC `listchannels` no longer includes private local channels (deprecated v23.08, disabled by default in v24.11).
2025-03-12 09:26:08 +10:30
Rusty Russell
73fc9b0c2a plugins: all plugins must now support non-numeric JSON RPC id fields.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: plugins which didn't accept string JSON RPC fields (deprecated v23.08, disabled by default in v24.11).
2025-03-12 09:26:08 +10:30
Rusty Russell
f95b542c1e plugins: no longer accept 0/1 for boolean options.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: allowing 0/1 instead of false/true for plugin options (deprecated v23.08, disabled by default in v24.11).
2025-03-12 09:26:08 +10:30
Rusty Russell
371965cec3 Makefile: update CLN_NEXT_VERSION.
We now have to explicitly enable various deprecated commando commands, and now
when deprecations are disabled, we honour missing MPP option in bolt12 invoices.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-03-12 09:26:08 +10:30
Rusty Russell
c05ffb2fb1 doc: remove documentation for disabled commando commands.
When we update the CLN_NEXT_VERSION, these will only be available with --i-promise-to-fix-broken-api-user.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-03-12 09:26:08 +10:30
Rusty Russell
ba8b5a6636 pytest: don't need allow-deprecated-apis in test_commando/test_commando_stress any more.
In d18f564324 "pytest: stop using
deprecated commando_rune commands." we stopped using deprecated commands in these tests,
but we didn't remove the 'allow-deprecated-apis' flag.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-03-12 09:26:08 +10:30
Rusty Russell
ac596c8e08 offers: don't add blinded path from a disconnected peer.
Really, any peer without a live channel is a bad prospect.

This requires us to wire the "enabled" flag through listincoming:
fortunately that's an internal, undocumented interface, so we don't
have a schema change.

Changelog-Fixed: Offline peers no longer selected for blinded paths..

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: https://github.com/ElementsProject/lightning/issues/8127
2025-03-04 20:13:49 -06:00
Rusty Russell
d47b188cab pytest: add a test that we don't use an offline peer for offer paths.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-03-04 20:13:49 -06:00
Rusty Russell
d2f4196179 offers: don't send blinded path to neighbor for *invoices*.
In 6e4ff6a7d2 ("offers: add a blinded path
if we have no advertized address") we were overzealous, and set blinded
paths not just for offers and invoicerequests, but for invoices themselves.

This has revealed various interop issues (which is great, but not good
for our users!) so we should disable that.  It also reduces the reliability
of payments in general.

Changelog-None: fixes previously overzealous addition
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-27 13:53:10 -06:00
Rusty Russell
2408233b2e pay: use correct CLTV values for blinded paths.
We added twice, which caused spurious failures in real-world cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reported-by: https://github.com/hMsats
Fixes: https://github.com/ElementsProject/lightning/issues/8119
Changelog-Fixed: `xpay` would double the CLTV values in blinded paths, sometimes causing spurious failures.
2025-02-26 14:26:47 -06:00
Rusty Russell
69476dbcab xpay: a test of a similar scenario to a real failure.
Use larger CLTVs and we see the failure from l3, complaining the CLTV is outside
the amount in the payment_constraint field, like:

```
Failing HTLC because of an invalid payload (TLV 10 pos 104): cltv_expiry 609 > payment_constraint 376
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-26 14:26:47 -06:00
Rusty Russell
10f333b041 devtools/bolt12-cli: fix interpretation of blindedpay, amounts.
The old blindedpay fields would have an entry per hop, but that was changed
to a single per-path entry.  The devtools hadn't caught up.

Similarly, it didn't like descriptionless offer fields in invreqs and invoices.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-26 14:26:47 -06:00
Rusty Russell
79b28eb8c2 onchaind: tell lightningd correct nSequence value for local leases.
If the nSequence in the tx it produces is not at least the value we
test in the script, the tx will always fail:

```
error code: -26\nerror message:\nmandatory-script-verify-flag-failed (Locktime requirement not satisfied)
```

If we have a lease, the nSequence is max(lease-time-remaining,
to-self-delay), so have onchaind tell lightningd the correct nSequence.

Fixes: https://github.com/ElementsProject/lightning/issues/7460
Reported-by: https://github.com/pabpas
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: Correctly collect our own (delayed) funds if we have a unilateral close when we are still offering a lease.
2025-02-25 10:10:14 +10:30
Rusty Russell
8c0b2334c1 pytest: add test that to-local output spend actually works during lease time.
What we expect to happen:

1. l3, which unilaterally closed, waits 4032 blocks (minus those mined) before
   trying to send get its "to_local" funds back.
2. This should then succeed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-25 10:10:14 +10:30
Rusty Russell
4fdbd8ba98 lightningd: catch edits of config files *before* we're committed.
Another report, that we crash if it's edited.  We should check that too!

Reported-by: daywalker90
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-24 19:38:37 +10:30
Rusty Russell
5e79cd4608 lightningd: check for writability before allowing setconfig.
If we actually can't write it, we crash (to avoid an inconsistent
state), so sanity check FIRST.

Fixes: https://github.com/ElementsProject/lightning/issues/7964
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-24 19:38:37 +10:30
Rusty Russell
8127fcf825 pytest: don't add bookeeper-db option if bookkeeper is disabled.
There are other ways we can disable it, of course (e.g full path name)
but this is the most obvious.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-24 19:38:37 +10:30