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

Function flowset_probability

plugins/renepay/flow.c:243–351  ·  view source on GitHub ↗

@ctx: allocator * @flows: flows for which the probability is computed * @gossmap: gossip * @chan_extra_map: knowledge * @compute_fees: compute fees along the way or not * @fail: if a failure occurs, returns a message to the caller * */ TODO(eduardo): here chan_extra_map should be const TODO(eduardo): here flows should be const

Source from the content-addressed store, hash-verified

241// TODO(eduardo): here chan_extra_map should be const
242// TODO(eduardo): here flows should be const
243double flowset_probability(const tal_t *ctx, struct flow **flows,
244 const struct gossmap *const gossmap,
245 struct chan_extra_map *chan_extra_map,
246 bool compute_fees,
247 char **fail)
248{
249 assert(flows);
250 assert(gossmap);
251 assert(chan_extra_map);
252 tal_t *this_ctx = tal(ctx, tal_t);
253 double prob = 1.0;
254
255 // TODO(eduardo): should it be better to use a map instead of an array
256 // here?
257 const size_t max_num_chans = gossmap_max_chan_idx(gossmap);
258 struct chan_inflight_flow *in_flight =
259 tal_arr(this_ctx, struct chan_inflight_flow, max_num_chans);
260
261 if (!in_flight) {
262 if (fail)
263 *fail = tal_fmt(ctx, "failed to allocate memory");
264 goto function_fail;
265 }
266
267 for (size_t i = 0; i < max_num_chans; ++i) {
268 in_flight[i].half[0] = in_flight[i].half[1] = AMOUNT_MSAT(0);
269 }
270
271 for (size_t i = 0; i < tal_count(flows); ++i) {
272 const struct flow *f = flows[i];
273 const size_t pathlen = tal_count(f->path);
274 struct amount_msat *amounts =
275 tal_flow_amounts(this_ctx, f, compute_fees);
276 if (!amounts)
277 {
278 if (fail)
279 *fail = tal_fmt(
280 ctx,
281 "failed to compute amounts along the path");
282 goto function_fail;
283 }
284
285 for (size_t j = 0; j < pathlen; ++j) {
286 const struct chan_extra_half *h =
287 get_chan_extra_half_by_chan(gossmap, chan_extra_map,
288 f->path[j], f->dirs[j]);
289 if (!h) {
290 if (fail)
291 *fail = tal_fmt(
292 ctx,
293 "channel not found in chan_extra_map");
294 goto function_fail;
295 }
296 const u32 c_idx = gossmap_chan_idx(gossmap, f->path[j]);
297 const int c_dir = f->dirs[j];
298
299 const struct amount_msat deliver = amounts[j];
300

Callers 3

minflowFunction · 0.85
print_flowsFunction · 0.85
print_flowsFunction · 0.85

Calls 9

gossmap_max_chan_idxFunction · 0.85
tal_flow_amountsFunction · 0.85
gossmap_chan_idxFunction · 0.85
amount_msat_addFunction · 0.85
amount_msat_less_eqFunction · 0.85
tal_freeFunction · 0.85
edge_probabilityFunction · 0.70
fmt_amount_msatFunction · 0.50

Tested by 2

print_flowsFunction · 0.68
print_flowsFunction · 0.68