From b985cd774d70c778cf858177c6b3e76d067aa1af Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 10 Sep 2021 11:44:23 +0930 Subject: [PATCH] openingd: allow channel_type to *downgrade* from default. e.g. you can negotiate anchor_outputs, but still ask for a non-anchor-output channel. If/when we make those features compulsory, downgrade will not be allowed. Signed-off-by: Rusty Russell --- openingd/openingd.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/openingd/openingd.c b/openingd/openingd.c index b4c8e67e8..6df478bc3 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -832,27 +832,30 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) "Parsing open_channel %s", tal_hex(tmpctx, open_channel_msg)); set_remote_upfront_shutdown(state, open_tlvs->upfront_shutdown_script); - state->channel_type - = default_channel_type(state, - state->our_features, state->their_features); - /* BOLT-channel-types #2: * The receiving node MUST fail the channel if: *... * - It supports `channel_type`, `channel_type` was set, and the * `type` is not suitable. */ - - /* FIXME: We in fact insist on the exact type we want! */ - if (open_tlvs->channel_type - && !featurebits_eq(state->channel_type->features, - open_tlvs->channel_type)) { - negotiation_failed(state, false, - "Did not support channel_type %s", - fmt_featurebits(tmpctx, - open_tlvs->channel_type)); - return NULL; - } + if (open_tlvs->channel_type) { + state->channel_type = + channel_type_accept(state, + open_tlvs->channel_type, + state->our_features, + state->their_features); + if (!state->channel_type) { + negotiation_failed(state, false, + "Did not support channel_type %s", + fmt_featurebits(tmpctx, + open_tlvs->channel_type)); + return NULL; + } + } else + state->channel_type + = default_channel_type(state, + state->our_features, + state->their_features); /* BOLT #2: *