@@ -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