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.
This commit is contained in:
Carl Dong 2022-12-22 18:52:55 -05:00 committed by Rusty Russell
parent 9d5eab1b69
commit 42e038b9ad

View file

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