From c83834ca82cc5277685f6bcf00a5046d2ee7c00e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 14 Nov 2019 10:48:53 +1030 Subject: [PATCH] lightningd: expose/accept "style" parameter in routes. Default is legacy. If we have future styles, new strings can be defined, but for now it's "tlv" or "legacy". Signed-off-by: Rusty Russell --- doc/lightning-getroute.7 | 5 +++-- doc/lightning-getroute.7.md | 5 +++-- lightningd/gossip_control.c | 16 ++++++++++++++++ lightningd/pay.c | 25 +++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/doc/lightning-getroute.7 b/doc/lightning-getroute.7 index 01b6f6dca..7c245e448 100644 --- a/doc/lightning-getroute.7 +++ b/doc/lightning-getroute.7 @@ -113,8 +113,9 @@ factor for larger amounts, and is basically ignored for tiny ones\. On success, a "route" array is returned\. Each array element contains \fIid\fR (the node being routed through), \fImsatoshi\fR (the millisatoshis -sent), \fIamount_msat\fR (the same, with \fImsat\fR appended), and \fIdelay\fR (the -number of blocks to timeout at this node)\. +sent), \fIamount_msat\fR (the same, with \fImsat\fR appended), \fIdelay\fR (the +number of blocks to timeout at this node), and \fIstyle\fR (indicating +the features which can be used for this hop)\. The final \fIid\fR will be the destination \fIid\fR given in the input\. The diff --git a/doc/lightning-getroute.7.md b/doc/lightning-getroute.7.md index 97a90d987..84b056e99 100644 --- a/doc/lightning-getroute.7.md +++ b/doc/lightning-getroute.7.md @@ -279,8 +279,9 @@ RETURN VALUE On success, a "route" array is returned. Each array element contains *id* (the node being routed through), *msatoshi* (the millisatoshis -sent), *amount\_msat* (the same, with *msat* appended), and *delay* (the -number of blocks to timeout at this node). +sent), *amount\_msat* (the same, with *msat* appended), *delay* (the +number of blocks to timeout at this node), and *style* (indicating +the features which can be used for this hop). The final *id* will be the destination *id* given in the input. The difference between the first *msatoshi* minus the *msatoshi* given in diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 677f007cd..67be0db43 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -303,6 +303,21 @@ static const struct json_command listnodes_command = { }; AUTODATA(json_command, &listnodes_command); +static void json_add_route_hop_style(struct json_stream *response, + const char *fieldname, + enum route_hop_style style) +{ + switch (style) { + case ROUTE_HOP_LEGACY: + json_add_string(response, fieldname, "legacy"); + return; + case ROUTE_HOP_TLV: + json_add_string(response, fieldname, "tlv"); + return; + } + fatal("Unknown route_hop_style %u", style); +} + /* Output a route hop */ static void json_add_route_hop(struct json_stream *r, char const *n, const struct route_hop *h) @@ -315,6 +330,7 @@ static void json_add_route_hop(struct json_stream *r, char const *n, json_add_num(r, "direction", h->direction); json_add_amount_msat_compat(r, h->amount, "msatoshi", "amount_msat"); json_add_num(r, "delay", h->delay); + json_add_route_hop_style(r, "style", h->style); json_object_end(r); } diff --git a/lightningd/pay.c b/lightningd/pay.c index e36cc26fd..9aff1b78d 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -788,6 +788,27 @@ send_payment(struct lightningd *ld, JSON-RPC sendpay interface -----------------------------------------------------------------------------*/ +static struct command_result *param_route_hop_style(struct command *cmd, + const char *name, + const char *buffer, + const jsmntok_t *tok, + enum route_hop_style **style) +{ + *style = tal(cmd, enum route_hop_style); + if (json_tok_streq(buffer, tok, "legacy")) { + **style = ROUTE_HOP_LEGACY; + return NULL; + } else if (json_tok_streq(buffer, tok, "tlv")) { + **style = ROUTE_HOP_TLV; + return NULL; + } + + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "'%s' should be a legacy or tlv, not '%.*s'", + name, json_tok_full_len(tok), + json_tok_full(buffer, tok)); +} + static struct command_result *json_sendpay(struct command *cmd, const char *buffer, const jsmntok_t *obj UNNEEDED, @@ -846,6 +867,7 @@ static struct command_result *json_sendpay(struct command *cmd, struct node_id *id; struct short_channel_id *channel; unsigned *delay, *direction; + enum route_hop_style *style; if (!param(cmd, buffer, t, /* Only *one* of these is required */ @@ -856,6 +878,8 @@ static struct command_result *json_sendpay(struct command *cmd, p_opt("delay", param_number, &delay), p_opt("channel", param_short_channel_id, &channel), p_opt("direction", param_number, &direction), + p_opt_def("style", param_route_hop_style, &style, + ROUTE_HOP_LEGACY), NULL)) return command_param_failed(); @@ -884,6 +908,7 @@ static struct command_result *json_sendpay(struct command *cmd, route[i].nodeid = *id; route[i].delay = *delay; route[i].channel_id = *channel; + route[i].style = *style; /* FIXME: Actually ignored by sending code! */ route[i].direction = direction ? *direction : 0; }