MCPcopy Create free account
hub / github.com/ElementsProject/lightning / init_linear_network

Function init_linear_network

plugins/askrene/child/mcf.c:531–626  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

529}
530
531static void init_linear_network(const tal_t *ctx,
532 const struct pay_parameters *params,
533 struct graph **graph, double **arc_prob_cost,
534 s64 **arc_fee_cost, s64 **arc_capacity)
535{
536 const struct gossmap *gossmap = params->rq->gossmap;
537 const size_t max_num_chans = gossmap_max_chan_idx(gossmap);
538 const size_t max_num_arcs = max_num_chans * ARCS_PER_CHANNEL;
539 const size_t max_num_nodes = gossmap_max_node_idx(gossmap);
540
541 *graph = graph_new(ctx, max_num_nodes, max_num_arcs, ARC_DUAL_BITOFF);
542 *arc_prob_cost = tal_arr(ctx, double, max_num_arcs);
543 for (size_t i = 0; i < max_num_arcs; ++i)
544 (*arc_prob_cost)[i] = DBL_MAX;
545
546 *arc_fee_cost = tal_arr(ctx, s64, max_num_arcs);
547 for (size_t i = 0; i < max_num_arcs; ++i)
548 (*arc_fee_cost)[i] = INT64_MAX;
549
550 *arc_capacity = tal_arrz(ctx, s64, max_num_arcs);
551
552 for(struct gossmap_node *node = gossmap_first_node(gossmap);
553 node;
554 node=gossmap_next_node(gossmap,node))
555 {
556 const u32 node_id = gossmap_node_idx(gossmap,node);
557
558 for(size_t j=0;j<node->num_chans;++j)
559 {
560 int half;
561 const struct gossmap_chan *c = gossmap_nth_chan(gossmap,
562 node, j, &half);
563
564 if (!channel_is_available(params->rq, c, half))
565 continue;
566
567 /* If a channel insists on more than our total, remove it */
568 if (amount_msat_less(params->amount, gossmap_chan_htlc_min(c, half)))
569 continue;
570
571 const u32 chan_id = gossmap_chan_idx(gossmap, c);
572
573 const struct gossmap_node *next = gossmap_nth_node(gossmap,
574 c,!half);
575
576 const u32 next_id = gossmap_node_idx(gossmap,next);
577
578 if(node_id==next_id)
579 continue;
580
581 // `cost` is the word normally used to denote cost per
582 // unit of flow in the context of MCF.
583 double prob_cost[CHANNEL_PARTS];
584 s64 capacity[CHANNEL_PARTS];
585
586 // split this channel direction to obtain the arcs
587 // that are outgoing to `node`
588 linearize_channel(params, c, half, capacity, prob_cost);

Callers 1

minflowFunction · 0.70

Calls 15

gossmap_max_chan_idxFunction · 0.85
gossmap_max_node_idxFunction · 0.85
graph_newFunction · 0.85
gossmap_first_nodeFunction · 0.85
gossmap_next_nodeFunction · 0.85
gossmap_node_idxFunction · 0.85
gossmap_nth_chanFunction · 0.85
gossmap_chan_htlc_minFunction · 0.85
gossmap_chan_idxFunction · 0.85
gossmap_nth_nodeFunction · 0.85
graph_add_arcFunction · 0.85
node_objFunction · 0.85

Tested by

no test coverage detected