Commit Graph

15484 Commits

Author SHA1 Message Date
Rusty Russell
b327bd30c3 doc: fix all JSON schemas to enforce no additional properties.
Without this, we have hardly any enforcement.  This is why the schema
mistake fixed in the previous patches weren't spotted immediately.

The hard work was done by:

```
$ for f in lightning-*.json; do grep -v '^  "additionalProperties": false,' $f | bagto $f; done
$ for f in lightning-*.json; do sed 's/"properties": {/"additionalProperties": false, "properties": {/' $f | bagto $f; done
$ make fmt-schemas
```

Then checking where 'additionalProperties: true' had been turned to
false (we deliberately use it in some places where there are if
statements in the schema, or occasionally where there can be arbitrary
fields).

[Including doc/rpc-schema-draft.json update by Shahana]
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-30 15:39:12 +10:30
Rusty Russell
7b2c791dcf doc: fix up missing fields from schemas.
This allows the next patch (which makes the schemas stricter) to not
break our tests.

We add some missing fields (including dev fields, but they're empty and hidden),
and add a few minor clarifications and a spelling fix.  Most of these are new
schemas for this release, so no mention in Changelog.

Here is the difference in the man pages:

    --- doc/lightning-askrene-inform-channel.7.md.old	2024-10-29 17:33:07.714521584 +1030
    +++ doc/lightning-askrene-inform-channel.7.md	2024-10-29 17:42:37.434280109 +1030
    @@ -24,6 +24,8 @@
     - **short\_channel\_id\_dir** (short\_channel\_id\_dir): The short channel id and direction
    +- **layer** (string): The name of the layer to apply this change to.
    +- **timestamp** (u64): The UNIX timestamp when this constraint was created.
     - **maximum\_msat** (msat, optional): The maximum value which this channel could pass.
    --- doc/lightning-askrene-listlayers.7.md.old	2024-10-29 17:33:07.716521571 +1030
    +++ doc/lightning-askrene-listlayers.7.md	2024-10-29 17:42:37.424280316 +1030
    @@ -29,13 +29,16 @@
     - **channel\_updates** (array of objects):
    +  - **short\_channel\_id\_dir** (short\_channel\_id\_dir): The short channel id and direction this update applies to.
    +  - **enabled** (boolean, optional): True if this can be used, false otherwise.
       - **htlc\_minimum\_msat** (msat, optional): The minimum value allowed in this direction.
       - **htlc\_maximum\_msat** (msat, optional): The maximum value allowed in this direction.
       - **fee\_base\_msat** (msat, optional): The base fee to apply to use the channel in this direction.
       - **fee\_proportional\_millionths** (u32, optional): The proportional fee (in parts per million) to apply to use the channel in this direction.
    -  - **delay** (u16, optional): The CLTV delay required for this direction.
    +  - **cltv\_expiry\_delta** (u16, optional): The CLTV delay required for this direction.
     - **constraints** (array of objects):
       - **short\_channel\_id\_dir** (short\_channel\_id\_dir): The short channel id and direction
    +  - **timestamp** (u64, optional): The UNIX timestamp when this constraint was created.
       - **maximum\_msat** (msat, optional): The maximum value which this channel could pass.
    --- doc/lightning-askrene-listreservations.7.md.old	2024-10-29 17:33:07.719521550 +1030
    +++ doc/lightning-askrene-listreservations.7.md	2024-10-29 17:42:37.428280233 +1030
    @@ -16,7 +16,7 @@
    -On success, an object containing **layers** is returned. It is an array of objects, where each object contains:
    +On success, an object containing **reservations** is returned. It is an array of objects, where each object contains:
    --- doc/lightning-autoclean-status.7.md.old	2024-10-29 17:33:07.732521462 +1030
    +++ doc/lightning-autoclean-status.7.md	2024-10-29 17:42:37.441279965 +1030
    @@ -9,7 +9,7 @@
     
    -The **autoclean-status** RPC command tells you about the status of the autclean plugin, optionally for only one subsystem.
    +The **autoclean-status** RPC command tells you about the status of the autoclean plugin, optionally for only one subsystem.
     
    --- doc/lightning-renepay.7.md.old	2024-10-29 17:33:07.927520140 +1030
    +++ doc/lightning-renepay.7.md	2024-10-29 17:42:37.996268504 +1030
    @@ -58,6 +58,9 @@
     - **status** (string) (one of "complete", "pending", "failed"): Status of payment.
    +- **bolt11** (string, optional): The bolt11 invoice paid. *(added v23.08)*
    +- **bolt12** (string, optional): The bolt12 invoice paid. *(added v23.08)*
    +- **groupid** (u64, optional): The groupid used for these payment parts (as can be seen in listsendpays) *(added v23.08)*
     - **destination** (pubkey, optional): The final destination of the payment.
    --- doc/lightning-sendonion.7.md.old	2024-10-29 17:33:07.937520073 +1030
    +++ doc/lightning-sendonion.7.md	2024-10-29 17:42:37.957269309 +1030
    @@ -22,7 +22,7 @@
    -- **first\_hop** (object): Instructs Core Lightning which peer to send the onion to. It is a JSON dictionary that corresponds to the first element of the route array returned by *getroute*.:
    +- **first\_hop** (object): Instructs Core Lightning which peer to send the onion to. It is a JSON dictionary that corresponds to the first element of the route array returned by *getroute* (so fields not mentioned here are ignored).:
    
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: `renepay` return fields documented in schema (`bolt11`, `bolt12` and `groupid`)
2024-10-30 15:39:12 +10:30
Rusty Russell
fd860f69f8 doc: fix schema for askrene-update-channel.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-30 15:39:12 +10:30
Rusty Russell
916a36a9e4 lightningd: new command injectpaymentonion.
This is like `sendonion` but unwraps the onion as the first hop,
avoiding nasty special cases for blinded paths which start with this
node, and also self-pay.

Tests split into multiple ones after Christian's review.

Changelog-Added: JSON-RPC: `injectpaymentonion` for initiating an HTLC like a peer would do.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-27 13:57:50 +11:00
Rusty Russell
6bfebf4307 lightningd: refactor payment failed.
Don't assume we have an outgoing HTLC at this level.

Note that previously we didn't save the failed onion unless it was
unparsable: we keep that both for space savings and because our
`waitsendpay` logic assumes that when it fetches from the db if
there's a failonion it was unparsable!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-27 13:57:50 +11:00
Rusty Russell
851d8733c6 pytest: generalize serialize_payload_tlv/serialize_payload_final_tlv
Put these in utils and make them a bit more powerful, so we can use
them elsewhere.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-27 13:57:50 +11:00
Rusty Russell
6a8e8b2dc9 lightningd: generalize waitsendpay_command so we can use it for injectpaymentonion.
Rather than assuming the callbacks, make them function pointers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-27 13:57:50 +11:00
Rusty Russell
93c1876d1e lightningd: generalize htlc_set.
Make it a set of arbitrary data, so we can use it for local payments,
not just HTLCs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-27 13:57:50 +11:00
Rusty Russell
41610d7bab lightningd: allow htlc_set_fail to take empty msg to send incorrect_or_unknown_payment_details
This message is supposed to include the msat amount received.  But this is
obviously per-HTLC, and we hacked it to use the value for the first one.

And we add logging whenever we fail an HTLC set, since we removed logging
by not calling failmsg_incorrect_or_unknown() (which, now, no longer needs
to log).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-27 13:57:50 +11:00
Rusty Russell
fdb3f5fe1b lightningd: make failmsg_incorrect_or_unknown take amount, not htlc_in.
This makes it slightly more generic.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-27 13:57:50 +11:00
Se7enZ
4017844d0c lightningd: listforwards returns 0 for missing received_time. ([#7157])
Removes the `COMPAT_V070` functionality for `listfowards`.

Changelog-Changed: The `listforwards` command will now return a value
of 0 for `received_time` for very old forward attempts.
2024-10-26 09:51:20 +02:00
Se7enZ
3a363df5fb docs: Fix openchannel_abort generated JSON schema.
Changelog-None
2024-10-25 12:13:32 -07:00
Lakshya Singh
9c5e1ca82c docs: openchannel_abort correction
Signed-off-by: Lakshya Singh <lakshay.singh1108@gmail.com>
2024-10-23 22:01:33 +02:00
Se7enZ
4f5ea34461 doc: gRPC SSL custom certificate generation instructions with SANs.
Changelog-Added: Example documentation on generating custom gRPC
certificates with SANs.
2024-10-21 13:58:42 -07:00
Se7enZ
35cda77b3b doc: Fix gRPC custom certificate anchor links. 2024-10-21 13:58:42 -07:00
Joseph Goulden
34187bbf9d doc: Add nix flake documentation to developers guide 2024-10-21 16:56:02 +02:00
Joseph Goulden
d49b5a53fb build: Add cln-postgres package to nix flake 2024-10-21 16:56:02 +02:00
Joseph Goulden
f31a8cf749 build: Update .version as part of the release 2024-10-21 16:56:02 +02:00
Joseph Goulden
fe7168b335 build: Exclude python plugins from flake build 2024-10-21 16:56:02 +02:00
Joseph Goulden
864ece025e build: Add nix derivation for building cargo workspace 2024-10-21 16:56:02 +02:00
Joseph Goulden
2056478e56 build: Add simple flake
Changelog-Added: Nix users can now install CLN from the new flake.
2024-10-21 16:56:02 +02:00
alfredo-toledano
3c3008c5cc doc(README.md): fix typo about supported installation options
Changelog-None
2024-10-21 12:40:28 +02:00
Emmanuel Ferdman
2cb590643f doc: update reference to the generator code
Changelog-None.

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
2024-10-18 14:01:33 -07:00
ShahanaFarooqui
4f0f84661e release: Update the changelog for point release v24.08.2
Changelog-None.
2024-10-18 09:06:17 -07:00
ShahanaFarooqui
2171583d47 doc: Fix documentation version
Changelog-Fixed: The documentation version was calculated as `pre-v24.08` for point releases like v24.08.1` also because `CLN_NEXT_VERSION` has not been included in the point release branches. Updating the script to build documentation on new tags and change the version to `pre-cln-next-version` for non-tagged commits.
2024-10-17 06:48:08 +10:30
Rusty Russell
fe344ee75b BOLT: update to latest BOLT 3 test vectors.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-16 07:14:32 +10:30
Rusty Russell
905461f7c4 BOLTs: more catchup ("BOLT 4: More clarifying changes.")
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-16 07:14:32 +10:30
Rusty Russell
76cfff7533 BOLT update: catch up ("BOLT 4: rename onionmsg_hop to blinded_path_hop")
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-16 07:14:32 +10:30
Rusty Russell
f92c9430fd BOLT catchup ("BOLT 4: clarify blinded path requirements.")
This is a significant rework, which lets us clarify a number of our
quotes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-16 07:14:32 +10:30
Rusty Russell
45533584e2 global: rename blinding to path_key everywhere.
Get with the modern nomenclature: the pubkey inside a blinded path is called
the `path_key` now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-16 07:14:32 +10:30
Rusty Russell
9f593a8184 lightningd: update injectonionmessage API to new terminology.
It's not documented, and only used internally, so we don't need a deprecation
cycle.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-16 07:14:32 +10:30
Rusty Russell
014459d893 lightningd: update decryptencrypteddata API to new terminology.
It's not documented, and only used internally, so we don't need a deprecation
cycle.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-16 07:14:32 +10:30
Rusty Russell
fd717c71af global: deprecate old names in JSON fields, add new ones.
Changelog-Added: JSON-RPC: `decode` now used modern BOLT 4 language for blinded paths, `first_path_key`.
Changelog-Deprecated: JSON-RPC: `decode` `blinding` in blinded path: use `first_path_key`.
Changelog-Added: Plugins: `onion_message_recv` and `onion_message_recv_secret` hooks now used modern BOLT 4 language for blinded paths, `first_path_key`.
Changelog-Deprecated: JSON-RPC: `onion_message_recv` and `onion_message_recv_secret` hooks `blinding` in blinded path: use `first_path_key`.
2024-10-16 07:14:32 +10:30
Rusty Russell
dc18f3cd7b BOLTs: update which renames blinding terminology.
No code changes, just catching up with the BOLT changes which rework our
blinded path terminology (for the better!).

Another patch will sweep the rest of our internal names, this tries only to
make things compile and fix up the BOLT quotes.

1. Inside payload: current_blinding_point -> current_path_key
2. Inside update_add_htlc TLV: blinding_point -> blinded_path
3. Inside blinded_path: blinding -> first_path_key
4. Inside onion_message: blinding -> path_key.
5. Inside encrypted_data_tlv: next_blinding_override -> next_path_key_override

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-16 07:14:32 +10:30
Rusty Russell
f944e03fca BOLT update: remove INVALID_REALM error.
This is obsolete (since modern onions) and so removed from spec.
We should not set it, and don't need to handle it specially.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-16 07:14:32 +10:30
Rusty Russell
63f971b892 BOLTs: catchup with "Drop the required channel_update in failure onions".
Not much difference for us.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-16 07:14:32 +10:30
Rusty Russell
3a9536fd37 BOLT catchup: quiescence is included.
This means we should support it by default.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `option_quiesce` enabled by default.
Changelog-Deprecated: Config: --experimental-quiesce: it's now the default.
2024-10-16 07:14:32 +10:30
Rusty Russell
c6be91f8ae wire: add missing patch.
We build with this: it changes the blinded_path field to sciddir_or_pubkey.
But it wasn't committed, so if someone rebuilt the wire files they'd be wrong.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-16 07:14:32 +10:30
Rusty Russell
318e49e9c7 askrene: more logging in explain_failure.
Lagrang3 doesn't like the logging in here at all, but he suggested we at
least be consistent!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-15 09:58:04 +10:30
Rusty Russell
95c5fda79f askrene: remove flowset_probability() now refine step calculates it.
Now we've checked it gives the same answers, we can remove a lot of
work in flow.c.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-15 09:58:04 +10:30
Rusty Russell
5501e4b13d askrene: use refine step to calculate flowset probability.
Since we know the total reservations on each hop, we can more easily
determine probabilities than using flowset_probability() which has to
replicate this collision detection.

We leave both in place for now, to check.  The results are not
identical, due to slightly different calculation methods.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-15 09:58:04 +10:30
Rusty Russell
4b6a38fe0a askrene: fix bug with reservations used during refinement.
We were trying to get the max capacity of a flow to see if we could add some
more sats, and hit an assertion:

tests/test_askrene.py:707: 

```
 DEBUG   plugin-cln-askrene: notify msg info: Flow reduced to deliver 88070161msat not 90008000msat, because 107x1x0/1 has remaining capacity 88071042msat
 DEBUG   plugin-cln-askrene: notify msg info: Flow reduced to deliver 284138158msat not 284787000msat, because 108x1x0/1 has remaining capacity 284141000msat
 **BROKEN** plugin-cln-askrene: Flow delivers 129565000msat but max only 56506138msat
 INFO    plugin-cln-askrene: Killing plugin: exited during normal operation
```

We need to *unreserve* our flow before asking for max capacity.  We were
also missing a few less important cases where we altered flows without altering
the reservation, so fix those too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-15 09:58:04 +10:30
Rusty Russell
bcc8bd59c8 askrene: don't *completely* ignore fees to start.
I noticed that increasing mu a little bit sometimes made a big difference,
because by completely ignoring fees we were choosing the worst of two channels
in some cases.

Start at 1% fees; this saves a lot on initial fees in this test!

Here's the new stats on mu levels:

     96  mu=1
     90  mu=10
     41  mu=20
     30  mu=30
     24  mu=40
     19  mu=50
     22  mu=60
      8  mu=70
     95  mu=80
     19  mu=90

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: `askrene` is now better at finding low-fee paths.
2024-10-15 09:58:04 +10:30
Rusty Russell
2a0f09fc2d askrene: calculate k value dynamically, using medians.
While the `k=8` value worked for the current main network tests with the
amounts in those tests, it wasn't robust across a wider range of values
(as demonstrated when other test changes broke tests!).

Time to do this properly: calculate the ratio at the time we combine them,
using median values.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-15 09:58:04 +10:30
Rusty Russell
32aa79a1e2 askrene: debug and check we actually reduce fees when mu increase.
Even after the previous fix, we still occasionally increase fees when my increases.

This is due to the difference between MCF's linear fees, and actual fees, and
is unavoidable, but add a check if it somehow happens.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-15 09:58:04 +10:30
Rusty Russell
08df93cb25 askrene: fix base fee.
I noticed this in the logs:

	plugin-cln-askrene: notify msg unusual: The flows had a fee of 151950msat, greater than max of 53697msat, retrying with mu of 10%...
	plugin-cln-askrene: notify msg unusual: The flows had a fee of 220126msat, greater than max of 53697msat, retrying with mu of 20%...

We would expect increasing mu to *reduce* the fee!

Turns out that our linear fee is a bad terrible approximation, because I
was using base_fee_penalty of 10.0.

 |
 |          /   __ <- real fee, with base: fee = base + propfee * amount.
 |         / __/
 |       _//
 |    __/
 | __/_/
 |/  _/
 | _/ <- linearized fee: fee = linear * amount
 |/
 +-----------------------------------

These cross over where linear = propfee + base / amount.  Assume we split the
payment into 10 parts, this implies that the base_fee_penalty should be 10 / amount
(this gives a slight penalty to the normal case, but that's ok).

This gives better results, too: we get down to 650099 sats in fees, vs 801613
before.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-15 09:58:04 +10:30
Rusty Russell
6273adbe47 askrene: calculate prob_cost_factor using ratio of typical mainnet channel.
During "test_real_data", then only successes with reduced fees were 92 on "mu=10", and only
1 on "mu=30": the rest went to mu=100 and failed.

I tried numerous approaches, and in the end, opted for the simplest:

The typical range of probability costs looks likes:
	min = 0, max = 924196240, mean = 10509.4, stddev = 1.9e+06

The typical range of linear fee costs looks like:
	min = 0, max = 101000000, mean = 81894.6, stddev = 2.6e+06

This implies a k factor of 8 makes the two comparable.

This makes the two numbers comparable, and thus makes "mu" much more
effective.  Here are the number of different mu values we succeeded at:

     87  mu=0
     90  mu=10
     42  mu=20
     24  mu=30
     17  mu=40
     19  mu=50
     19  mu=60
     11  mu=70
     95  mu=80
     19  mu=90

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-15 09:58:04 +10:30
Rusty Russell
4897286c25 mcf: simplify mu -> cost translation.
The current prob_cost_factor setting does not seem to make mu very
effective, in fact, it gives strange results:

	plugin-cln-askrene: notify msg unusual: The flows had a fee of 151950msat, greater than max of 53697msat, retrying with mu of 10%...
	plugin-cln-askrene: notify msg unusual: The flows had a fee of 220126msat, greater than max of 53697msat, retrying with mu of 20%...

We would expect increasing mu to *reduce* the fee!

As a first step, simplify (it can't be infinite, and the -1 are weird).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-15 09:58:04 +10:30
Rusty Russell
83eee64fda pytest: test askrene with worse maxfee argument.
We ask it again, but reduce fees by 1msat from the previous answer.
This is really nasty, as it frequently exercises the case where we
only go over fee when we do the refinement step.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-15 09:58:04 +10:30
Rusty Russell
55fc7fc2e5 pytest: test askrene on real network data.
I checked the failures, they seem real.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-10-15 09:58:04 +10:30