Skip to content

Commit 767893d

Browse files
Lagrang3rustyrussell
authored andcommitted
askrene: rework the caller of the MCF solver
We use a wrapper around the MCF solver that takes care of finding the best linearization parameters and fixing the flow values to meet the htlc_min and htlc_max constraints. We have reworked the current implementation and made it a bit more similar to renepay's version. Out of 50000 simulated payment situations distributed accross payment amounts of 1e2, 1e3, 1e4, 1e5 and 1e6 sats, we find that 133 failed cases in the master branch turn to success with the current changes, while only 3 success cases in the master are not solved by the changes. master +-------+------+ | S | F | +---+-------+------+ | S | 46329 | 133 | changes +---+-------+------+ | F | 3 | 3535 | +---+-------+------+ Out of the 133 cases that flipped from failure to success the failed reasons were: 122 -> "Could not find route without excessive cost" 5 -> "We couldn't quite afford it" 5 -> "Amount *msat below minimum" 1 -> tripped an HTLC min check Changelog-None. Signed-off-by: Lagrang3 <[email protected]>
1 parent d64f438 commit 767893d

File tree

3 files changed

+225
-143
lines changed

3 files changed

+225
-143
lines changed

plugins/askrene/flow.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,24 @@ struct amount_msat flowset_delivers(struct plugin *plugin,
3232
return final;
3333
}
3434

35-
static double edge_probability(struct amount_msat sent,
36-
struct amount_msat mincap,
37-
struct amount_msat maxcap,
38-
struct amount_msat used)
35+
/* Stolen whole-cloth from @Lagrang3 in renepay's flow.c. Wrong
36+
* because of htlc overhead in reservations! */
37+
static double edge_probability(const struct route_query *rq,
38+
const struct short_channel_id_dir *scidd,
39+
struct amount_msat sent)
3940
{
4041
struct amount_msat numerator, denominator;
42+
struct amount_msat mincap, maxcap, additional;
43+
const struct gossmap_chan *c = gossmap_find_chan(rq->gossmap, &scidd->scid);
4144

42-
if (!amount_msat_sub(&mincap, mincap, used))
43-
mincap = AMOUNT_MSAT(0);
44-
if (!amount_msat_sub(&maxcap, maxcap, used))
45-
maxcap = AMOUNT_MSAT(0);
45+
get_constraints(rq, c, scidd->dir, &mincap, &maxcap);
46+
47+
/* We add an extra per-htlc reservation for the *next* HTLC, so we "over-reserve"
48+
* on local channels. Undo that! */
49+
additional = get_additional_per_htlc_cost(rq, scidd);
50+
if (!amount_msat_accumulate(&mincap, additional)
51+
|| !amount_msat_accumulate(&maxcap, additional))
52+
abort();
4653

4754
if (amount_msat_less_eq(sent, mincap))
4855
return 1.0;
@@ -129,10 +136,11 @@ double flow_probability(const struct flow *flow,
129136

130137
for (int i = (int)pathlen - 1; i >= 0; i--) {
131138
const struct half_chan *h = flow_edge(flow, i);
132-
struct amount_msat mincap, maxcap;
139+
struct short_channel_id_dir scidd;
140+
scidd.scid = gossmap_chan_scid(rq->gossmap, flow->path[i]);
141+
scidd.dir = flow->dirs[i];
133142

134-
get_constraints(rq, flow->path[i], flow->dirs[i], &mincap, &maxcap);
135-
prob *= edge_probability(spend, mincap, maxcap, AMOUNT_MSAT(0));
143+
prob *= edge_probability(rq, &scidd, spend);
136144

137145
if (!amount_msat_add_fee(&spend, h->base_fee,
138146
h->proportional_fee)) {

0 commit comments

Comments
 (0)