This mirrors get_constraints() */
| 33 | |
| 34 | /* This mirrors get_constraints() */ |
| 35 | static const char *why_max_constrained(const tal_t *ctx, |
| 36 | const struct route_query *rq, |
| 37 | struct short_channel_id_dir *scidd, |
| 38 | struct amount_msat amount) |
| 39 | { |
| 40 | char *ret = NULL; |
| 41 | const char *reservations; |
| 42 | const struct layer *constrains = NULL; |
| 43 | struct amount_msat max = amount; |
| 44 | |
| 45 | /* Figure out the layer that constrains us (most) */ |
| 46 | for (size_t i = 0; i < tal_count(rq->layers); i++) { |
| 47 | struct amount_msat min = AMOUNT_MSAT(0), new_max = max; |
| 48 | |
| 49 | layer_apply_constraints(rq->layers[i], scidd, &min, &new_max); |
| 50 | if (!amount_msat_eq(new_max, max)) |
| 51 | constrains = rq->layers[i]; |
| 52 | max = new_max; |
| 53 | } |
| 54 | |
| 55 | if (constrains) { |
| 56 | if (!ret) |
| 57 | ret = tal_strdup(ctx, ""); |
| 58 | else |
| 59 | tal_append_fmt(&ret, ", "); |
| 60 | tal_append_fmt(&ret, "layer %s says max is %s", |
| 61 | layer_name(constrains), |
| 62 | fmt_amount_msat(tmpctx, max)); |
| 63 | } |
| 64 | |
| 65 | reservations = fmt_reservations(tmpctx, rq->reserved, scidd, rq->layers); |
| 66 | if (reservations) { |
| 67 | if (!ret) |
| 68 | ret = tal_strdup(ctx, ""); |
| 69 | else |
| 70 | tal_append_fmt(&ret, " and "); |
| 71 | tal_append_fmt(&ret, "already reserved %s", reservations); |
| 72 | } |
| 73 | |
| 74 | /* This seems unlikely, but don't return NULL. */ |
| 75 | if (!ret) |
| 76 | ret = tal_fmt(ctx, "is constrained"); |
| 77 | return ret; |
| 78 | } |
| 79 | |
| 80 | struct stat { |
| 81 | size_t num_channels; |
no test coverage detected