From e4511452aca7f2dd8135a8e3d7dc84dfb17596a1 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 14 Apr 2022 14:35:39 +0200 Subject: [PATCH] bolt: Reflect the zeroconf featurebits in code --- common/features.c | 35 +++++++++++++++++++++++++++++++++-- common/features.h | 10 ++++++++++ lightningd/lightningd.c | 2 ++ tests/test_misc.py | 4 ++++ tests/utils.py | 4 ++-- 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/common/features.c b/common/features.c index bd7db0bfb..14c0a3914 100644 --- a/common/features.c +++ b/common/features.c @@ -89,6 +89,26 @@ static const struct feature_style feature_styles[] = { [NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT, [BOLT11_FEATURE] = FEATURE_REPRESENT, [CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT} }, + /* FIXME: Currently not explicitly signalled, but we do + * support it for zeroconf */ + { OPT_SCID_ALIAS, + .copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT, + [NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT, + [BOLT11_FEATURE] = FEATURE_DONT_REPRESENT, + [CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT} }, + + /* Zeroconf is always signalled in `init`, but we still + * negotiate on a per-channel basis when calling `fundchannel` + * with the `mindepth` parameter, and accept a channel with + * the `open_channel` hook and its return value for + * `mindepth`. + */ + { OPT_ZEROCONF, + .copy_style = { + [INIT_FEATURE] = FEATURE_REPRESENT, + [NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT, + [BOLT11_FEATURE] = FEATURE_DONT_REPRESENT, + [CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT} }, { OPT_SHUTDOWN_ANYSEGWIT, .copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT, [NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT, @@ -422,9 +442,9 @@ const char *feature_name(const tal_t *ctx, size_t f) "option_want_peer_backup", /* 40/41 */ /* https://github.com/lightningnetwork/lightning-rfc/pull/881 */ "option_provide_peer_backup", /* https://github.com/lightningnetwork/lightning-rfc/pull/881 */ NULL, - NULL, + "option_scid_alias", /* https://github.com/lightning/bolts/pull/910 */ "option_payment_metadata", - NULL, /* 50/51 */ + "option_zeroconf", /* 50/51, https://github.com/lightning/bolts/pull/910 */ NULL, "option_keysend", NULL, @@ -546,3 +566,14 @@ const char *fmt_featurebits(const tal_t *ctx, const u8 *featurebits) } return fmt; } + +struct feature_set *feature_set_dup(const tal_t *ctx, + const struct feature_set *other) +{ + struct feature_set *res = tal(ctx, struct feature_set); + + for (size_t i = 0; i < ARRAY_SIZE(res->bits); i++) + res->bits[i] = tal_dup_talarr(res, u8, other->bits[i]); + + return res; +} diff --git a/common/features.h b/common/features.h index 3bea46356..58b57c48f 100644 --- a/common/features.h +++ b/common/features.h @@ -81,6 +81,9 @@ bool featurebits_eq(const u8 *f1, const u8 *f2); /* Good for debugging: returns comma-separated string of bits. */ const char *fmt_featurebits(const tal_t *ctx, const u8 *featurebits); +struct feature_set *feature_set_dup(const tal_t *ctx, + const struct feature_set *other); + /* BOLT #9: * * Flags are numbered from the least-significant bit, at bit 0 (i.e. 0x1, @@ -134,6 +137,13 @@ const char *fmt_featurebits(const tal_t *ctx, const u8 *featurebits); */ #define OPT_DUAL_FUND 28 +/* BOLT-519be05f61e2c35ddf95b731203f89b4ee0946c3 #9: + * | 46/47 | `option_scid_alias` | ... IN ... + * | 50/51 | `option_eroconf` | ... IN ... + */ +#define OPT_SCID_ALIAS 46 +#define OPT_ZEROCONF 50 + /* BOLT-quiescent #9: * | 34/35 | `option_quiesce` | ... IN ... */ diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 45e71ed14..e54610f00 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -824,6 +824,8 @@ static struct feature_set *default_features(const tal_t *ctx) OPTIONAL_FEATURE(OPT_STATIC_REMOTEKEY), OPTIONAL_FEATURE(OPT_SHUTDOWN_ANYSEGWIT), OPTIONAL_FEATURE(OPT_PAYMENT_METADATA), + OPTIONAL_FEATURE(OPT_SCID_ALIAS), + OPTIONAL_FEATURE(OPT_ZEROCONF), #if EXPERIMENTAL_FEATURES OPTIONAL_FEATURE(OPT_ANCHOR_OUTPUTS), OPTIONAL_FEATURE(OPT_QUIESCE), diff --git a/tests/test_misc.py b/tests/test_misc.py index 5a86cb835..b93579447 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -1819,9 +1819,13 @@ def test_list_features_only(node_factory): expected += ['option_shutdown_anysegwit/odd'] expected += ['option_quiesce/odd'] expected += ['option_onion_messages/odd'] + expected += ['option_scid_alias/odd'] + expected += ['option_zeroconf/odd'] expected += ['supports_open_accept_channel_type'] else: expected += ['option_shutdown_anysegwit/odd'] + expected += ['option_scid_alias/odd'] + expected += ['option_zeroconf/odd'] assert features == expected diff --git a/tests/utils.py b/tests/utils.py index 0af3afadd..ef1a18b15 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -37,7 +37,7 @@ def hex_bits(features): def expected_peer_features(wumbo_channels=False, extra=[]): """Return the expected peer features hexstring for this configuration""" - features = [1, 5, 7, 8, 11, 13, 14, 17, 27] + features = [1, 5, 7, 8, 11, 13, 14, 17, 27, 47, 51] if EXPERIMENTAL_FEATURES: # OPT_ONION_MESSAGES features += [39] @@ -59,7 +59,7 @@ def expected_peer_features(wumbo_channels=False, extra=[]): # features for the 'node' and the 'peer' feature sets def expected_node_features(wumbo_channels=False, extra=[]): """Return the expected node features hexstring for this configuration""" - features = [1, 5, 7, 8, 11, 13, 14, 17, 27, 55] + features = [1, 5, 7, 8, 11, 13, 14, 17, 27, 47, 51, 55] if EXPERIMENTAL_FEATURES: # OPT_ONION_MESSAGES features += [39]