From 7930e34da32036fc7e372e61f6c6b861b3392905 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 4 May 2022 15:52:43 +0200 Subject: [PATCH] pay: Populate the channel hints with either the scid or the alias We'll use one of the two, and we reuse the `scid` field, since we don't really care that much which one it is. --- plugins/libplugin-pay.c | 20 ++++++++++++++++---- plugins/libplugin-pay.h | 5 +++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 9411de286..e27305fa9 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -2293,7 +2293,7 @@ local_channel_hints_listpeers(struct command *cmd, const char *buffer, const jsmntok_t *toks, struct payment *p) { const jsmntok_t *peers, *peer, *channels, *channel, *spendsats, *scid, - *dir, *connected, *max_htlc, *htlcs, *state; + *dir, *connected, *max_htlc, *htlcs, *state, *alias, *alias_local; size_t i, j; peers = json_get_member(buffer, toks, "peers"); @@ -2311,12 +2311,20 @@ local_channel_hints_listpeers(struct command *cmd, const char *buffer, struct channel_hint h; spendsats = json_get_member(buffer, channel, "spendable_msat"); scid = json_get_member(buffer, channel, "short_channel_id"); + + alias = json_get_member(buffer, channel, "alias"); + if (alias != NULL) + alias_local = json_get_member(buffer, alias, "local"); + else + alias_local = NULL; + dir = json_get_member(buffer, channel, "direction"); max_htlc = json_get_member(buffer, channel, "max_accepted_htlcs"); htlcs = json_get_member(buffer, channel, "htlcs"); state = json_get_member(buffer, channel, "state"); - if (spendsats == NULL || scid == NULL || dir == NULL || - max_htlc == NULL || state == NULL || + if (spendsats == NULL || + (scid == NULL && alias_local == NULL) || + dir == NULL || max_htlc == NULL || state == NULL || max_htlc->type != JSMN_PRIMITIVE || htlcs == NULL || htlcs->type != JSMN_ARRAY) continue; @@ -2327,7 +2335,11 @@ local_channel_hints_listpeers(struct command *cmd, const char *buffer, json_to_bool(buffer, connected, &h.enabled); h.enabled &= json_tok_streq(buffer, state, "CHANNELD_NORMAL"); - json_to_short_channel_id(buffer, scid, &h.scid.scid); + if (scid != NULL) + json_to_short_channel_id(buffer, scid, &h.scid.scid); + else + json_to_short_channel_id(buffer, alias_local, &h.scid.scid); + json_to_int(buffer, dir, &h.scid.dir); json_to_msat(buffer, spendsats, &h.estimated_capacity); diff --git a/plugins/libplugin-pay.h b/plugins/libplugin-pay.h index eb125acef..8ec8ec07a 100644 --- a/plugins/libplugin-pay.h +++ b/plugins/libplugin-pay.h @@ -60,6 +60,11 @@ struct payment_result { * get remove on failure. Success keeps the capacities, since the capacities * changed due to the successful HTLCs. */ struct channel_hint { + /* The short_channel_id we're going to use when referring to + * this channel. This can either be the real scid, or the + * local alias. The `pay` algorithm doesn't really care which + * one it is, but we'll prefer the scid as that's likely more + * readable than the alias. */ struct short_channel_id_dir scid; /* Upper bound on remove channels inferred from payment failures. */