-
Notifications
You must be signed in to change notification settings - Fork 961
xpay reserve clash #8685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xpay reserve clash #8685
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,12 +147,21 @@ static struct command_result *parse_reserve_hop(struct command *cmd, | |
| struct reserve_hop *rhop) | ||
| { | ||
| const char *err; | ||
| const char *layername = NULL; | ||
|
|
||
| err = json_scan(tmpctx, buffer, tok, "{short_channel_id_dir:%,amount_msat:%}", | ||
| err = json_scan(tmpctx, buffer, tok, "{short_channel_id_dir:%,amount_msat:%,layer?:%}", | ||
| JSON_SCAN(json_to_short_channel_id_dir, &rhop->scidd), | ||
| JSON_SCAN(json_to_msat, &rhop->amount)); | ||
| JSON_SCAN(json_to_msat, &rhop->amount), | ||
| JSON_SCAN_TAL(tmpctx, json_strdup, &layername)); | ||
| if (err) | ||
| return command_fail_badparam(cmd, name, buffer, tok, err); | ||
| if (layername) { | ||
| rhop->layer = find_layer(get_askrene(cmd->plugin), layername); | ||
| if (!rhop->layer) | ||
| return command_fail_badparam(cmd, name, buffer, tok, "Unknown layer"); | ||
| } else | ||
| rhop->layer = NULL; | ||
|
|
||
| return NULL; | ||
| } | ||
|
|
||
|
|
@@ -548,8 +557,8 @@ void get_constraints(const struct route_query *rq, | |
| *max = gossmap_chan_get_capacity(rq->gossmap, chan); | ||
|
|
||
| /* Finally, if any is in use, subtract that! */ | ||
| reserve_sub(rq->reserved, &scidd, min); | ||
| reserve_sub(rq->reserved, &scidd, max); | ||
| reserve_sub(rq->reserved, &scidd, rq->layers, min); | ||
| reserve_sub(rq->reserved, &scidd, rq->layers, max); | ||
| } | ||
|
|
||
| static struct command_result *do_getroutes(struct command *cmd, | ||
|
|
@@ -916,9 +925,11 @@ static struct command_result *json_askrene_unreserve(struct command *cmd, | |
| for (size_t i = 0; i < tal_count(path); i++) { | ||
| if (!reserve_remove(askrene->reserved, &path[i])) { | ||
| return command_fail(cmd, JSONRPC2_INVALID_PARAMS, | ||
| "Unknown reservation for %s", | ||
| "Unknown reservation for %s%s%s", | ||
| fmt_short_channel_id_dir(tmpctx, | ||
| &path[i].scidd)); | ||
| &path[i].scidd), | ||
| path[i].layer ? " on layer " : "", | ||
| path[i].layer ? layer_name(path[i].layer) : ""); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -933,14 +944,15 @@ static struct command_result *json_askrene_listreservations(struct command *cmd, | |
| struct askrene *askrene = get_askrene(cmd->plugin); | ||
| struct json_stream *response; | ||
|
|
||
| /* FIXME: We could allow layer names here? */ | ||
| if (!param(cmd, buffer, params, | ||
| NULL)) | ||
| return command_param_failed(); | ||
| plugin_log(cmd->plugin, LOG_TRACE, "%s called: %.*s", __func__, | ||
| json_tok_full_len(params), json_tok_full(buffer, params)); | ||
|
|
||
| response = jsonrpc_stream_success(cmd); | ||
| json_add_reservations(response, askrene->reserved, "reservations"); | ||
| json_add_reservations(response, askrene->reserved, "reservations", NULL); | ||
| return command_finished(cmd, response); | ||
| } | ||
|
|
||
|
|
@@ -1065,7 +1077,7 @@ static struct command_result *json_askrene_inform_channel(struct command *cmd, | |
| case INFORM_CONSTRAINED: | ||
| /* It didn't pass, so minimal assumption is that reserve was all used | ||
| * then there we were one msat short. */ | ||
| if (!reserve_accumulate(askrene->reserved, scidd, amount)) | ||
| if (!reserve_accumulate(askrene->reserved, scidd, layer, amount)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be documented in I create a reservation of 5 in layer1 and a reservation of 7 in layer2 for the same channel.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My opinion on this is that we add an extra argument For example:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've documented this, and that we only want to put the reservation in the layer when it's not in the gossmap. We are using them to fake up namespaces, which is pretty gross. This is not a generic mechanism for per-layer reservations. Just a disambiguation one for fake channels, which are not unique. The right answer to this whole mess is to ensure scids are unique, but that's hard to do properly. We would need to rework things to have askrene assign them. I'm not sure it's worth it (especially since we're closing on rc1). |
||
| return command_fail(cmd, JSONRPC2_INVALID_PARAMS, | ||
| "Amount overflow with reserves"); | ||
| if (!amount_msat_deduct(amount, AMOUNT_MSAT(1))) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, why not?
The only question is: if I specify a list of layers here, would I want to get a list of reservations
in which some of them are global or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that
get_constraintsand thusgetroutesfetch the reservations belonging to the request layersplus the global reservations. I guess the answer should include the global as well.
But on the other hand it is weird to call
listreservationsspecifying some layer and getting globalreservations mixed up in the reply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, indeed. One reason I didn't implement it, since I can't tell how it would be used.