From 0ce68b26c63b0e15fcbfcc22724ca43e46e8c046 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 4 May 2022 15:51:11 +0200 Subject: [PATCH] jsonrpc: Include the direction also if we have an alias The direction only depends on the ordering between node_ids, not the short_channel_id, so we can include it and it won't change. This was causing some trouble loading the `channel_hints` in the `pay` plugin. --- lightningd/peer_control.c | 9 +++++++-- plugins/libplugin.c | 13 +++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 6109ed895..284dc78bb 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -653,12 +653,17 @@ static void json_add_channel(struct lightningd *ld, if (channel->owner) json_add_string(response, "owner", channel->owner->name); - if (channel->scid) { + if (channel->scid) json_add_short_channel_id(response, "short_channel_id", channel->scid); + + /* If there is any way we can use the channel we'd better have + * a direction attached. Technically we could always add it, + * as it's just the lexicographic order between node_ids, but + * why bother if we can't use it? */ + if (channel->scid || channel->alias[LOCAL] || channel->alias[REMOTE]) json_add_num(response, "direction", node_id_idx(&ld->id, &channel->peer->id)); - } json_add_string(response, "channel_id", type_to_string(tmpctx, struct channel_id, &channel->cid)); diff --git a/plugins/libplugin.c b/plugins/libplugin.c index 577c45ee3..394ec0f4c 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -1603,14 +1603,19 @@ static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx, if (scidtok != NULL) { assert(dirtok != NULL); chan->scid = tal(chan, struct short_channel_id); - chan->direction = tal(chan, int); json_to_short_channel_id(buffer, scidtok, chan->scid); - json_to_int(buffer, dirtok, chan->direction); - }else { - assert(dirtok == NULL); + } else { chan->scid = NULL; chan->direction = NULL; } + + if (dirtok != NULL) { + chan->direction = tal(chan, int); + json_to_int(buffer, dirtok, chan->direction); + } else { + chan->direction = NULL; + } + if (aliastok != NULL) { const jsmntok_t *loctok = json_get_member(buffer, aliastok, "local"),