From 42e038b9ad876a945a6a4eb5584ef8bd1b0b7c27 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Thu, 22 Dec 2022 18:52:55 -0500 Subject: [PATCH] lightningd: Look for channels by alias when finding channels When a channel is not yet confirmed onchain and only has an alias, `getroute` will return the alias under the "channel" key. However, if you supply that to `sendpay`, it will not be able to find the channel and will fail since it calls `find_channel_for_htlc_add` and that only looks for channels by their scid and doesn't consider their alias. This patch makes `find_channel_for_htlc_add` also consider channel aliases when looking for channels. Changelog-Fixed: JSON-RPC: `sendpay` now can send to a short-channel-id alias for the first hop. --- lightningd/pay.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lightningd/pay.c b/lightningd/pay.c index 5e44ec11e..75cdbcc42 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -834,19 +834,23 @@ static struct command_result *check_invoice_request_usage(struct command *cmd, static struct channel *find_channel_for_htlc_add(struct lightningd *ld, const struct node_id *node, - const struct short_channel_id *scid) + const struct short_channel_id *scid_or_alias) { struct channel *channel; struct peer *peer = peer_by_id(ld, node); if (!peer) return NULL; - channel = find_channel_by_scid(peer, scid); + channel = find_channel_by_scid(peer, scid_or_alias); + if (channel && channel_can_add_htlc(channel)) + return channel; + + channel = find_channel_by_alias(peer, scid_or_alias, LOCAL); if (channel && channel_can_add_htlc(channel)) return channel; /* We used to ignore scid: now all-zero means "any" */ - if (!channel && (deprecated_apis || memeqzero(scid, sizeof(*scid)))) { + if (!channel && (deprecated_apis || memeqzero(scid_or_alias, sizeof(*scid_or_alias)))) { list_for_each(&peer->channels, channel, list) { if (channel_can_add_htlc(channel)) { return channel;