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.
This commit is contained in:
Christian Decker 2022-05-04 15:52:43 +02:00
parent 0ce68b26c6
commit 7930e34da3
2 changed files with 21 additions and 4 deletions

View file

@ -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);

View file

@ -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. */