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 <rusty@rustcorp.com.au>
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.
This commit is contained in:
Rusty Russell
2023-04-10 09:50:56 +09:30
parent f1deeda123
commit 7e5146ab0c
10 changed files with 53 additions and 6 deletions

View File

@@ -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,
};

View File

@@ -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);

View File

@@ -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: <https://github.com/ElementsProject/lightning> Lightning
RFC site (BOLT \#9):
<https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md>
[comment]: # ( SHA256STAMP:1e589a9e6eace9134d04693dd00caa03da98dd40c2e65d3c675c9bee06daff7f)
[comment]: # ( SHA256STAMP:98524b075be2355d84732638277bf125549bc7ca21822ed35e1ffd1dff53d7f7)

View File

@@ -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: <https://github.com/ElementsProject/lightning> Lightning
RFC site (BOLT \#9):
<https://github.com/lightning/bolts/blob/master/09-features.md>
[comment]: # ( SHA256STAMP:156e5622823a8b948c0f15f694afc1d87bb5107091e5b65ee6190b4067661bb4)
[comment]: # ( SHA256STAMP:c0d0cc8f083168fd76caa2430a7c7d27d72a5273c55fb14b0efcbcb7a87274f4)

View File

@@ -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"

View File

@@ -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"

View File

@@ -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;
}

View File

@@ -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,

View File

@@ -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

View File

@@ -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
1 #include <bitcoin/chainparams.h>
28 # reasons, but some implementations and users keep asking for it.
29 msgdata,openingd_init,allowdustreserve,bool,
30 # Openingd->master: they offered channel, should we continue? # Core LN prior to 23.05 didn't like this bit set!
31 msgdata,openingd_init,can_set_scid_alias_channel_type,bool,
32 # Openingd->master: they offered channel, should we continue?
33 msgtype,openingd_got_offer,6005
34 msgdata,openingd_got_offer,funding_satoshis,amount_sat,
35 msgdata,openingd_got_offer,push_msat,amount_msat,