Skip to content

Commit

Permalink
lightningd: Look for channels by alias when finding channels
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dongcarl committed Dec 22, 2022
1 parent b3a1d01 commit f61cf34
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f61cf34

Please sign in to comment.