Initialize the data vectors for the single-path solver. */
| 1143 | |
| 1144 | /* Initialize the data vectors for the single-path solver. */ |
| 1145 | static void init_linear_network_single_path( |
| 1146 | const tal_t *ctx, const struct pay_parameters *params, struct graph **graph, |
| 1147 | double **arc_prob_cost, double **arc_fee_cost, double **arc_delay_cost, |
| 1148 | s64 **arc_capacity) |
| 1149 | { |
| 1150 | const size_t max_num_chans = gossmap_max_chan_idx(params->rq->gossmap); |
| 1151 | const size_t max_num_arcs = max_num_chans * ARCS_PER_CHANNEL; |
| 1152 | const size_t max_num_nodes = gossmap_max_node_idx(params->rq->gossmap); |
| 1153 | |
| 1154 | *graph = graph_new(ctx, max_num_nodes, max_num_arcs, ARC_DUAL_BITOFF); |
| 1155 | *arc_prob_cost = tal_arr(ctx, double, max_num_arcs); |
| 1156 | for (size_t i = 0; i < max_num_arcs; ++i) |
| 1157 | (*arc_prob_cost)[i] = DBL_MAX; |
| 1158 | |
| 1159 | *arc_fee_cost = tal_arr(ctx, double, max_num_arcs); |
| 1160 | for (size_t i = 0; i < max_num_arcs; ++i) |
| 1161 | (*arc_fee_cost)[i] = DBL_MAX; |
| 1162 | |
| 1163 | *arc_delay_cost = tal_arr(ctx, double, max_num_arcs); |
| 1164 | for (size_t i = 0; i < max_num_arcs; ++i) |
| 1165 | (*arc_delay_cost)[i] = DBL_MAX; |
| 1166 | *arc_capacity = tal_arrz(ctx, s64, max_num_arcs); |
| 1167 | |
| 1168 | const struct gossmap *gossmap = params->rq->gossmap; |
| 1169 | |
| 1170 | for (struct gossmap_node *node = gossmap_first_node(gossmap); node; |
| 1171 | node = gossmap_next_node(gossmap, node)) { |
| 1172 | const u32 node_id = gossmap_node_idx(gossmap, node); |
| 1173 | |
| 1174 | for (size_t j = 0; j < node->num_chans; ++j) { |
| 1175 | int half; |
| 1176 | const struct gossmap_chan *c = |
| 1177 | gossmap_nth_chan(gossmap, node, j, &half); |
| 1178 | struct amount_msat mincap, maxcap; |
| 1179 | |
| 1180 | if (!channel_is_available(params->rq, c, half)) |
| 1181 | continue; |
| 1182 | |
| 1183 | /* If a channel cannot forward the total amount we don't |
| 1184 | * use it. */ |
| 1185 | if (amount_msat_less(params->amount, |
| 1186 | gossmap_chan_htlc_min(c, half)) || |
| 1187 | amount_msat_greater(params->amount, |
| 1188 | gossmap_chan_htlc_max(c, half))) |
| 1189 | continue; |
| 1190 | |
| 1191 | get_constraints(params->rq, c, half, &mincap, &maxcap); |
| 1192 | /* Assume if min > max, min is wrong */ |
| 1193 | if (amount_msat_greater(mincap, maxcap)) |
| 1194 | mincap = maxcap; |
| 1195 | /* It is preferable to work on 1msat past the known |
| 1196 | * bound. */ |
| 1197 | if (!amount_msat_accumulate(&maxcap, amount_msat(1))) |
| 1198 | abort(); |
| 1199 | |
| 1200 | /* If amount is greater than the known liquidity upper |
| 1201 | * bound we get infinite probability cost. */ |
| 1202 | if (amount_msat_greater_eq(params->amount, maxcap)) |
no test coverage detected