From e2777642c03c37052f141c1f2858cf83f4d2cebd Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 15 Jan 2019 20:34:07 +1030 Subject: [PATCH] getroute: add direction to route returned. We also ignore it in sendpay. Signed-off-by: Rusty Russell --- gossipd/routing.c | 1 + gossipd/routing.h | 1 + lightningd/gossip_msg.c | 3 +++ lightningd/json.c | 1 + lightningd/pay.c | 5 ++++- 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gossipd/routing.c b/gossipd/routing.c index 3d3d0b0dd..c1384b963 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -1561,6 +1561,7 @@ struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate, hops[i].nodeid = n->id; hops[i].amount = total_amount; hops[i].delay = total_delay; + hops[i].direction = idx; total_amount += connection_fee(c, total_amount); total_delay += c->delay; n = other_node(n, route[i]); diff --git a/gossipd/routing.h b/gossipd/routing.h index 1cb9ee237..73c2fd660 100644 --- a/gossipd/routing.h +++ b/gossipd/routing.h @@ -207,6 +207,7 @@ get_channel(const struct routing_state *rstate, struct route_hop { struct short_channel_id channel_id; + int direction; struct pubkey nodeid; u64 amount; u32 delay; diff --git a/lightningd/gossip_msg.c b/lightningd/gossip_msg.c index 20d84af9b..39155fbea 100644 --- a/lightningd/gossip_msg.c +++ b/lightningd/gossip_msg.c @@ -64,13 +64,16 @@ void fromwire_route_hop(const u8 **pptr, size_t *max, struct route_hop *entry) { fromwire_pubkey(pptr, max, &entry->nodeid); fromwire_short_channel_id(pptr, max, &entry->channel_id); + entry->direction = fromwire_u8(pptr, max); entry->amount = fromwire_u64(pptr, max); entry->delay = fromwire_u32(pptr, max); } + void towire_route_hop(u8 **pptr, const struct route_hop *entry) { towire_pubkey(pptr, &entry->nodeid); towire_short_channel_id(pptr, &entry->channel_id); + towire_u8(pptr, entry->direction); towire_u64(pptr, entry->amount); towire_u32(pptr, entry->delay); } diff --git a/lightningd/json.c b/lightningd/json.c index 88614747e..cee09ff01 100644 --- a/lightningd/json.c +++ b/lightningd/json.c @@ -30,6 +30,7 @@ json_add_route_hop(struct json_stream *r, char const *n, json_add_pubkey(r, "id", &h->nodeid); json_add_short_channel_id(r, "channel", &h->channel_id); + json_add_num(r, "direction", h->direction); json_add_u64(r, "msatoshi", h->amount); json_add_num(r, "delay", h->delay); json_object_end(r); diff --git a/lightningd/pay.c b/lightningd/pay.c index aed9206f6..53e5decec 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -1004,13 +1004,14 @@ static struct command_result *json_sendpay(struct command *cmd, u64 *amount; struct pubkey *id; struct short_channel_id *channel; - unsigned *delay; + unsigned *delay, *direction; if (!param(cmd, buffer, t, p_req("msatoshi", param_u64, &amount), p_req("id", param_pubkey, &id), p_req("delay", param_number, &delay), p_req("channel", param_short_channel_id, &channel), + p_opt("direction", param_number, &direction), NULL)) return command_param_failed(); @@ -1020,6 +1021,8 @@ static struct command_result *json_sendpay(struct command *cmd, route[n_hops].nodeid = *id; route[n_hops].delay = *delay; route[n_hops].channel_id = *channel; + /* FIXME: Actually ignored by sending code! */ + route[n_hops].direction = direction ? *direction : 0; n_hops++; }