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

Function get_constraints

plugins/askrene/child/route_query.c:19–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19void get_constraints(const struct route_query *rq,
20 const struct gossmap_chan *chan,
21 int dir,
22 struct amount_msat *min,
23 struct amount_msat *max)
24{
25 struct short_channel_id_dir scidd;
26 size_t idx = gossmap_chan_idx(rq->gossmap, chan);
27
28 *min = AMOUNT_MSAT(0);
29
30 /* Fast path: no information known, no reserve. */
31 if (idx < tal_count(rq->capacities) && rq->capacities[idx] != 0) {
32 *max = amount_msat(fp16_to_u64(rq->capacities[idx]) * 1000);
33 return;
34 }
35
36 /* Naive implementation! */
37 scidd.scid = gossmap_chan_scid(rq->gossmap, chan);
38 scidd.dir = dir;
39 *max = AMOUNT_MSAT(-1ULL);
40
41 /* Look through layers for any constraints (might be dummy
42 * ones, for created channels!) */
43 for (size_t i = 0; i < tal_count(rq->layers); i++)
44 layer_apply_constraints(rq->layers[i], &scidd, min, max);
45
46 /* Might be here because it's reserved, but capacity is normal. */
47 if (amount_msat_eq(*max, AMOUNT_MSAT(-1ULL)))
48 *max = gossmap_chan_get_capacity(rq->gossmap, chan);
49
50 /* Finally, if any is in use, subtract that! */
51 reserve_sub(rq->reserved, &scidd, rq->layers, min);
52 reserve_sub(rq->reserved, &scidd, rq->layers, max);
53}

Callers 8

flow_max_deliverableFunction · 0.85
remove_bottleneckFunction · 0.85
explain_failureFunction · 0.85
linearize_channelFunction · 0.85
edge_probabilityFunction · 0.85
fmt_flow_fullFunction · 0.85

Calls 8

gossmap_chan_idxFunction · 0.85
fp16_to_u64Function · 0.85
gossmap_chan_scidFunction · 0.85
layer_apply_constraintsFunction · 0.85
reserve_subFunction · 0.85
amount_msatClass · 0.70
amount_msat_eqFunction · 0.50

Tested by

no test coverage detected