MCPcopy Create free account
hub / github.com/ElementsProject/lightning / edge_probability

Function edge_probability

plugins/askrene/child/flow.c:37–69  ·  view source on GitHub ↗

Stolen whole-cloth from @Lagrang3 in renepay's flow.c. Wrong * because of htlc overhead in reservations! */

Source from the content-addressed store, hash-verified

35/* Stolen whole-cloth from @Lagrang3 in renepay's flow.c. Wrong
36 * because of htlc overhead in reservations! */
37static double edge_probability(const struct route_query *rq,
38 const struct short_channel_id_dir *scidd,
39 struct amount_msat sent)
40{
41 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);
44
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();
53
54 if (amount_msat_less_eq(sent, mincap))
55 return 1.0;
56 else if (amount_msat_greater(sent, maxcap))
57 return 0.0;
58
59 /* Linear probability: 1 - (spend - min) / (max - min) */
60
61 /* spend > mincap, from above. */
62 if (!amount_msat_sub(&numerator, sent, mincap))
63 abort();
64 /* This can only fail is maxcap was < mincap,
65 * so we would be captured above */
66 if (!amount_msat_sub(&denominator, maxcap, mincap))
67 abort();
68 return 1.0 - amount_msat_ratio(numerator, denominator);
69}
70
71struct amount_msat flow_spend(const struct flow *flow)
72{

Callers 1

flow_probabilityFunction · 0.70

Calls 9

gossmap_find_chanFunction · 0.85
get_constraintsFunction · 0.85
amount_msat_accumulateFunction · 0.85
abortFunction · 0.85
amount_msat_less_eqFunction · 0.85
amount_msat_greaterFunction · 0.85
amount_msat_subFunction · 0.85
amount_msat_ratioFunction · 0.85

Tested by

no test coverage detected