@@ -365,9 +365,13 @@ static void linearize_channel(const struct pay_parameters *params,
365365 b = 1 + amount_msat_ratio_floor (maxcap , params -> accuracy );
366366
367367 /* An extra bound on capacity, here we use it to reduce the flow such
368- * that it does not exceed htlcmax. */
368+ * that it does not exceed htlcmax.
369+ * Also there is no need to keep track of more capacity than the payment
370+ * amount, this can help us prune some arcs. */
369371 u64 cap_on_capacity =
370- amount_msat_ratio_floor (gossmap_chan_htlc_max (c , dir ), params -> accuracy );
372+ MIN (amount_msat_ratio_floor (gossmap_chan_htlc_max (c , dir ),
373+ params -> accuracy ),
374+ amount_msat_ratio_ceil (params -> amount , params -> accuracy ));
371375
372376 set_capacity (& capacity [0 ], a , & cap_on_capacity );
373377 cost [0 ]= 0 ;
@@ -603,8 +607,9 @@ static void init_linear_network(const tal_t *ctx,
603607 // when the `i` hits the `next` node.
604608 for (size_t k = 0 ;k < CHANNEL_PARTS ;++ k )
605609 {
606- /* FIXME: Can we prune arcs with 0 capacity?
607- * if(capacity[k]==0)continue; */
610+ /* prune arcs with 0 capacity */
611+ if (capacity [k ] == 0 )
612+ continue ;
608613
609614 struct arc arc = arc_from_parts (chan_id , half , k , false);
610615
@@ -964,10 +969,14 @@ struct flow **minflow(const tal_t *ctx,
964969 params -> source = source ;
965970 params -> target = target ;
966971 params -> amount = amount ;
967- params -> accuracy = AMOUNT_MSAT (1000 );
968- /* FIXME: params->accuracy = amount_msat_max(amount_msat_div(amount,
969- * 1000), AMOUNT_MSAT(1));
972+ /* -> At most 1M units of flow are allowed, that reduces the
973+ * computational burden for algorithms that depend on it, eg. "capacity
974+ * scaling" and "successive shortest path".
975+ * -> Using Ceil operation instead of Floor so that
976+ * accuracy x 1M >= amount
970977 * */
978+ params -> accuracy = amount_msat_max (
979+ AMOUNT_MSAT (1 ), amount_msat_div_ceil (amount , 1000000 ));
971980
972981 // template the channel partition into linear arcs
973982 params -> cap_fraction [0 ]= 0 ;
0 commit comments