Commit graph

1637 commits

Author SHA1 Message Date
ShahanaFarooqui
c9552e4228 meta: Update changelog for 24.08rc3
Release candidate 3 for v24.08
2024-08-26 11:53:42 -07:00
Rusty Russell
50949b7b9c askrene: hack in some padding so we don't overflow capacities.
Of course, we still will, since spendable is for a single HTLC, but
this also shows why we should treat *minimum* as the incorrect answer
if they cross, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: https://github.com/ElementsProject/lightning/issues/7563
2024-08-23 18:52:15 +09:30
Rusty Russell
fafda82d82 askrene: fix up our handling of htlc_max.
It seems we didn't handle it correctly: we need to cap the first
segment as well as the others, as far as I can tell.

Also, it can be less than the maximum capacity.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-23 18:52:15 +09:30
Rusty Russell
975326ab5d askrene: round capacity *down* when converting to fp16.
Conversion is lossy, and we don't want to spend more than the channel,
so it's conservative to round down here.

This doesn't actually help our test though!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-23 18:52:15 +09:30
Rusty Russell
7fb7234da1 askrene: change finalcltv to final_cltv, and return it in response.
You need to know it to make an onion, and in theory if we decided to
fuzz it could be different for different paths.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-19 10:12:51 -07:00
Lagrang3
5400989552 renepay: bugfix: apply channel filter globally
Channel filter must apply to the modified gossmap+localmods,
otherwise we disable local channels with htlcmax=0.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-19 10:11:35 -07:00
Lagrang3
4fdc74f100 renepay: take it easy with local channels
Add a little bit of uncertainty to the local channels to avoid
consuming precisely all spendable_msat on our side, which leads to
temporary channel failure if the spendable_msat changes during the
course of the payment.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-19 10:11:35 -07:00
Lagrang3
e41625fb29 renepay: bugfix refreshgossmap
Refresh gossmap once before we read the routehints.
Make sure that if channels in the routehints are public,
we retrieve their capacities from gossip.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-19 10:11:35 -07:00
Lagrang3
d39b0092ec renepay: bugfix reserved htlc in MCF
Reserved HTLCs were underestimated by floor (mathematical function)
use ceil instead.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-19 10:11:35 -07:00
Lagrang3
bb68e65b7a renepay: add precondition check + error msg
- add more checks
- add more error messages
- compute probabilities without fees during MCF
- compute probabilities with fees during get_routes

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-19 10:11:35 -07:00
Lagrang3
684d6dff50 renepay: patch to assertion htlc_total<=known_max
In theory we should not have htlc_total<=known_max.
But for some strange race condition we do sometimes.
Until we find a solution to ensure the correct state
of the uncertainty network we remove the assertion.
Thanks to signed arithmetic and MIN guards, the rest
of the code in linearize_channel can handle the
weird cases with known_max<htlc_total.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-19 10:11:35 -07:00
ShahanaFarooqui
52f9678deb meta: Update changelog for 24.08rc2
Release candidate 2 for v24.08
2024-08-15 21:20:35 -07:00
Rusty Russell
9a6325c4f3 doc: properly document sub-subobject fields.
Inside listpeerchannels, there's an object called `updates`, and inside that objects `local` and `remote`.  We flatten this, but the documentation doesn't mention the `updates` field at all.

Ideally we would rename these fields to include `updates_` but that would be a breaking change.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

```
     - `row` (reference to `peerchannels_channel_type.rowid`, sqltype `INTEGER`)
     - `arrindex` (index within array, sqltype `INTEGER`)
     - `names` (type `string`, sqltype `TEXT`)
-  - `local_htlc_minimum_msat` (type `msat`, sqltype `INTEGER`, from JSON object `local`)
-  - `local_htlc_maximum_msat` (type `msat`, sqltype `INTEGER`, from JSON object `local`)
-  - `local_cltv_expiry_delta` (type `u32`, sqltype `INTEGER`, from JSON object `local`)
-  - `local_fee_base_msat` (type `msat`, sqltype `INTEGER`, from JSON object `local`)
-  - `local_fee_proportional_millionths` (type `u32`, sqltype `INTEGER`, from JSON object `local`)
-  - `remote_htlc_minimum_msat` (type `msat`, sqltype `INTEGER`, from JSON object `remote`)
-  - `remote_htlc_maximum_msat` (type `msat`, sqltype `INTEGER`, from JSON object `remote`)
-  - `remote_cltv_expiry_delta` (type `u32`, sqltype `INTEGER`, from JSON object `remote`)
-  - `remote_fee_base_msat` (type `msat`, sqltype `INTEGER`, from JSON object `remote`)
-  - `remote_fee_proportional_millionths` (type `u32`, sqltype `INTEGER`, from JSON object `remote`)
+  - `local_htlc_minimum_msat` (type `msat`, sqltype `INTEGER`, from JSON object `updates.local`)
+  - `local_htlc_maximum_msat` (type `msat`, sqltype `INTEGER`, from JSON object `updates.local`)
+  - `local_cltv_expiry_delta` (type `u32`, sqltype `INTEGER`, from JSON object `updates.local`)
+  - `local_fee_base_msat` (type `msat`, sqltype `INTEGER`, from JSON object `updates.local`)
+  - `local_fee_proportional_millionths` (type `u32`, sqltype `INTEGER`, from JSON object `updates.local`)
+  - `remote_htlc_minimum_msat` (type `msat`, sqltype `INTEGER`, from JSON object `updates.remote`)
+  - `remote_htlc_maximum_msat` (type `msat`, sqltype `INTEGER`, from JSON object `updates.remote`)
+  - `remote_cltv_expiry_delta` (type `u32`, sqltype `INTEGER`, from JSON object `updates.remote`)
+  - `remote_fee_base_msat` (type `msat`, sqltype `INTEGER`, from JSON object `updates.remote`)
+  - `remote_fee_proportional_millionths` (type `u32`, sqltype `INTEGER`, from JSON object `updates.remote`)
   - `ignore_fee_limits` (type `boolean`, sqltype `INTEGER`)
   - `lost_state` (type `boolean`, sqltype `INTEGER`)
   - `feerate_perkw` (type `u32`, sqltype `INTEGER`, from JSON object `feerate`)
```
2024-08-16 07:19:52 +09:30
Rusty Russell
054eeb8aa2 plugins/sql: fix crash when subobject is missing which has subobject inside it.
There's only one place (added in v24.02) where we have nested subobjects, and
if the outer sub-object is not there it crashes.

```
sql: FATAL SIGNAL 11 (version v24.08rc1-2-ge134f2f-modded)
0x5781d447239b send_backtrace
        common/daemon.c:33
0x5781d4472432 crashdump
        common/daemon.c:75
0x787bcd64531f ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x5781d447782a json_get_membern
        common/json_parse_simple.c:210
0x5781d44778cc json_get_member
        common/json_parse_simple.c:223
0x5781d445d0e2 process_json_obj
        plugins/sql.c:537
0x5781d445d10d process_json_obj
        plugins/sql.c:538
0x5781d445d598 process_json_list
        plugins/sql.c:684
0x5781d445d65a process_json_result
        plugins/sql.c:699
0x5781d445d7cb default_list_done
        plugins/sql.c:722
0x5781d446349d handle_rpc_reply
        plugins/libplugin.c:1016
0x5781d4463640 rpc_read_response_one
        plugins/libplugin.c:1202
0x5781d44636f1 rpc_conn_read_response
        plugins/libplugin.c:1226
0x5781d459e56c next_plan
        ccan/ccan/io/io.c:60
0x5781d459ea3d do_plan
        ccan/ccan/io/io.c:422
0x5781d459eafa io_ready
        ccan/ccan/io/io.c:439
0x5781d45a0469 io_loop
        ccan/ccan/io/poll.c:455
0x5781d4463dcb plugin_main
        plugins/libplugin.c:2230
```

Changelog-Fixed: Plugins: `sql` crash on querying `listpeerchannels` during channel establishment.
Fixes: https://github.com/ElementsProject/lightning/issues/7505
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-16 07:19:52 +09:30
Rusty Russell
a6c2f183d6 bookkeeper: fix up out-of-order migrations in rc1
This was introduced in rc1, resulting in:

```
2024-08-15T01:33:48.343Z **BROKEN** plugin-bookkeeper: query failed: plugins/bkpr/recorder.c:738: SELECT  e.id, e.account_id, a.name, e.origin, e.tag, e.credit, e.debit, e.output_value, e.currency, e.timestamp, e.blockheight, e.utxo_txid, e.outnum, e.spending_txid, e.payment_id, e.ignored, e.stealable, e.ev_desc, e.spliced FROM chain_events e LEFT OUTER JOIN accounts a ON e.account_id = a.id WHERE  e.spending_txid = ? AND e.account_id = ? AND e.utxo_txid = ? AND e.outnum = ?
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-16 07:18:29 +09:30
Lagrang3
7056018b15 renepay: add const probability cost
The probability for a success forward of x amount on a channel is now
computed as:

	P_success(x) = b * P_rene(x)

where P_rene(x) is the probability distribution proposed by Rene
Pickhardt with a uniform distribution on the known liquidity of the
channel and 'b' is a new parameter we add in this PR, by the name of
"base probability". The "base probability" represents the probability
for a channel in the network choosen at random to be able to forward at
least 1msat, ie. of being alive, non-depleted and with at least one HTLC
slot. We don't know the value of 'b', but for the moment we assume that
it is 0.98 and use that as default.

As a consequence the probability cost becomes non-linear and non-convex
because of the additional constant term:

	Cost(x) = - log P_success(x)
	        = - log b  -  - log P_rene(x)
		= - log b  +  Cost_rene(x)

We currently don't handle well base fees and neither this additional
"base probability" but we can as a first approximation linearize the
cost function in this way:

	Cost_linear(x) = (- log b)*x  +  Cost_rene_linear(x)

Changelog-Added: renepay: Add a dev parameter to renepay that represents
a constant probability of availability for all channels in the network.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-15 16:46:41 +09:30
ShahanaFarooqui
fb3579c1a4 meta: Update changelog for 24.08rc1
Release candidate 1 for v24.08
2024-08-13 08:32:23 -07:00
ShahanaFarooqui
3fe454b54e gitignore: Add missing gitignore plugins an devtools 2024-08-13 08:32:23 -07:00
Lagrang3
9afc10bf99 renepay: add cli option exclude
msggen cannot handle the complex type in renepay-exclude,
therefore I added a rule override for it, just like pay-exclude.

```
msggen cln-grpc/proto/node.proto
Traceback (most recent call last):
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/__main__.py", line 131, in <module>
    main()
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/__main__.py", line 115, in main
    run()
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/__main__.py", line 72, in run
    service = load_jsonrpc_service(
              ^^^^^^^^^^^^^^^^^^^^^
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/utils/utils.py", line 241, in load_jsonrpc_service
    methods = [load_jsonrpc_method(name) for name in grpc_method_names]
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/utils/utils.py", line 209, in load_jsonrpc_method
    request = CompositeField.from_js(schema["methods"][rpc_name]['request'], path=name)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/model.py", line 297, in from_js
    field = ArrayField.from_js(fpath, ftype)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/model.py", line 464, in from_js
    itemtype = UnionField.from_js(child_js, path)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/model.py", line 393, in from_js
    itemtype = PrimitiveField(
               ^^^^^^^^^^^^^^^
TypeError: PrimitiveField.__init__() missing 2 required positional arguments: 'added' and 'deprecated'
```

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Changelog-EXPERIMENTAL: renepay: add cli option "exclude" to manually disable channels and nodes.
2024-08-12 22:44:58 -07:00
Lagrang3
44d53dc473 renepay: add a channel filtering paymod
We add a channel filtering paymod that disables channels that have very
low max_htlc. It can be expanded to consider other properties as well,
for instance high base fee, low capacity or high latency.

Changelog-Added: renepay: prune the network by disabling channels we
don't like, eg. very low max_htlc.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 22:44:58 -07:00
Lagrang3
c0dd3cd826 renepay: disabled channels in a map
Expecting to have more than just a bunch of disabled channels if we
prune the lightning network heavily I am changing the internal data
structure of disabledmap from a simple array to a hashtable.

Have a finer control over disabled channels by targeting
short_channel_id_dir instead of short_channel_id,
ie. we can disable a single direction of a channel.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 22:44:58 -07:00
daywalker90
7ffd0a3936 cln-plugin: add multi options for String and i64
Changelog-Added: cln-plugin: add multi options for String and i64
2024-08-13 12:24:45 +09:30
Alex Myers
88504ea6d2 reckless-rpc: catch failed reckless subprocess
... before processing the output. It's probably a python backtrace, not
json anyway.
2024-08-12 18:10:45 -07:00
Alex Myers
1cb478d2c7 reckless-rpc: catch failed json parsing of reckless output 2024-08-12 18:10:45 -07:00
Alex Myers
2567a116b1 reckless-rpc: catch old installed version
If the rpc plugin is run while an older version of reckless is found on
PATH, it produces an error:

2024-08-01T18:32:00.849Z DEBUG   plugin-recklessrpc: reckless-stderr:usage: reckless [-h] [-d RECKLESS_DIR] [-l LIGHTNING] [-c CONF] [-r] [--network NETWORK] [-v]
{install,uninstall,search,enable,disable,source,help} ...
reckless: error: unrecognized arguments: --json

Catch this and don't try to parse the output as json.
2024-08-12 18:10:45 -07:00
Alex Myers
f93ec36f8a reckless-rpc: accept and pass generic subcommands
This allows generic subcommands to be passed to reckless-rpc along with
the target to search/install/etc..  These commands are unvalidated so
far and may crash the reckless process.

Changelog-Added: reckless-rpc plugin: issue commands to reckless over rpc.
2024-08-12 18:10:45 -07:00
Alex Myers
9eb5359eb0 reckless-rpc: auto-accept reckless config creation dialog
This would interupt most commands during the config reading
step until the user accepts the prompt to create a new empty
config.
2024-08-12 18:10:45 -07:00
Alex Myers
1d9ff8b022 reckless-rpc: read lightningdir and network from listconfigs 2024-08-12 18:10:45 -07:00
Alex Myers
f69c4d6385 reckless-rpc: initial boilerplate
Trying a single command first - reckless-search to test
launching a reckless process and processing the result.
2024-08-12 18:10:45 -07:00
Lagrang3
5073942eef askrene: memleak: scan reserved htable
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-13 09:12:40 +09:30
Lagrang3
cf3375c701 askrene: change reserve_hash for reserve_htable
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-13 09:12:40 +09:30
Lagrang3
3f32f9ea10 renepay: fix strange gossmap_refresh log
Often I find this in the logs:
DEBUG   plugin-cln-renepay: gossmap ignored 94692259263600 channel updates

Apparently gossmap_refresh does not initialize the input variable num_channel_updates_rejected.
Fix this by explicitely initializing it before calling gossmap_refresh.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
5e4eb7bdc3 renepay: fix double free of tal object
routefail object allocation was linked to route,
we had a crash of the plugin with the following error:

0x561f424fc07a send_backtrace
	common/daemon.c:33
0x561f424fc102 crashdump
	common/daemon.c:75
0x7f5b0e7dc04f ???
	???:0
0x7f5b0e82ae2c ???
	???:0
0x7f5b0e7dbfb1 ???
	???:0
0x7f5b0e7c6471 ???
	???:0
0x561f4252581f call_error
	ccan/ccan/tal/tal.c:95
0x561f425258c8 check_bounds
	ccan/ccan/tal/tal.c:169
0x561f425258f9 to_tal_hdr
	ccan/ccan/tal/tal.c:179
0x561f42526283 tal_free
	ccan/ccan/tal/tal.c:525
0x561f424e5379 routefail_end
	plugins/renepay/routefail.c:52
0x561f424e557b handle_failure
	plugins/renepay/routefail.c:431

apparently there was a race condition for which the route was first
freed before we arrived to routefail_end where we manually free
routefail. I don't see how this could have happened, but anyways
this subtle bug can be avoided by linking the routefail to the payment.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
c4d0447773 renepay: remove __PRETTY_FUNCTION__
Remove __PRETTY_FUNCTION__ in favor of __func__

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
cc9b8b0a19 renepay: bugfix finalized routes
Changelog-Fixed: renepay: finalized routes have to be processed and
determine the payment status even after the payment goes into the
background (no current command active). Not doing so leads to finalized
routes getting stuck in the payment internal data structure and their
associated HTLCs in the uncertainty network don't get released.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
04bf0ae29d renepay: remove unnecessary payment list
We rather have a payment hash table to look up payments based on the
payment hash than having a list.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
6a1776d312 renepay: rm HTLCs from uncertainty on route free
Add remove_htlc in the route destructor.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
d6667e305b renepay: review routetracking
Add missing uncertainty update after payment success.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
ccb70de4eb renepay: minor fix
Use success_data_from_listsendpays to check if there are "complete"
sendpays instead of imposing the presence of "complete" sendpays as a
precondition for success_data_from_listsendpays.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
0c685f541e renepay: rethink the computed routes storage
Simply move the "computed routes" array from the payment to the
routetracker. It makes sense to put all temporary stages of routing into
a single data structure: the routetracker.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
1052945ac0 renepay: remove unnecessary rpc calls
There were some dummy rpc calls to waitblockheight in the payment workflow
to allow the function stack to clear. But it is better if some steps in
the payment are executed "atomically" to avoid strange race conditions.
For example: all steps between getting pending sendpays, computing new
routes and sending those routes.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
a339e553e8 renepay: listsendpay before computing routes
It feels unsafe to rely on the internal state of the plugin's database
to tell how many pending sendpays there are for the current payment.
The safest way is to assume lightningd knows and thus use listsendpay
before computing routes.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
ec431276ac renepay: global record of computed routes
Use a single global map of computed routes instead of one for each
payment.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
8b2d45e52e renepay: simpler routetracker
- remove payment pointer from routetracker, fetch payment if necessary
  from payment_hash;
- "have results" condition as a function call to routetracker.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
f16363b86d renepay: small tweak to decay time
The time of decay "TIMER_FORGET_SEC" was set to 1 hour,
which is very low, it would make the plugin try depleted channels after
just a couple of seconds for very small amounts.
I set it to 1 week ~ 6e5 seconds.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:17:21 -07:00
Lagrang3
5ef5739e27 askrene: reserve: fix assertion
Fixes bad guide for json_scan.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:17:09 -07:00
michael1011
d32433a553 bkpr: add payment_id parameter to listaccountevents to filter events.
When you have *lots* of events in your bkpr database looking up a
specific event via calling bkpr-listaccountevents and using jq or
grep to filter gets very slow (and wasteful of CPU and disk resources).
This commit adds the paremeter payment_id to the call to filter for a
specific payment id via a where clause in the request to the database of bkpr.

Changelog-Added: Plugins: Add payment_id parameter to bkpr-listaccountevents to filter events.
2024-08-12 10:22:55 -07:00
michael1011
406d6a6e22 bkpr: minor clarification in comment. 2024-08-12 10:22:55 -07:00
Rusty Russell
a243f3c79c plugin/pay: fix crash if failcodename isn't set.
Fixes: https://github.com/ElementsProject/lightning/issues/7200
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-12 18:36:11 +09:30
Rusty Russell
d0c0c4480a plugins: fix more uninitialized vars in bookkeeper.
Did a sweep to find any others, give this from sanitizer:

```
2024-08-09T18:06:45.1729472Z plugins/bkpr/recorder.c:2057:23: runtime error: load of value 190, which is not a valid value for type 'bool'
2024-08-09T18:06:45.1729877Z SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior plugins/bkpr/recorder.c:2057:23 in
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-10 12:21:39 +09:30