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

Function init_linear_network_single_path

plugins/askrene/child/mcf.c:1058–1145  ·  view source on GitHub ↗

Initialize the data vectors for the single-path solver. */

Source from the content-addressed store, hash-verified

1056
1057/* Initialize the data vectors for the single-path solver. */
1058static void init_linear_network_single_path(
1059 const tal_t *ctx, const struct pay_parameters *params, struct graph **graph,
1060 double **arc_prob_cost, s64 **arc_fee_cost, s64 **arc_capacity)
1061{
1062 const size_t max_num_chans = gossmap_max_chan_idx(params->rq->gossmap);
1063 const size_t max_num_arcs = max_num_chans * ARCS_PER_CHANNEL;
1064 const size_t max_num_nodes = gossmap_max_node_idx(params->rq->gossmap);
1065
1066 *graph = graph_new(ctx, max_num_nodes, max_num_arcs, ARC_DUAL_BITOFF);
1067 *arc_prob_cost = tal_arr(ctx, double, max_num_arcs);
1068 for (size_t i = 0; i < max_num_arcs; ++i)
1069 (*arc_prob_cost)[i] = DBL_MAX;
1070
1071 *arc_fee_cost = tal_arr(ctx, s64, max_num_arcs);
1072 for (size_t i = 0; i < max_num_arcs; ++i)
1073 (*arc_fee_cost)[i] = INT64_MAX;
1074 *arc_capacity = tal_arrz(ctx, s64, max_num_arcs);
1075
1076 const struct gossmap *gossmap = params->rq->gossmap;
1077
1078 for (struct gossmap_node *node = gossmap_first_node(gossmap); node;
1079 node = gossmap_next_node(gossmap, node)) {
1080 const u32 node_id = gossmap_node_idx(gossmap, node);
1081
1082 for (size_t j = 0; j < node->num_chans; ++j) {
1083 int half;
1084 const struct gossmap_chan *c =
1085 gossmap_nth_chan(gossmap, node, j, &half);
1086 struct amount_msat mincap, maxcap;
1087
1088 if (!channel_is_available(params->rq, c, half))
1089 continue;
1090
1091 /* If a channel cannot forward the total amount we don't
1092 * use it. */
1093 if (amount_msat_less(params->amount,
1094 gossmap_chan_htlc_min(c, half)) ||
1095 amount_msat_greater(params->amount,
1096 gossmap_chan_htlc_max(c, half)))
1097 continue;
1098
1099 get_constraints(params->rq, c, half, &mincap, &maxcap);
1100 /* Assume if min > max, min is wrong */
1101 if (amount_msat_greater(mincap, maxcap))
1102 mincap = maxcap;
1103 /* It is preferable to work on 1msat past the known
1104 * bound. */
1105 if (!amount_msat_accumulate(&maxcap, amount_msat(1)))
1106 abort();
1107
1108 /* If amount is greater than the known liquidity upper
1109 * bound we get infinite probability cost. */
1110 if (amount_msat_greater_eq(params->amount, maxcap))
1111 continue;
1112
1113 const u32 chan_id = gossmap_chan_idx(gossmap, c);
1114
1115 const struct gossmap_node *next =

Callers 1

single_path_flowFunction · 0.85

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
amount_msat_greaterFunction · 0.85
gossmap_chan_htlc_maxFunction · 0.85
get_constraintsFunction · 0.85
amount_msat_accumulateFunction · 0.85

Tested by

no test coverage detected