Stolen whole-cloth from @Lagrang3 in renepay's flow.c. Wrong * because of htlc overhead in reservations! */
| 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) |
| 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 | |
| 71 | struct amount_msat flow_spend(const struct flow *flow) |
| 72 | { |
no test coverage detected