From 7e5146ab0cd05428688632fcb602a4edc59d3020 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 10 Apr 2023 09:50:56 +0930 Subject: [PATCH] common/channel_type: routines to set known variants, set scid_alias. I tested this indeed breaks if we don't accept it, then implemented the code to accept it. Signed-off-by: Rusty Russell Changelog-Fixed: protocol: We now correctly accept the `option_scid_alias` bit in `open_channel` `channel_type`. Changelog-Deprecated: protocol: Not setting `option_scid_alias` in `option_channel` `channel_type` for unannounced channels. --- common/channel_type.c | 14 ++++++++++++++ common/channel_type.h | 4 ++++ doc/lightning-listpeerchannels.7.md | 4 ++-- doc/lightning-listpeers.7.md | 4 ++-- doc/schemas/listpeerchannels.schema.json | 1 + doc/schemas/listpeers.schema.json | 1 + lightningd/opening_control.c | 3 ++- lightningd/peer_control.c | 2 ++ openingd/openingd.c | 24 +++++++++++++++++++++++- openingd/openingd_wire.csv | 2 ++ 10 files changed, 53 insertions(+), 6 deletions(-) diff --git a/common/channel_type.c b/common/channel_type.c index 920aeb99c..d4569f40a 100644 --- a/common/channel_type.c +++ b/common/channel_type.c @@ -43,6 +43,18 @@ struct channel_type *channel_type_anchor_outputs(const tal_t *ctx) return type; } +void channel_type_set_zeroconf(struct channel_type *type) +{ + set_feature_bit(&type->features, + COMPULSORY_FEATURE(OPT_ZEROCONF)); +} + +void channel_type_set_scid_alias(struct channel_type *type) +{ + set_feature_bit(&type->features, + COMPULSORY_FEATURE(OPT_SCID_ALIAS)); +} + struct channel_type *default_channel_type(const tal_t *ctx, const struct feature_set *our_features, const u8 *their_features) @@ -119,6 +131,7 @@ struct channel_type *channel_type_accept(const tal_t *ctx, static const size_t feats[] = { OPT_ANCHOR_OUTPUTS, OPT_STATIC_REMOTEKEY, + OPT_SCID_ALIAS, OPT_ZEROCONF, }; @@ -128,6 +141,7 @@ struct channel_type *channel_type_accept(const tal_t *ctx, * - `option_zeroconf` (bit 50) */ static const size_t variants[] = { + OPT_SCID_ALIAS, OPT_ZEROCONF, }; diff --git a/common/channel_type.h b/common/channel_type.h index 2f59df10b..f4df925c6 100644 --- a/common/channel_type.h +++ b/common/channel_type.h @@ -10,6 +10,10 @@ struct channel_type *channel_type_none(const tal_t *ctx); struct channel_type *channel_type_static_remotekey(const tal_t *ctx); struct channel_type *channel_type_anchor_outputs(const tal_t *ctx); +/* channel_type variants */ +void channel_type_set_zeroconf(struct channel_type *channel_type); +void channel_type_set_scid_alias(struct channel_type *channel_type); + /* Duplicate a channel_type */ struct channel_type *channel_type_dup(const tal_t *ctx, const struct channel_type *t); diff --git a/doc/lightning-listpeerchannels.7.md b/doc/lightning-listpeerchannels.7.md index af7d202a0..c17506a36 100644 --- a/doc/lightning-listpeerchannels.7.md +++ b/doc/lightning-listpeerchannels.7.md @@ -29,7 +29,7 @@ On success, an object containing **channels** is returned. It is an array of ob - **state** (string): the channel state, in particular "CHANNELD\_NORMAL" means the channel can be used normally (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN") - **opener** (string): Who initiated the channel (one of "local", "remote") - **features** (array of strings): - - BOLT #9 features which apply to this channel (one of "option\_static\_remotekey", "option\_anchor\_outputs", "option\_zeroconf") + - BOLT #9 features which apply to this channel (one of "option\_static\_remotekey", "option\_anchor\_outputs", "option\_scid\_alias", "option\_zeroconf") - **scratch\_txid** (txid, optional): The txid we would use if we went onchain now - **channel\_type** (object, optional): channel\_type as negotiated with peer *(added v23.05)*: - **bits** (array of u32s): Each bit set in this channel\_type: @@ -194,4 +194,4 @@ Main web site: Lightning RFC site (BOLT \#9): -[comment]: # ( SHA256STAMP:1e589a9e6eace9134d04693dd00caa03da98dd40c2e65d3c675c9bee06daff7f) +[comment]: # ( SHA256STAMP:98524b075be2355d84732638277bf125549bc7ca21822ed35e1ffd1dff53d7f7) diff --git a/doc/lightning-listpeers.7.md b/doc/lightning-listpeers.7.md index 7acd42b47..21462a787 100644 --- a/doc/lightning-listpeers.7.md +++ b/doc/lightning-listpeers.7.md @@ -69,7 +69,7 @@ On success, an object containing **peers** is returned. It is an array of objec - **state** (string): the channel state, in particular "CHANNELD\_NORMAL" means the channel can be used normally (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN") - **opener** (string): Who initiated the channel (one of "local", "remote") - **features** (array of strings): - - BOLT #9 features which apply to this channel (one of "option\_static\_remotekey", "option\_anchor\_outputs", "option\_zeroconf") + - BOLT #9 features which apply to this channel (one of "option\_static\_remotekey", "option\_anchor\_outputs", "option\_scid\_alias", "option\_zeroconf") - **scratch\_txid** (txid, optional): The txid we would use if we went onchain now - **feerate** (object, optional): Feerates for the current tx: - **perkw** (u32): Feerate per 1000 weight (i.e kSipa) @@ -398,4 +398,4 @@ Main web site: Lightning RFC site (BOLT \#9): -[comment]: # ( SHA256STAMP:156e5622823a8b948c0f15f694afc1d87bb5107091e5b65ee6190b4067661bb4) +[comment]: # ( SHA256STAMP:c0d0cc8f083168fd76caa2430a7c7d27d72a5273c55fb14b0efcbcb7a87274f4) diff --git a/doc/schemas/listpeerchannels.schema.json b/doc/schemas/listpeerchannels.schema.json index bd3a2e75f..f0748b6cb 100644 --- a/doc/schemas/listpeerchannels.schema.json +++ b/doc/schemas/listpeerchannels.schema.json @@ -211,6 +211,7 @@ "enum": [ "option_static_remotekey", "option_anchor_outputs", + "option_scid_alias", "option_zeroconf" ], "description": "BOLT #9 features which apply to this channel" diff --git a/doc/schemas/listpeers.schema.json b/doc/schemas/listpeers.schema.json index 03de437a5..d465b955c 100644 --- a/doc/schemas/listpeers.schema.json +++ b/doc/schemas/listpeers.schema.json @@ -334,6 +334,7 @@ "enum": [ "option_static_remotekey", "option_anchor_outputs", + "option_scid_alias", "option_zeroconf" ], "description": "BOLT #9 features which apply to this channel" diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 7b993c3dd..dece107cb 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -964,7 +964,8 @@ bool peer_start_openingd(struct peer *peer, struct peer_fd *peer_fd) feerate_min(peer->ld, NULL), feerate_max(peer->ld, NULL), IFDEV(peer->ld->dev_force_tmp_channel_id, NULL), - peer->ld->config.allowdustreserve); + peer->ld->config.allowdustreserve, + !deprecated_apis); subd_send_msg(uc->open_daemon, take(msg)); return true; } diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 73a581292..91a607eb1 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -866,6 +866,8 @@ static void json_add_channel(struct lightningd *ld, json_add_string(response, NULL, "option_anchor_outputs"); if (channel_has(channel, OPT_ZEROCONF)) json_add_string(response, NULL, "option_zeroconf"); + if (channel_has(channel, OPT_SCID_ALIAS)) + json_add_string(response, NULL, "option_scid_alias"); json_array_end(response); if (!amount_sat_sub(&peer_funded_sats, channel->funding_sats, diff --git a/openingd/openingd.c b/openingd/openingd.c index fd23fbd93..9e746a846 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -102,6 +102,9 @@ struct state { struct amount_sat *reserve; bool allowdustreserve; + + /* Are we allowed to set option_scid_alias is channel_type? */ + bool can_set_scid_alias_channel_type; }; /*~ If we can't agree on parameters, we fail to open the channel. @@ -332,6 +335,14 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags) state->our_features, state->their_features); + /* Spec says we should use the option_scid_alias variation if we + * want them to *only* use the scid_alias. But we didn't accept this + * in CLN prior to v23.05, so we don't send that in deprecated mode! */ + if (state->can_set_scid_alias_channel_type) { + if (!(channel_flags & CHANNEL_FLAGS_ANNOUNCE_CHANNEL)) + channel_type_set_scid_alias(state->channel_type); + } + open_tlvs = tlv_open_channel_tlvs_new(tmpctx); open_tlvs->upfront_shutdown_script = state->upfront_shutdown_script[LOCAL]; @@ -902,6 +913,16 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) open_tlvs->channel_type)); return NULL; } + + /* If we're not using scid_alias in channel type, intuit it here. + * We have to do this, because we used not to accept that bit, so older + * clients won't send it! */ + if (!state->can_set_scid_alias_channel_type + && !(channel_flags & CHANNEL_FLAGS_ANNOUNCE_CHANNEL) + && feature_negotiated(state->our_features, state->their_features, + OPT_SCID_ALIAS)) { + channel_type_set_scid_alias(state->channel_type); + } } else state->channel_type = default_channel_type(state, @@ -1453,7 +1474,8 @@ int main(int argc, char *argv[]) &state->minimum_depth, &state->min_feerate, &state->max_feerate, &force_tmp_channel_id, - &state->allowdustreserve)) + &state->allowdustreserve, + &state->can_set_scid_alias_channel_type)) master_badmsg(WIRE_OPENINGD_INIT, msg); #if DEVELOPER diff --git a/openingd/openingd_wire.csv b/openingd/openingd_wire.csv index 4ab658773..3431b5447 100644 --- a/openingd/openingd_wire.csv +++ b/openingd/openingd_wire.csv @@ -28,6 +28,8 @@ msgdata,openingd_init,dev_temporary_channel_id,?byte,32 # reserves? This is explicitly required by the spec for safety # reasons, but some implementations and users keep asking for it. msgdata,openingd_init,allowdustreserve,bool, +# Core LN prior to 23.05 didn't like this bit set! +msgdata,openingd_init,can_set_scid_alias_channel_type,bool, # Openingd->master: they offered channel, should we continue? msgtype,openingd_got_offer,6005