From e036080fc5ffc655047646082ec77fe92dba5a44 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 26 Jun 2023 08:37:21 +0930 Subject: [PATCH] common: simple helpers to test for either anchor feature. Signed-off-by: Rusty Russell --- common/channel_type.c | 6 ++++++ common/channel_type.h | 3 +++ common/initial_channel.c | 5 +++++ common/initial_channel.h | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/common/channel_type.c b/common/channel_type.c index 80a9138f7..ba4126388 100644 --- a/common/channel_type.c +++ b/common/channel_type.c @@ -97,6 +97,12 @@ bool channel_type_has(const struct channel_type *type, int feature) return feature_offered(type->features, feature); } +bool channel_type_has_anchors(const struct channel_type *type) +{ + return feature_offered(type->features, OPT_ANCHOR_OUTPUTS) + || feature_offered(type->features, OPT_ANCHORS_ZERO_FEE_HTLC_TX); +} + bool channel_type_eq(const struct channel_type *a, const struct channel_type *b) { diff --git a/common/channel_type.h b/common/channel_type.h index 28096f3c2..14f5bfa4b 100644 --- a/common/channel_type.h +++ b/common/channel_type.h @@ -30,6 +30,9 @@ struct channel_type *default_channel_type(const tal_t *ctx, /* Does this type include this feature? */ bool channel_type_has(const struct channel_type *type, int feature); +/* Convenience for querying either anchor_outputs or anchors_zero_fee_htlc_tx */ +bool channel_type_has_anchors(const struct channel_type *type); + /* Are these two channel_types equivalent? */ bool channel_type_eq(const struct channel_type *a, const struct channel_type *b); diff --git a/common/initial_channel.c b/common/initial_channel.c index cae1ad140..46728b017 100644 --- a/common/initial_channel.c +++ b/common/initial_channel.c @@ -182,6 +182,11 @@ bool channel_has(const struct channel *channel, int feature) return channel_type_has(channel->type, feature); } +bool channel_has_anchors(const struct channel *channel) +{ + return channel_type_has_anchors(channel->type); +} + static char *fmt_channel_view(const tal_t *ctx, const struct channel_view *view) { return tal_fmt(ctx, "{ owed_local=%s," diff --git a/common/initial_channel.h b/common/initial_channel.h index 713d55f5f..0ec7cf3ae 100644 --- a/common/initial_channel.h +++ b/common/initial_channel.h @@ -159,4 +159,8 @@ struct channel_type *channel_desired_type(const tal_t *ctx, /* Convenience for querying channel->type */ bool channel_has(const struct channel *channel, int feature); + +/* Convenience for querying either anchor_outputs or anchors_zero_fee_htlc_tx */ +bool channel_has_anchors(const struct channel *channel); + #endif /* LIGHTNING_COMMON_INITIAL_CHANNEL_H */