Commit Graph

3857 Commits

Author SHA1 Message Date
wqxoxo
bc3b9b4f11 pay: Enforce maxdelay for direct channel payments
When paying through a direct channel, direct_pay_override() creates a
route bypassing the normal routing path, which skips the CLTV budget
check in payment_getroute(). This allows payments to succeed even when
maxdelay is set below the required min_final_cltv_expiry.

Add a check in direct_pay_override() to verify the required CLTV
doesn't exceed cltv_budget before using the direct channel shortcut.
If it exceeds, skip the direct channel and let normal routing handle
the failure with a proper error message.

Fixes: #8609

Changelog-Fixed: pay: `maxdelay` parameter now enforced for direct channel payments
2025-12-19 12:41:17 +01:00
nazarevsky
d065d3692d tests: add payer_note case for xpay 2025-12-18 12:47:06 -08:00
nazarevsky
bcdce8f40d cln-rpc: update schema, update proto for xpay payer_note field 2025-12-18 12:47:06 -08:00
Rusty Russell
f0e9547661 gossipd: make sure we correctly move node announcement when *no* channel preceeds it in the gossip store.
We had the test backwards, so we moved it *all the time*.  This bloats our gossip store, as well as
not moving it in the case where we need to.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: gossipd: we would occasionally not show a node announcement in listnodes().
2025-12-17 11:56:42 +10:30
Rusty Russell
d1857fff91 pytest: add test to demonstrate gossip_store misordering node announcements.
We usually lose the node announcement on restart, because the
node_announcement message is ignored by gossmap, as it doesn't (yet!) know of the node, since the
channel_announcement does not precede the node_announcement.

This is supposed to be detected and fixed by gossipd, but this simple test shows that it is not!

```
FAILED tests/test_gossip.py::test_gossmap_lost_node - AssertionError: assert {'nodes': [{'nodeid': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'alias': 'SILENTARTIST-v25.12-2-g703851b', 'color': '022d22', 'last_timestamp': 1765172273, 'features': '8898880a8a59a1', 'addresses': []}, {'nodeid': '0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518', 'alias': 'JUNIORBEAM-v25.12-2-g703851b', 'color': '0266e4', 'last_timestamp': 1765172273, 'features': '8898880a8a59a1', 'addresses': []}, {'nodeid': '035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d'}, {'nodeid': '0382ce59ebf18be7d84677c2e35f23294b9992ceca95491fcf8a56c6cb2d9de199', 'alias': 'JUNIORFELONY-v25.12-2-g703851b', 'color': '0382ce', 'last_timestamp': 1765172273, 'features': '8898880a8a59a1', 'addresses': []}]} == {'nodes': [{'nodeid': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'alias': 'SILENTARTIST-v25.12-2-g703851b', 'color': '022d22', 'last_timestamp': 1765172273, 'features': '8898880a8a59a1', 'addresses': []}, {'nodeid': '0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518', 'alias': 'JUNIORBEAM-v25.12-2-g703851b', 'color': '0266e4', 'last_timestamp': 1765172273, 'features': '8898880a8a59a1', 'addresses': []}, {'nodeid': '035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d', 'alias': 'HOPPINGFIRE-v25.12-2-g703851b', 'color': '035d2b', 'last_timestamp': 1765172273, 'features': '8898880a8a59a1', 'addresses': []}, {'nodeid': '0382ce59ebf18be7d84677c2e35f23294b9992ceca95491fcf8a56c6cb2d9de199', 'alias': 'JUNIORFELONY-v25.12-2-g703851b', 'color': '0382ce', 'last_timestamp': 1765172273, 'features': '8898880a8a59a1', 'addresses': []}]}
  
  Differing items:
  {'nodes': [{'addresses': [], 'alias': 'SILENTARTIST-v25.12-2-g703851b', 'color': '022d22', 'features': '8898880a8a59a1...}, {'addresses': [], 'alias': 'JUNIORFELONY-v25.12-2-g703851b', 'color': '0382ce', 'features': '8898880a8a59a1', ...}]} != {'nodes': [{'addresses': [], 'alias': 'SILENTARTIST-v25.12-2-g703851b', 'color': '022d22', 'features': '8898880a8a59a1...}, {'addresses': [], 'alias': 'JUNIORFELONY-v25.12-2-g703851b', 'color': '0382ce', 'features': '8898880a8a59a1', ...}]}
  
  Full diff:
    {
        'nodes': [
            {
                'addresses': [],
                'alias': 'SILENTARTIST-v25.12-2-g703851b',
                'color': '022d22',
                'features': '8898880a8a59a1',
                'last_timestamp': 1765172273,
                'nodeid': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59',
            },
            {
                'addresses': [],
                'alias': 'JUNIORBEAM-v25.12-2-g703851b',
                'color': '0266e4',
                'features': '8898880a8a59a1',
                'last_timestamp': 1765172273,
                'nodeid': '0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518',
            },
            {
  -             'addresses': [],
  -             'alias': 'HOPPINGFIRE-v25.12-2-g703851b',
  -             'color': '035d2b',
  -             'features': '8898880a8a59a1',
  -             'last_timestamp': 1765172273,
                'nodeid': '035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d',
            },
            {
                'addresses': [],
                'alias': 'JUNIORFELONY-v25.12-2-g703851b',
                'color': '0382ce',
                'features': '8898880a8a59a1',
                'last_timestamp': 1765172273,
                'nodeid': '0382ce59ebf18be7d84677c2e35f23294b9992ceca95491fcf8a56c6cb2d9de199',
            },
        ],
    }

```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-12-17 11:56:42 +10:30
Rusty Russell
98a188b394 doc: document the direction field in listpeerchannels.
We mentioned it in the schema (so it was allowed), but we didn't document it!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-12-12 14:20:08 +01:00
Matt Whitlock
7a1a363330 test_renepay.py: remove data dump into /tmp
Changelog-None
2025-12-08 17:47:26 +10:30
Christian Decker
5c749fe4ee ci: Mark some tests as rerun 2025-12-06 12:32:38 +01:00
Matt Whitlock
6db80536cc tests/test_misc.py: fix another "AF_UNIX path too long"
Also, avoid resource leak by explicitly closing socket.

Changelog-None
2025-11-29 08:35:09 +10:30
Rusty Russell
9d4a150b7f pytest: add test that we correctly scan back for missed UTXOs.
I took the node from the original test which missed the UTXO, and
added some more blocks.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-29 08:18:20 +10:30
Rusty Russell
1e66414b9e wallet: make sure we re-watch outpoints after blocks are rolled back.
At startup, we load the outpoints to watch, *then* roll back 15
blocks.  If there were things in those blocks we wanted to watch, we
no longer do!

1. We load the utxoset into memory: everything in the utxoset table
   which has spendheight null.
2. We roll back 15 blocks to re-read.  Deleting a block from the
   database causes the utxo spentheights referring to it to be set
   to null.
3. We roll forward, but we didn't update the in-memory utxoset,
   so we're not watching those utxos which are spent.

The main symptom of this is that we spam peers with obsolete gossip
(if we get sent a channel announcement for a closed channel, we can
think it isn't spent yet).  But it could *also* mean we don't notice
onchain txs, if we restart at the wrong time!

Changelog-Fixed: lightningd: we could miss tx spends which happened in the past blocks when we restarted.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-29 08:18:20 +10:30
Rusty Russell
8caffde0fa pytest: test for watching utxos over restart reorg.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-29 08:18:20 +10:30
Rusty Russell
4d8f1d33e9 pytest: add failing downgrade test.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-28 09:16:53 +10:30
Rusty Russell
a45c907200 lightningd-downgrade: downgrade askrene's layer info too.
If they had a channel bias, and ran xpay, it will update the bias
to a v2 bias (with a timestamp).  We must downgrade that, or the
older version won't load!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-28 09:16:53 +10:30
Rusty Russell
9981e238a3 tools/lightning-downgrade: tool to downgrade (offline) v25.12 to v25.09.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: tools: `lightningd-downgrade` can downgrade your database from v25.12 to v25.09 if something goes wrong.
2025-11-28 09:16:53 +10:30
Rusty Russell
23f2141683 global: use lightning-hsmtool not hsmtool.
When installed, the name is `lightning-hsmtool`.  We actually copy
`tools/hsmtool` to `tools/lightning-hsmtool` but that's a silly step
which we should get rid of.

So:
1. Make sure our documentation always refers to it as lightning-hsmtool.
2. Make sure our tests invoke it as `lightning-hsmtool`.
3. Rename the C file.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-28 09:16:53 +10:30
Rusty Russell
fc23b538cd lightningd: print UNUSUAL log message if a command is very slow.
We don't expect an internal command to take 5 seconds to service
without explicitly pausing: if it does, log at a higher level.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-27 15:04:20 +10:30
Sangbida Chaudhuri
4c7e2d449d hsmd: fix HSM sent an unknown message type error
When we enter the wrong passphrase hsmd crashes like this with an unknown message type:

lightning_hsmd: Failed to load hsm_secret: Wrong passphrase (version v25.12rc1-7-g7713a42-modded)
0x102ba44bf ???
        send_backtrace+0x4f:0
0x102b0900f status_failed
        common/status.c:207
0x102af1a37 hsmd_send_init_reply_failure
        hsmd/hsmd.c:301
0x102af1497 load_hsm
        hsmd/hsmd.c:446
0x102af1497 init_hsm
        hsmd/hsmd.c:548
0x102b29e63 next_plan
        ccan/ccan/io/io.c:60
0x102b29e63 do_plan
        ccan/ccan/io/io.c:422
0x102b29d8b io_ready
        ccan/ccan/io/io.c:439
0x102b2b4bf io_loop
        ccan/ccan/io/poll.c:470
0x102af0a83 main
        hsmd/hsmd.c:886
lightningd: HSM sent unknown message type

This change swaps write_all() to wire_synce_write() because write_all() is missing the wire protocol length prefix. We also don't send a stack trace anymore if the user has entered the wrong passphrase and exit cleanly.
2025-11-27 14:06:17 +10:30
Peter Neuroth
719fb2ce52 plugin: change method name of lsps-jitchannel
The original method name was lsps-lsps2-invoice but I somehow messed it
up and renamed during a rebase.

Changelog-Changed: lsps-jitchannel is now lsps-lsps2-invoice

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-11-21 13:48:29 +10:30
Rusty Russell
b4f17508b1 libplugin: add spamlistcommand
This hammers lightingd with `listinvoices` commands.

	$ VALGRIND=0 TEST_DB_PROVIDER=postgres eatmydata uv run pytest -v tests/benchmark.py::test_spam_listcommands

sqlite3:

   test_spam_listcommands     2.1193  2.4524  2.2343  0.1341  2.2229  0.1709       1;0  0.4476       5           1

PostgreSQL:

   test_spam_listcommands     6.5572  6.8440  6.7067  0.1032  6.6967  0.1063       2;0  0.1491       5           1

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-20 16:30:50 +10:30
Rusty Russell
ce425b465c pytest: move test_coinmoves.py::test_generate_coinmoves and test_plugin.py::test_spam_commands to benchmark.py
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-20 16:30:50 +10:30
Rusty Russell
5fd95b3d22 tests/benchmark.py: tune nodes a little.
Drop the log level, don't do extra memory checks, don't dump I/O.  These are not
realistic for testing non-development nodes.

Here's the comparison, using:
	VALGRIND=0 eatmydata uv run pytest -v --benchmark-compare=0001_baseline tests/benchmark.py

Name (time in us)                                       Min                       Max                      Mean                  StdDev                    Median                     IQR            Outliers         OPS            Rounds  Iterations
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_invoice (NOW)                                 414.9430 (1.0)         39,115.6150 (12.35)          834.7296 (1.0)        2,274.1198 (6.59)           611.7745 (1.0)          162.0230 (1.0)          1;33  1,197.9927 (1.0)         290           1
test_invoice (0001_baselin)                        951.9740 (2.29)         3,166.4061 (1.0)          1,366.7944 (1.64)         345.1460 (1.0)          1,328.6110 (2.17)         339.3517 (2.09)        48;15    731.6389 (0.61)        221           1

test_pay (NOW)                                  36,339.2329 (87.58)       69,477.8530 (21.94)       51,719.9459 (61.96)      8,033.4262 (23.28)       52,639.5601 (86.04)      9,590.1425 (59.19)         6;0     19.3349 (0.02)         17           1
test_pay (0001_baselin)                         61,741.5591 (148.80)     108,801.6961 (34.36)       88,284.6752 (105.76)    15,875.4417 (46.00)       96,006.0760 (156.93)    27,500.9771 (169.74)        6;0     11.3270 (0.01)         13           1

test_single_payment (NOW)                       46,721.4010 (112.60)      66,027.6250 (20.85)       56,699.4597 (67.93)      5,829.7234 (16.89)       54,659.9385 (89.35)      9,810.9820 (60.55)         6;0     17.6369 (0.01)         14           1
test_single_payment (0001_baselin)              52,215.3670 (125.84)     109,608.0400 (34.62)       74,521.8032 (89.28)     16,175.6833 (46.87)       72,881.5976 (119.13)    17,668.8581 (109.05)        4;1     13.4189 (0.01)         12           1

test_forward_payment (NOW)                     108,338.2401 (261.09)     115,570.7800 (36.50)      111,353.7021 (133.40)     2,483.2338 (7.19)       111,981.6790 (183.04)     3,360.6182 (20.74)         3;0      8.9804 (0.01)         11           1
test_forward_payment (0001_baselin)            108,917.7490 (262.49)     168,348.2911 (53.17)      140,321.5990 (168.10)    22,375.2216 (64.83)      143,746.4900 (234.97)    36,363.4459 (224.43)        3;0      7.1265 (0.01)          7           1

test_start (NOW)                               299,278.4000 (721.25)     330,340.2610 (104.33)     314,121.8292 (376.32)    11,385.4700 (32.99)      314,603.4899 (514.25)    13,876.4871 (85.65)         2;0      3.1835 (0.00)          5           1
test_start (0001_baselin)                      305,928.9111 (737.28)     575,270.0820 (181.68)     419,496.8460 (502.55)   138,248.1937 (400.55)     334,207.0500 (546.29)   254,339.0035 (>1000.0)       2;0      2.3838 (0.00)          5           1

test_long_forward_payment (NOW)              1,088,077.8680 (>1000.0)  1,131,035.0260 (357.20)   1,108,896.7970 (>1000.0)   20,494.1195 (59.38)    1,098,544.8329 (>1000.0)   36,904.4899 (227.77)        3;0      0.9018 (0.00)          5           1
test_long_forward_payment (0001_baselin)     1,282,326.5721 (>1000.0)  1,450,350.8301 (458.04)   1,369,618.5776 (>1000.0)   73,432.8716 (212.76)   1,380,547.3910 (>1000.0)  132,647.3573 (818.69)        2;0      0.7301 (0.00)          5           1

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-20 16:30:50 +10:30
Rusty Russell
b03562b980 pytest: test for 1M JSONRPC calls which don't need transactions.
To measure the improvement (if any) if we don't actually create empty transactions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-20 16:30:50 +10:30
Rusty Russell
6865fe380d pytest: increase test_generate_coinmoves to 5M entries.
This is slow, but will make sure we find out if we add latency spikes in future.

tests/test_coinmoves.py::test_generate_coinmoves (5,000,000, sqlite3):
	Time (from start to end of l2 node):	 223 seconds
	Latency min/median/max:			 0.0023 / 0.0033 / 0.113 seconds

tests/test_coinmoves.py::test_generate_coinmoves (5,000,000, Postgres):
	Time (from start to end of l2 node):	 470 seconds
	Worst latency:				 0.0024 / 0.0098 / 0.124 seconds

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: lightningd: multiple signficant speedups for large nodes, especially preventing "freezes" under exceptionally high load.
2025-11-20 16:30:50 +10:30
Rusty Russell
213cbba5bf lightningd: allow filtering on custommsg hook too.
Changelog-Added: Plugins: "filters" can be specified on the `custommsg` hook to limit what message types the hook will be called for.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-20 16:30:50 +10:30
Rusty Russell
9961f6bf0e xpay: use filtering on rpc_command so we only get called on "pay".
tests/test_coinmoves.py::test_generate_coinmoves (2,000,000, sqlite3):
	Time (from start to end of l2 node):	 135 seconds **WAS 227**
	Worst latency:				 12.1 seconds **WAS 62.4**

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-20 16:30:50 +10:30
Rusty Russell
6006467824 pytest: increase test_generate_coinmoves to 2M entries.
Now we've rid ourselves of the worst offenders, we can make this a real
stress test.  We remove plugin io saving and low-level logging, to avoid
benchmarking testing artifacts.

Here are the results:

tests/test_coinmoves.py::test_generate_coinmoves (2,000,000, sqlite3):
	Time (from start to end of l2 node):	518 seconds
	Worst latency:				353 seconds

tests/test_coinmoves.py::test_generate_coinmoves (2,000,000, Postgres):
	Time (from start to end of l2 node):	 417 seconds
	Worst latency:				 96.6 seconds

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-20 16:30:50 +10:30
Rusty Russell
576f48cb74 lightningd: log when we have to defer hook registration.
If livelock ever *does* become an issue, we will see it in the logs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-20 16:30:50 +10:30
Rusty Russell
a4f772efa7 lightningd: avoid race when runtime-added plugins register hooks.
If we add a new hook, not at the end, while hooks are getting called,
then iteration could be messed up (e.g. calling a plugin twice, or
skipping one).

The simplest thing is to defer updates until nobody is calling the
hook.  In theory this could livelock, in practice it won't.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-20 16:30:50 +10:30
Rusty Russell
fd2bf0dc16 pytest: latency and speed test on large coinmoves.
We start with 100,000 entries.  We will scale this to 2M as we fix the
O(N^2) bottlenecks.

I measure the node time after we modify the db, like so:

	while guilt push && rm -rf /tmp/ltests* && uv run make -s RUST=0; do RUST=0 VALGRIND=0 TIMEOUT=100 TEST_DEBUG=1 eatmydata uv run pytest -vvv -p no:logging tests/test_coinmoves.py::test_generate_coinmoves > /tmp/`guilt top`-sql 2>&1; done

Then analyzed the results with:
	FILE=/tmp/synthetic-data.patch-sql; START=$(grep 'lightningd-2 .* Server started with public key' $FILE | tail -n1 | cut -d\  -f2 | cut -d. -f1); END=$(grep 'lightningd-2 .* JSON-RPC shutdown' $FILE | tail -n1 | cut -d\  -f2 | cut -d. -f1); echo $(( $(date +%s -d $END) - $(date +%s -d $START) )); grep 'E       assert' $FILE;

tests/test_coinmoves.py::test_generate_coinmoves (100,000, sqlite3):
	Time (from start to end of l2 node):	85 seconds
	Worst latency:				75 seconds

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-20 16:30:50 +10:30
Rusty Russell
d66e7de9bc pytest: fix changed msg on plugin failure.
bc4bb2b0ef "libplugin: use jsonrpc_io logic for sync requests too."
changed this message, and test was not updated.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-20 16:30:50 +10:30
Rusty Russell
9d803caeec pytest: fix flake in test_connect_ratelimit
Delay can cause bogus complaints:

```
2025-11-13T23:50:03.6643632Z lightningd-3 2025-11-13T23:37:29.947Z **BROKEN** 0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-connectd: wake delay for WIRE_CHANNEL_REESTABLISH: 5708msec
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-19 14:29:08 +10:30
Rusty Russell
989d59f72d pytest: fix flake when htlc_timeout_tx gets short sig:
```
        check_channel_moves(l1, expected_channel1)
>       check_chain_moves(l1, expected_chain1)

tests/test_coinmoves.py:942: 
...
                   'account_id': 'wallet',
                   'blockheight': 115,
                   'created_index': 15,
         -         'credit_msat': Decimal('6358000.00000000'),
         -         'debit_msat': 0,
         ?           --
         +         'credit_msat': 6366000,
         ?          +++           ++++++
         +         'debit_msat': 0,
                   'extra_tags': [],
         -         'output_msat': Decimal('6358000.00000000'),
         +         'output_msat': 6366000,
                   'primary_tag': 'deposit',
                   'utxo': '4a16b7aceac233ed68bed0f18adfc1ab338b5fc55b696d1376eea173adeac8e3:1',
               },
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-19 14:29:08 +10:30
Rusty Russell
2520bd5b90 pytest: test withhold parameter to fundchannel_complete.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-19 07:23:39 +10:30
Rusty Russell
39349965a6 lightningd: add withheld flag to listpeerchannels and listclosedchannels.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `listpeerchannels` `funding` object `withheld` flag, and `listclosedchannels` `funding_withheld` flags, indicating fundchannel_complete was called with the `withheld` parameter true.
2025-11-19 07:23:39 +10:30
Rusty Russell
df5f38dbc1 spender: look for unsigned PSBT on awaiting channels on startup, and re-send.
This covers the other corner case, where we crash before actually
signing and sending the PSBT.  We can spot this because the channel is
in AWAITING_LOCKIN and we have a PSBT, but it's not signed yet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-19 07:23:39 +10:30
Rusty Russell
606aad07ed lightningd: expose funding PSBT (if we have it) in JSON API.
Changelog-Added: JSON-RPC: `psbt` field in `funding` in listpeerchannels, and `funding_psbt` in listclosedchannels.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-19 07:23:39 +10:30
Rusty Russell
409beb6923 pytest: test failure if we crash after fundchannel_complete but before sendpsbt.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-19 07:23:39 +10:30
Rusty Russell
d44fa2f3bd lightningd: re-xmit funding txs on startup.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Protocol: we now re-transmit unseen funding transactions on startup, for more robustness.
2025-11-19 07:23:39 +10:30
Rusty Russell
21d19546d5 pytest: test case where we crash before bitcoind gets the opening tx.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-19 07:23:39 +10:30
Rusty Russell
f284489c96 common: don't abort() if wally_psbt_output_taproot_keypath_add() fails.
It fails on duplicates.  It would ideally succeed, but bug reported:

	https://github.com/ElementsProject/libwally-core/issues/509

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: JSON-RPC: `signpsbt` no longer crashes if asked to sign an already-signed PSBT with taproot paths.
2025-11-19 07:23:39 +10:30
Rusty Russell
eaf7ac19c1 pytest: test for signing a signed PSBT.
Spoiler: we crash!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-19 07:23:39 +10:30
Rusty Russell
13852b7ff5 pytest: add tests for channel_state_changed into the CLOSED state.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-18 14:28:22 +10:30
Rusty Russell
73147dafe2 xpay: restrict maxparts to 6 for non-public nodes, but remove it if we can't route.
This attempts to solve a problem we have with Phoenix clients:

	This payment has been split in two many parts by the sender: 31 parts vs max 6 parts allowed for on-the-fly funding.

The problem is that we don't have any way in bolt11 or bolt12 to
specify the maximum number of HTLCs.

As a workaround, we start by restricting askrene to 6 parts if the
node is not openly reachable, and if it struggles, we remove the
restriction.  This would work much better if askrene handled maxparts
more completely!

See-Also: https://github.com/ElementsProject/lightning/issues/8331
Changelog-Fixed: `xpay` will not try to send too many HTLCs through unknown channels (6, as that is Phoenix's limit) unless it has no choice
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-17 19:46:00 +10:30
Rusty Russell
145af08feb pytest: Test that we don't try to pay too many htlcs at once through an unknown channel.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-17 19:46:00 +10:30
Rusty Russell
1102d8063e askrene: add optional layers to reservations.
We have the issue of aliases: xpay uses scids like 0x0x0 for
routehints and blinded paths, and then can apply reservations to them.  But
generally, reservations are *global*, so we need to differentiate.

Changelog-Added: Plugins: `askrene-reserve` and `askrene-unreserve` can take an optional `layer` inside `path` elements.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-17 13:52:54 +10:30
Rusty Russell
da4edd2811 pytest: test to demonstrate that reservations of "private" channels overlap.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-17 13:52:54 +10:30
Rusty Russell
8c7ac33f88 askrene: implement reduce_num_flows in refine, using increase_flows().
Now we simply call it at the end.  We need to check it hasn't violated fee maxima, but
otherwise it's simple.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Plugins: `askrene` now handles limits on number of htlcs much more gracefully.
2025-11-17 10:56:18 +10:30
Rusty Russell
7c7a4f8795 askrene: Remove index indirection from squash_flows, simplify sorting.
We don't need to convert to strings, we can compare directly.  This removes the final
use of the index arrays.

This of course changes the order of returned routes, which alters test_real_biases, since
that biases against the final channel in the *first* route.

Took me far too long to diagnose that!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-17 10:56:18 +10:30
Rusty Russell
35f65c5d91 common: add amount_msat_deduct / amount_msat_deduct_sub.
I added amount_msat_accumulate for the "a+=b" case, but I was struggling
with a name for the subtractive equivalent.  After some prompting, ChatGPT
suggested deduct.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-17 10:56:18 +10:30