@@ -235,16 +235,25 @@ static int revcmp_flows(const size_t *a, const size_t *b, struct flow **flows)
235235// -> check that htlc_max are all satisfied
236236// -> check that (x+1) at least one htlc_max is violated
237237/* Given the channel constraints, return the maximum amount that can be
238- * delivered. */
239- static struct amount_msat path_max_deliverable (struct channel_data * path )
238+ * delivered. Sets *bottleneck_idx to one of the contraining channels' idx, if non-NULL */
239+ static struct amount_msat path_max_deliverable (struct channel_data * path ,
240+ u32 * bottleneck_idx )
240241{
241242 struct amount_msat deliver = AMOUNT_MSAT (-1 );
242243 for (size_t i = 0 ; i < tal_count (path ); i ++ ) {
243244 deliver =
244245 amount_msat_sub_fee (deliver , path [i ].fee_base_msat ,
245246 path [i ].fee_proportional_millionths );
246- deliver = amount_msat_min (deliver , path [i ].htlc_max );
247- deliver = amount_msat_min (deliver , path [i ].liquidity_max );
247+ if (amount_msat_greater (deliver , path [i ].htlc_max )) {
248+ if (bottleneck_idx )
249+ * bottleneck_idx = path [i ].idx ;
250+ deliver = path [i ].htlc_max ;
251+ }
252+ if (amount_msat_greater (deliver , path [i ].liquidity_max )) {
253+ if (bottleneck_idx )
254+ * bottleneck_idx = path [i ].idx ;
255+ deliver = path [i ].liquidity_max ;
256+ }
248257 }
249258 return deliver ;
250259}
@@ -477,9 +486,9 @@ static void write_selected_flows(const tal_t *ctx, size_t *flows_index,
477486 tal_free (tmp_flows );
478487}
479488
480- /* FIXME: on failure return error message */
481489const char * refine_flows (const tal_t * ctx , struct route_query * rq ,
482- struct amount_msat deliver , struct flow * * * flows )
490+ struct amount_msat deliver , struct flow * * * flows ,
491+ u32 * bottleneck_idx )
483492{
484493 const tal_t * working_ctx = tal (ctx , tal_t );
485494 const char * error_message = NULL ;
@@ -499,7 +508,7 @@ const char *refine_flows(const tal_t *ctx, struct route_query *rq,
499508 for (size_t i = 0 ; i < tal_count (channel_mpp_cache ); i ++ ) {
500509 // FIXME: does path_max_deliverable work for a single
501510 // channel with 0 fees?
502- max_deliverable [i ] = path_max_deliverable (channel_mpp_cache [i ]);
511+ max_deliverable [i ] = path_max_deliverable (channel_mpp_cache [i ], bottleneck_idx );
503512 min_deliverable [i ] = path_min_deliverable (channel_mpp_cache [i ]);
504513 /* We use an array of indexes to keep track of the order
505514 * of the flows. Likewise flows can be removed by simply
@@ -578,7 +587,7 @@ void squash_flows(const tal_t *ctx, struct route_query *rq,
578587 struct short_channel_id_dir scidd ;
579588 flows_index [i ] = i ;
580589 paths_str [i ] = tal_strdup (working_ctx , "" );
581- max_deliverable [i ] = path_max_deliverable (channel_mpp_cache [i ]);
590+ max_deliverable [i ] = path_max_deliverable (channel_mpp_cache [i ], NULL );
582591
583592 for (size_t j = 0 ; j < tal_count (flow -> path ); j ++ ) {
584593 scidd .scid =
0 commit comments