| 17 | } |
| 18 | |
| 19 | void 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 | } |
no test coverage detected