@@ -360,9 +360,13 @@ static void linearize_channel(const struct pay_parameters *params,
360360 b = 1 + amount_msat_ratio_floor (maxcap , params -> accuracy );
361361
362362 /* An extra bound on capacity, here we use it to reduce the flow such
363- * that it does not exceed htlcmax. */
363+ * that it does not exceed htlcmax.
364+ * Also there is no need to keep track of more capacity than the payment
365+ * amount, this can help us prune some arcs. */
364366 u64 cap_on_capacity =
365- amount_msat_ratio_floor (gossmap_chan_htlc_max (c , dir ), params -> accuracy );
367+ MIN (amount_msat_ratio_floor (gossmap_chan_htlc_max (c , dir ),
368+ params -> accuracy ),
369+ amount_msat_ratio_ceil (params -> amount , params -> accuracy ));
366370
367371 set_capacity (& capacity [0 ], a , & cap_on_capacity );
368372 cost [0 ]= 0 ;
@@ -598,8 +602,9 @@ static void init_linear_network(const tal_t *ctx,
598602 // when the `i` hits the `next` node.
599603 for (size_t k = 0 ;k < CHANNEL_PARTS ;++ k )
600604 {
601- /* FIXME: Can we prune arcs with 0 capacity?
602- * if(capacity[k]==0)continue; */
605+ /* prune arcs with 0 capacity */
606+ if (capacity [k ] == 0 )
607+ continue ;
603608
604609 struct arc arc = arc_from_parts (chan_id , half , k , false);
605610
@@ -960,10 +965,14 @@ struct flow **minflow(const tal_t *ctx,
960965 params -> source = source ;
961966 params -> target = target ;
962967 params -> amount = amount ;
963- params -> accuracy = AMOUNT_MSAT (1000 );
964- /* FIXME: params->accuracy = amount_msat_max(amount_msat_div(amount,
965- * 1000), AMOUNT_MSAT(1));
968+ /* -> At most 1M units of flow are allowed, that reduces the
969+ * computational burden for algorithms that depend on it, eg. "capacity
970+ * scaling" and "successive shortest path".
971+ * -> Using Ceil operation instead of Floor so that
972+ * accuracy x 1M >= amount
966973 * */
974+ params -> accuracy = amount_msat_max (
975+ AMOUNT_MSAT (1 ), amount_msat_div_ceil (amount , 1000000 ));
967976
968977 // template the channel partition into linear arcs
969978 params -> cap_fraction [0 ]= 0 ;
0 commit comments