From 92b891bee3759c206e27057d3558ebb08062c852 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 6 May 2022 15:38:34 +0200 Subject: [PATCH] ld: Add function to retrieve either the scid or the local alias We use this in a couple of places, when we want to refer to a channel by its `short_channel_id`, I'm moving this into a separate function primarily to have a way to mark places where we do that. --- lightningd/channel.c | 10 ++++++++++ lightningd/channel.h | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/lightningd/channel.c b/lightningd/channel.c index 123ca84a5..e0bffb768 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -956,3 +956,13 @@ void channel_fail_reconnect(struct channel *channel, const char *fmt, ...) err_and_reconnect(channel, tal_vfmt(tmpctx, fmt, ap), 1); va_end(ap); } + +const struct short_channel_id * +channel_scid_or_local_alias(const struct channel *chan) +{ + assert(chan->scid != NULL || chan->alias[LOCAL] != NULL); + if (chan->scid != NULL) + return chan->scid; + else + return chan->alias[LOCAL]; +} diff --git a/lightningd/channel.h b/lightningd/channel.h index aabbcf1ff..afd72e4a7 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -476,6 +476,16 @@ static inline bool channel_has(const struct channel *channel, int f) return channel_type_has(channel->type, f); } +/** + * Either returns the short_channel_id if it is known or the local alias. + * + * This is used to refer to a channel by its scid. But sometimes we + * don't have a scid yet, e.g., for `zeroconf` channels, so we resort + * to referencing it by the local alias, which we have in that case. + */ +const struct short_channel_id * +channel_scid_or_local_alias(const struct channel *chan); + void get_channel_basepoints(struct lightningd *ld, const struct node_id *peer_id, const u64 dbid,