Skip to content

Commit 7afce23

Browse files
committed
askrene: add optional layers to reservations.
We have the issue of aliases: xpay uses scids like 0x0x0 for routehints and blinded paths, and then can apply reservations to them. But generally, reservations are *global*, so we need to differentiate. Changelog-Added: Plugins: `askrene-reserve` and `askrene-unreserve` can take an optional `layer` inside `path` elements. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent b368a3e commit 7afce23

File tree

14 files changed

+258
-152
lines changed

14 files changed

+258
-152
lines changed

.msggen.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@
762762
"Askrene-reservePath": {
763763
"AskRene-Reserve.path[].amount_msat": 3,
764764
"AskRene-Reserve.path[].direction": 2,
765+
"AskRene-Reserve.path[].layer": 5,
765766
"AskRene-Reserve.path[].short_channel_id": 1,
766767
"AskRene-Reserve.path[].short_channel_id_dir": 4
767768
},
@@ -771,6 +772,7 @@
771772
"Askrene-unreservePath": {
772773
"AskRene-Unreserve.path[].amount_msat": 3,
773774
"AskRene-Unreserve.path[].direction": 2,
775+
"AskRene-Unreserve.path[].layer": 5,
774776
"AskRene-Unreserve.path[].short_channel_id": 1,
775777
"AskRene-Unreserve.path[].short_channel_id_dir": 4
776778
},
@@ -4469,6 +4471,10 @@
44694471
"added": "v24.08",
44704472
"deprecated": null
44714473
},
4474+
"AskRene-Reserve.path[].layer": {
4475+
"added": "v25.12",
4476+
"deprecated": null
4477+
},
44724478
"AskRene-Reserve.path[].short_channel_id": {
44734479
"added": "v24.08",
44744480
"deprecated": null
@@ -4493,6 +4499,10 @@
44934499
"added": "v24.08",
44944500
"deprecated": null
44954501
},
4502+
"AskRene-Unreserve.path[].layer": {
4503+
"added": "v25.12",
4504+
"deprecated": null
4505+
},
44964506
"AskRene-Unreserve.path[].short_channel_id": {
44974507
"added": "v24.08",
44984508
"deprecated": null

cln-grpc/proto/node.proto

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-grpc/src/convert.rs

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-rpc/src/model.rs

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/msggen/msggen/schema.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,13 @@
15531553
"description": [
15541554
"The amount to send into this hop."
15551555
]
1556+
},
1557+
"layer": {
1558+
"added": "v25.12",
1559+
"type": "string",
1560+
"description": [
1561+
"The layer to restrict this reservation to (useful for fake channels)."
1562+
]
15561563
}
15571564
}
15581565
}
@@ -1654,6 +1661,13 @@
16541661
"description": [
16551662
"The amount to send into this hop."
16561663
]
1664+
},
1665+
"layer": {
1666+
"added": "v25.12",
1667+
"type": "string",
1668+
"description": [
1669+
"The layer to restrict this reservation to (useful for fake channels)."
1670+
]
16571671
}
16581672
}
16591673
}

contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Lines changed: 135 additions & 135 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/schemas/askrene-reserve.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
"description": [
3737
"The amount to send into this hop."
3838
]
39+
},
40+
"layer": {
41+
"added": "v25.12",
42+
"type": "string",
43+
"description": [
44+
"The layer to restrict this reservation to (useful for fake channels)."
45+
]
3946
}
4047
}
4148
}

doc/schemas/askrene-unreserve.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
"description": [
3737
"The amount to send into this hop."
3838
]
39+
},
40+
"layer": {
41+
"added": "v25.12",
42+
"type": "string",
43+
"description": [
44+
"The layer to restrict this reservation to (useful for fake channels)."
45+
]
3946
}
4047
}
4148
}

plugins/askrene/askrene.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,21 @@ static struct command_result *parse_reserve_hop(struct command *cmd,
118118
struct reserve_hop *rhop)
119119
{
120120
const char *err;
121+
const char *layername = NULL;
121122

122-
err = json_scan(tmpctx, buffer, tok, "{short_channel_id_dir:%,amount_msat:%}",
123+
err = json_scan(tmpctx, buffer, tok, "{short_channel_id_dir:%,amount_msat:%,layer?:%}",
123124
JSON_SCAN(json_to_short_channel_id_dir, &rhop->scidd),
124-
JSON_SCAN(json_to_msat, &rhop->amount));
125+
JSON_SCAN(json_to_msat, &rhop->amount),
126+
JSON_SCAN_TAL(tmpctx, json_strdup, &layername));
125127
if (err)
126128
return command_fail_badparam(cmd, name, buffer, tok, err);
129+
if (layername) {
130+
rhop->layer = find_layer(get_askrene(cmd->plugin), layername);
131+
if (!rhop->layer)
132+
return command_fail_badparam(cmd, name, buffer, tok, "Unknown layer");
133+
} else
134+
rhop->layer = NULL;
135+
127136
return NULL;
128137
}
129138

@@ -519,8 +528,8 @@ void get_constraints(const struct route_query *rq,
519528
*max = gossmap_chan_get_capacity(rq->gossmap, chan);
520529

521530
/* Finally, if any is in use, subtract that! */
522-
reserve_sub(rq->reserved, &scidd, min);
523-
reserve_sub(rq->reserved, &scidd, max);
531+
reserve_sub(rq->reserved, &scidd, rq->layers, min);
532+
reserve_sub(rq->reserved, &scidd, rq->layers, max);
524533
}
525534

526535
static struct command_result *do_getroutes(struct command *cmd,
@@ -876,9 +885,11 @@ static struct command_result *json_askrene_unreserve(struct command *cmd,
876885
for (size_t i = 0; i < tal_count(path); i++) {
877886
if (!reserve_remove(askrene->reserved, &path[i])) {
878887
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
879-
"Unknown reservation for %s",
888+
"Unknown reservation for %s%s%s",
880889
fmt_short_channel_id_dir(tmpctx,
881-
&path[i].scidd));
890+
&path[i].scidd),
891+
path[i].layer ? " on layer " : "",
892+
path[i].layer ? layer_name(path[i].layer) : "");
882893
}
883894
}
884895

@@ -893,14 +904,15 @@ static struct command_result *json_askrene_listreservations(struct command *cmd,
893904
struct askrene *askrene = get_askrene(cmd->plugin);
894905
struct json_stream *response;
895906

907+
/* FIXME: We could allow layer names here? */
896908
if (!param(cmd, buffer, params,
897909
NULL))
898910
return command_param_failed();
899911
plugin_log(cmd->plugin, LOG_TRACE, "%s called: %.*s", __func__,
900912
json_tok_full_len(params), json_tok_full(buffer, params));
901913

902914
response = jsonrpc_stream_success(cmd);
903-
json_add_reservations(response, askrene->reserved, "reservations");
915+
json_add_reservations(response, askrene->reserved, "reservations", NULL);
904916
return command_finished(cmd, response);
905917
}
906918

@@ -1025,7 +1037,7 @@ static struct command_result *json_askrene_inform_channel(struct command *cmd,
10251037
case INFORM_CONSTRAINED:
10261038
/* It didn't pass, so minimal assumption is that reserve was all used
10271039
* then there we were one msat short. */
1028-
if (!reserve_accumulate(askrene->reserved, scidd, amount))
1040+
if (!reserve_accumulate(askrene->reserved, scidd, layer, amount))
10291041
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
10301042
"Amount overflow with reserves");
10311043
if (!amount_msat_sub(amount, *amount, AMOUNT_MSAT(1)))

plugins/askrene/explain_failure.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static const char *why_max_constrained(const tal_t *ctx,
6060
fmt_amount_msat(tmpctx, max));
6161
}
6262

63-
reservations = fmt_reservations(tmpctx, rq->reserved, scidd);
63+
reservations = fmt_reservations(tmpctx, rq->reserved, scidd, rq->layers);
6464
if (reservations) {
6565
if (!ret)
6666
ret = tal_strdup(ctx, "");

0 commit comments

Comments
 (0)