mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
zeroconf: Add channel_type variant support
If zeroconf was negotiated we'll add it to the basic channel type. Similarly we'll accept it if it was negotiated too.
This commit is contained in:
parent
47719018df
commit
cced81646d
@ -47,6 +47,7 @@ struct channel_type *default_channel_type(const tal_t *ctx,
|
||||
const struct feature_set *our_features,
|
||||
const u8 *their_features)
|
||||
{
|
||||
struct channel_type *type;
|
||||
/* BOLT #2:
|
||||
* Both peers:
|
||||
* - if `channel_type` was present in both `open_channel` and `accept_channel`:
|
||||
@ -60,20 +61,28 @@ struct channel_type *default_channel_type(const tal_t *ctx,
|
||||
*/
|
||||
if (feature_negotiated(our_features, their_features,
|
||||
OPT_ANCHOR_OUTPUTS))
|
||||
return channel_type_anchor_outputs(ctx);
|
||||
type = channel_type_anchor_outputs(ctx);
|
||||
/* BOLT #2:
|
||||
* - otherwise, if `option_static_remotekey` was negotiated:
|
||||
* - the `channel_type` is `option_static_remotekey` (bit 12)
|
||||
*/
|
||||
else if (feature_negotiated(our_features, their_features,
|
||||
OPT_STATIC_REMOTEKEY))
|
||||
return channel_type_static_remotekey(ctx);
|
||||
type = channel_type_static_remotekey(ctx);
|
||||
/* BOLT #2:
|
||||
* - otherwise:
|
||||
* - the `channel_type` is empty
|
||||
*/
|
||||
else
|
||||
return channel_type_none(ctx);
|
||||
type = channel_type_none(ctx);
|
||||
|
||||
/* Now apply optional types if any: */
|
||||
if (feature_negotiated(our_features, their_features,
|
||||
OPT_ZEROCONF)) {
|
||||
set_feature_bit(&type->features, OPT_ZEROCONF);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
bool channel_type_has(const struct channel_type *type, int feature)
|
||||
@ -108,9 +117,21 @@ struct channel_type *channel_type_accept(const tal_t *ctx,
|
||||
const struct feature_set *our_features,
|
||||
const u8 *their_features)
|
||||
{
|
||||
struct channel_type *ctype;
|
||||
static const size_t feats[] = { OPT_ANCHOR_OUTPUTS,
|
||||
OPT_STATIC_REMOTEKEY };
|
||||
struct channel_type *ctype, proposed;
|
||||
/* Need to copy since we're going to blank variant bits for equality. */
|
||||
proposed.features = tal_dup_talarr(tmpctx, u8, t);
|
||||
|
||||
static const size_t feats[] = {
|
||||
OPT_ANCHOR_OUTPUTS,
|
||||
OPT_STATIC_REMOTEKEY,
|
||||
OPT_ZEROCONF,
|
||||
};
|
||||
|
||||
/* The basic channel_types can have any number of the
|
||||
* following optional bits. */
|
||||
static const size_t variants[] = {
|
||||
OPT_ZEROCONF,
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(feats); i++) {
|
||||
size_t f = feats[i];
|
||||
@ -128,15 +149,22 @@ struct channel_type *channel_type_accept(const tal_t *ctx,
|
||||
}
|
||||
}
|
||||
|
||||
/* Blank variants so we can just check for equality. */
|
||||
for (size_t i = 0; i< ARRAY_SIZE(variants); i++)
|
||||
featurebits_unset(&proposed.features, variants[i]);
|
||||
|
||||
/* Otherwise, just needs to be a known channel type. */
|
||||
ctype = channel_type_none(tmpctx);
|
||||
if (featurebits_eq(t, ctype->features))
|
||||
return tal_steal(ctx, ctype);
|
||||
ctype = channel_type_static_remotekey(tmpctx);
|
||||
if (featurebits_eq(t, ctype->features))
|
||||
return tal_steal(ctx, ctype);
|
||||
ctype = channel_type_anchor_outputs(tmpctx);
|
||||
if (featurebits_eq(t, ctype->features))
|
||||
return tal_steal(ctx, ctype);
|
||||
if (channel_type_eq(&proposed, channel_type_none(tmpctx)) ||
|
||||
channel_type_eq(&proposed,
|
||||
channel_type_static_remotekey(tmpctx)) ||
|
||||
channel_type_eq(&proposed, channel_type_anchor_outputs(tmpctx))) {
|
||||
/* At this point we know it matches, and maybe has
|
||||
* a couple of extra options. So let's just reply
|
||||
* with their proposal. */
|
||||
ctype = tal(ctx, struct channel_type);
|
||||
ctype->features = tal_dup_talarr(ctx, u8, t);
|
||||
return ctype;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user