Commit graph

174 commits

Author SHA1 Message Date
Rusty Russell
757e6f8a9b libplugin: allow display of default values.
This means we can see the values in listconfigs, even if we haven't set
them yet.

In particular, we now see the following:

* autoclean-cycle.value_int=3600
* bitcoin-rpcclienttimeout.value_int=60
* bitcoin-retry-timeout.value_int=60
* funder-max-their-funding.value_str=4294967295sat
* funder-per-channel-min.value_str=10000sat
* funder-reserve-tank.value_str=0sat
* funder-fund-probability.value_int=100

Changelog-Changed: plugins: libplugin now shows plugin option default values (where they're non-trivial)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-05-15 15:50:54 -05:00
Rusty Russell
cb2c4963f2 bolt12: allow first_node_id in blinded path to be a scid.
We don't actually support it yet, but this threads through the type change,
puts it in "decode" etc.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-05-12 19:11:43 -05:00
Rusty Russell
cca784c9d0 BOLT: update to include 2016 for max_htlc_cltv.
And deprecate the --max-locktime-blocks which allows them to set it.

Hilariously, the spec misspells CLTV as CTLV at one point, so we work around it for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-05-09 16:14:23 -05:00
Lagrang3
7335777595 renepay: fix some memory leaks 2024-05-08 22:32:13 -05:00
Lagrang3
7b18056b09 renepay: fix sources 2024-05-08 22:32:13 -05:00
Lagrang3
985a01b41d renepay: wake-up result collector every 50msec 2024-05-08 22:32:13 -05:00
Lagrang3
014e32ca2f renepay: a bit more verbose information in logs 2024-05-08 22:32:13 -05:00
Lagrang3
e97e6ede41 renepay: update test files 2024-05-08 22:32:13 -05:00
Lagrang3
16d00e09ef renepay: bug fix, local channel information
Listpeerchannels would update the local channel information setting the
liquidity in the outgoing channel to known_min=known_max=capacity,
when in fact it should be known_min=known_max=spendable.
2024-05-08 22:32:13 -05:00
Lagrang3
4adf9b4080 renepay: bug fix on the routebuilder
The route-builder checks the liquidity bounds of each route one at a
time. Every route that satisfy the contraints is recorded in the
uncertainty network and produces an HTLC burden on the channels it uses,
so that the following routes cannot count on the same liquidity twice.
2024-05-08 22:32:13 -05:00
Lagrang3
da00cae30b renepay: remove payment from route
Routes contain only routing information and the payment they're linked
to can be obtained through the payment_hash. We remove the dependency of
route building routines from the payment itself. In order to make
plain payment information available we define a payment_info structure.
2024-05-08 22:32:13 -05:00
Lagrang3
ca2b4e54ae renepay: add disabledmap abstraction
Define a new object called disabledmap that carries information about
the disabled channels and nodes.
2024-05-08 22:32:13 -05:00
Lagrang3
96bd0e455b renepay: refactor routefail
- use switch case over all possible WIRE_* errors,
- remove the virtual machine for routefail, use a simple two step
  solution: 1. update the gossip and 2. handle error cases
2024-05-08 22:32:13 -05:00
Lagrang3
cafc08be1d renepay: disable channels not in chan_extra_map
Expand the disabled set to include channels that are not present in the
chan_extra_map/uncertainty network.
2024-05-08 22:32:13 -05:00
Lagrang3
d2c44fc3df renepay: add a test for routehints 2024-05-08 22:32:13 -05:00
Lagrang3
761c295199 renepay: uncertainty network update revisited
- Update the uncertainty network with the gossmap+local_gossmods,
- ignore channels that fail to give their capacity.
2024-05-08 22:32:13 -05:00
Lagrang3
9f13621de9 renepay: pay selfpayments on spot
Resolve a selfpayment right from the result of `sendpay` instead of
waiting for the notification.
2024-05-08 22:32:13 -05:00
Lagrang3
fa199e21d2 renepay: minor fixes 2024-05-08 22:32:13 -05:00
Lagrang3
0e2660733f renepay: update unit tests 2024-05-08 22:32:13 -05:00
Lagrang3
1ee157f02b renepay: update the Makefile 2024-05-08 22:32:13 -05:00
Lagrang3
cc00d509b1 renepay: add a helper module json.c 2024-05-08 22:32:13 -05:00
Lagrang3
73c6142965 renepay: add error codes
Using enum renepay_errorcode simplifies the low level API of chan_extra and flow.
We can extract information about the nature of a function call failure
from its return value.
2024-05-08 22:32:13 -05:00
Lagrang3
7584629696 renepay: add routefail.c
Routefail consist mainly of an API `routefail_start` that handles the
failure of a forwarding request (encoded in a route). Internally there
is a routefail datastructure that goes through a series of execution
steps, eg. updating the gossmap, updating the uncertainty network, etc.
2024-05-08 22:32:13 -05:00
Lagrang3
480dec58f2 renepay: add routetracker.c
Routetracker is a structure that is used to follow the progress of the
route forwarding requests.
2024-05-08 22:32:13 -05:00
Lagrang3
84651fa4ba renepay: add routebuilder.c
Routebuilder constitute the module that builds the routes we try in the
payment. The public API is simply `get_routes`, it replaces the similar
interface for pay_flows.
2024-05-08 22:32:13 -05:00
Lagrang3
6766acbcdf renepay: payment state machine (mods)
Add a new implementation of the payment state machine.
This is based in the `pay` plugin concept of payment modifiers,
but here we take it to the next level.
The payment goes through a virtual machine that includes calling
functions and evaluating conditions.
2024-05-08 22:32:13 -05:00
Lagrang3
4b9fe23293 renepay: the plugin executable is main.c
- move the plugin executable from pay.c to main.c,
- adapt the plugin main program to handle concurrent pay calls,
2024-05-08 22:32:13 -05:00
Lagrang3
190649585f renepay: THE plugin global structure
The plugin global structure is now defined in payplugin.h
2024-05-08 22:32:13 -05:00
Lagrang3
7ffb722b27 renepay: refactor uncertainty API
The uncertainty structure is updated based on the result of a route,
previously chan_extra and pay_flow were used instead.
2024-05-08 22:32:13 -05:00
Lagrang3
2a4a23a362 renepay: rename uncertainty_network for uncertanty 2024-05-08 22:32:13 -05:00
Lagrang3
4c91bc0ef0 renepay: abandon pay_flow for route
The role of the structure pay_flow is not taken by a new structure
called route.
2024-05-08 22:32:13 -05:00
Lagrang3
ba54d678bc renepay: concurrent pay calls
Refactor the payment structure to handle multiple pay requests for the
same or different invoices.
2024-05-08 22:32:13 -05:00
Lagrang3
3cbbaa7ab5 renepay: separate flow and chan_extra
Flow and chan_extra are two different concepts, we keep their
definitions and APIs separate.
2024-05-08 22:32:13 -05:00
Rusty Russell
e3c4bdf209 renepay: fix gcc -O3 overzealous warning.
gcc-12 (Ubuntu 12.3.0-9ubuntu2) 12.3.0 with -O3 gives:

```
In file included from plugins/renepay/test/../mcf.c:5,
                 from plugins/renepay/test/run-arc.c:13:
ccan/ccan/tal/str/str.h: In function ‘minflow’:
ccan/ccan/tal/str/str.h:43:9: error: ‘errmsg’ may be used uninitialized [-Werror=maybe-uninitialized]
   43 |         tal_fmt_(ctx, TAL_LABEL(char, "[]"), __VA_ARGS__)
      |         ^~~~~~~~
plugins/renepay/test/../mcf.c:1565:15: note: ‘errmsg’ was declared here
 1565 |         char *errmsg;
      |               ^~~~~~
cc1: all warnings being treated as errors
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-05-06 20:51:19 -05:00
Lagrang3
bb31856b80 remove is_local variable from listpeerchannels cb
is_local, ie. "is this side of the channel ours?" is not needed since we
can determine that predicate by evaluating
`scidd->dir == node_id_idx(self, peer)`
2024-04-03 10:07:13 +10:30
Lagrang3
22a70339de renepay: limit arc capacities by htlc_max
In the Min. Cost Flow solver we put a constraint on arcs capacities,
such that the total flow that can be allocated through a channel does
not exceed htlc_max. This solves two previous problem of the htlc_max
constraint at the MCF level.
2024-04-03 10:07:13 +10:30
Lagrang3
56ac5eebef add more fields to gossmods_listpeerchannels
Add spendable/receivable and is_local fields to the callback function
used in gossmods_from_listpeerchannels. This allows to do more fine
grained use of the listpeerchannels call.
The first use case is renepay, for which we need to ignore the htlc_max
of the local channels only.
2024-04-03 10:07:13 +10:30
Rusty Russell
9450d46db1 bitcoin/short_channel_id: pass by copy everywhere.
It's a u64, we should pass by copy.  This is a big sweeping change,
but mainly mechanical (change one, compile, fix breakage, repeat).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 13:51:48 +10:30
Rusty Russell
e0e879c003 common: remove type_to_string files altogther.
This means including <common/utils.h> where it was indirectly included.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 13:51:48 +10:30
Rusty Russell
37d22f9141 global: change all type_to_string to fmt_X.
This has the benefit of being shorter, as well as more reliable (you
will get a link error if we can't print it, not a runtime one!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 13:51:48 +10:30
Rusty Russell
be546fc60e Makefiles: remove leftover references to $(EXP)
This was also removed a while ago, it's never set.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 13:51:48 +10:30
Rusty Russell
ac40fdf414 Makefiles: remove dependency on wire/onion_wiregen.o where unnecessary.
Also, WIRE_ONION_OBJS hasn't existed for a while.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 13:51:48 +10:30
Lagrang3
6ca5128ab0 renepay: bugfix situation with htlcmax=htlcmin
In some weird situations it may happen that some channel along the route
could have htlcmax=htlcmin, so that the supremum of htlcmin and the
infimum of htlcmax are the same number. In that case there is only one
allowed amount that can go through that route.
Without this patch renepay would not handle correctly this cornercase.
2024-03-08 10:15:38 +01:00
Lagrang3
b51acf6a31 renepay: refuse to pay BOLT12 invoice
We have not yet worked on supporting BOLT12 invoices,
we better refuse to pay them until we do.
2024-03-07 14:09:29 +01:00
Rusty Russell
e50539d852 pay: ignore fees on our own channels when determining routing.
I noticed that run-route-infloop chose some worse-looking paths after
routing was fixed, eg the second node:

Before:
	Destination node, success, probability, hops, fees, cltv, scid...
	02b3aa1e4ed31be83cca4bd367b2c01e39502cb25e282a9b4520ad376a1ba0a01a,1,0.991856,2,1004,40,2572260x39x0/1,2131897x45x0/0

After:
	Destination node, success, probability, hops, fees, cltv, scid...
	02b3aa1e4ed31be83cca4bd367b2c01e39502cb25e282a9b4520ad376a1ba0a01a,1,0.954540,3,1046,46,2570715x21x0/1,2346882x26x14/1,2131897x45x0/0

This is because although the final costs don't reflect it, routing was taking
into account local channels, and 2572260x39x0/1 has a base fee of 2970.

There's an easy fix: when we the pay plugin creates localmods for our
gossip graph, add all local channels with delay and fees equal to 0.
We do the same thing in our unit test.  This improves things across
the board:

Linear success probability (when found): min-max(mean +/- stddev)
	Before: 0.487040-0.999543(0.952548+/-0.075)
	After:  0.486985-0.999750(0.975978+/-0.053)

Hops:
	Before: 1-5(2.98374+/-0.77)
	After:  1-5(2.09593+/-0.63)

Fees:
	Before: 0-50848(922.457+/-2.7e+03)
	After:  0-50041(861.621+/-2.7e+03)

Delay (blocks):
	Before: 0-196(65.8081+/-60)
	After:  0-190(60.3285+/-60)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Plugins: `pay` route algorithm doesn't bias against our own "expensive" channels any more.
2024-03-07 14:09:14 +01:00
Lagrang3
c916066f85 renepay: update the gossmap after addgossip
Whenever there is a payment failure that requires gossip update, for
example changing the fee rates of remote channels, we call addgossip.
For renepay to consider this changes in the coming payment attempts, it
must update gossmap.
2024-02-16 14:51:14 +01:00
Lagrang3
7e0d6d396e renepay bug fix: list previous sendpays
- previous pending sendpays must add up so that the plugin tries to pay
the rest of the amount,
- avoid groupid, partid collisions,
- add shadow fees if the option is set and the payment amount - total
  delivering = 0
- add a test,
- also fix a buggy shadow routing test
2024-02-16 14:51:14 +01:00
Lagrang3
59935c535c fixed source (using raw millisatohis) 2024-02-02 11:28:47 +01:00
Lagrang3
997d5aa970 renepay: flow routes limited by htlc_max/min
The flow routes returned by minflow are bounded by the htlc_min and
    htlc_max along the route whenever possible.
2024-02-02 11:28:47 +01:00
Lagrang3
b0054aad46 renepay: accomodate fees in the payment flow
Min. Cost Flow does not take into account fees when computing a flow
    with liquidity constraints.
    This is a work-around solution that reduces the amount on every route to
    respect the liquidity bound. The deficity in the delivered amount is
    solved by running MCF once again.

    Changes:

    1. the function `flow_complete` allocates amounts to send over the set of routes
       computed by the MCF algorithm, but it does not allocate more than liquidity
       bound of the route. For this reason `minflow` returns a set of routes that
       satisfy the liquidity bounds but it is not guaranteed that the total payment
       reaches the destination therefore there could a deficit in the delivery:
       `deficit = amount_to_deliver - delivering`.

    2. in the function `add_payflows` after `minflow` returns a set of routes we
       call `flows_fit_amount` that tries to a allocate the `deficit` in the routes
       that the MCF have computed.

    3. if the resulting flows pass all payment constraints then we update
        `amount_to_deliver = amount_to_deliver - delivering`, and the loop
        repeats as long as `amount_to_deliver` is not zero.

    In other words, the excess amount, beyond the liquidity bound,
    in the routes is removed and then we try to allocate it
    into known routes, otherwise we do a whole MCF again just for the
    remaining amount.

    Fixes issue #6599
2024-01-29 10:48:24 +10:30