@@ -32,17 +32,24 @@ struct amount_msat flowset_delivers(struct plugin *plugin,
32
32
return final ;
33
33
}
34
34
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 )
39
40
{
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 );
41
44
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 ();
46
53
47
54
if (amount_msat_less_eq (sent , mincap ))
48
55
return 1.0 ;
@@ -129,10 +136,11 @@ double flow_probability(const struct flow *flow,
129
136
130
137
for (int i = (int )pathlen - 1 ; i >= 0 ; i -- ) {
131
138
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 ];
133
142
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 );
136
144
137
145
if (!amount_msat_add_fee (& spend , h -> base_fee ,
138
146
h -> proportional_fee )) {
0 commit comments