@@ -3838,18 +3838,10 @@ where
38383838 return Err(ChannelError::close("Got an accept_channel message at a strange time".to_owned()));
38393839 }
38403840
3841- if let Some(ty) = &common_fields.channel_type {
3842- if ty != funding.get_channel_type() {
3843- return Err(ChannelError::close("Channel Type in accept_channel didn't match the one sent in open_channel.".to_owned()));
3844- }
3845- } else if their_features.supports_channel_type() {
3846- // Assume they've accepted the channel type as they said they understand it.
3847- } else {
3848- let channel_type = ChannelTypeFeatures::from_init(&their_features);
3849- if channel_type != ChannelTypeFeatures::only_static_remote_key() {
3850- return Err(ChannelError::close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
3851- }
3852- funding.channel_transaction_parameters.channel_type_features = channel_type;
3841+ let channel_type = common_fields.channel_type.as_ref()
3842+ .ok_or_else(|| ChannelError::close("option_channel_type assumed to be supported".to_owned()))?;
3843+ if channel_type != funding.get_channel_type() {
3844+ return Err(ChannelError::close("Channel Type in accept_channel didn't match the one sent in open_channel.".to_owned()));
38533845 }
38543846
38553847 if common_fields.dust_limit_satoshis > 21000000 * 100000000 {
@@ -11542,37 +11534,31 @@ where
1154211534/// [`msgs::CommonOpenChannelFields`].
1154311535#[rustfmt::skip]
1154411536pub(super) fn channel_type_from_open_channel(
11545- common_fields: &msgs::CommonOpenChannelFields, their_features: &InitFeatures,
11546- our_supported_features: &ChannelTypeFeatures
11537+ common_fields: &msgs::CommonOpenChannelFields, our_supported_features: &ChannelTypeFeatures
1154711538) -> Result<ChannelTypeFeatures, ChannelError> {
11548- if let Some(channel_type) = &common_fields.channel_type {
11549- if channel_type.supports_any_optional_bits() {
11550- return Err(ChannelError::close("Channel Type field contained optional bits - this is not allowed".to_owned()));
11551- }
11539+ let channel_type = common_fields.channel_type.as_ref()
11540+ .ok_or_else(|| ChannelError::close("option_channel_type assumed to be supported".to_owned()))?;
1155211541
11553- // We only support the channel types defined by the `ChannelManager` in
11554- // `provided_channel_type_features`. The channel type must always support
11555- // `static_remote_key`, either implicitly with `option_zero_fee_commitments`
11556- // or explicitly.
11557- if !channel_type.requires_static_remote_key() && !channel_type.requires_anchor_zero_fee_commitments() {
11558- return Err(ChannelError::close("Channel Type was not understood - we require static remote key".to_owned()));
11559- }
11560- // Make sure we support all of the features behind the channel type.
11561- if channel_type.requires_unknown_bits_from(&our_supported_features) {
11562- return Err(ChannelError::close("Channel Type contains unsupported features".to_owned()));
11563- }
11564- let announce_for_forwarding = if (common_fields.channel_flags & 1) == 1 { true } else { false };
11565- if channel_type.requires_scid_privacy() && announce_for_forwarding {
11566- return Err(ChannelError::close("SCID Alias/Privacy Channel Type cannot be set on a public channel".to_owned()));
11567- }
11568- Ok(channel_type.clone())
11569- } else {
11570- let channel_type = ChannelTypeFeatures::from_init(&their_features);
11571- if channel_type != ChannelTypeFeatures::only_static_remote_key() {
11572- return Err(ChannelError::close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
11573- }
11574- Ok(channel_type)
11542+ if channel_type.supports_any_optional_bits() {
11543+ return Err(ChannelError::close("Channel Type field contained optional bits - this is not allowed".to_owned()));
11544+ }
11545+
11546+ // We only support the channel types defined by the `ChannelManager` in
11547+ // `provided_channel_type_features`. The channel type must always support
11548+ // `static_remote_key`, either implicitly with `option_zero_fee_commitments`
11549+ // or explicitly.
11550+ if !channel_type.requires_static_remote_key() && !channel_type.requires_anchor_zero_fee_commitments() {
11551+ return Err(ChannelError::close("Channel Type was not understood - we require static remote key".to_owned()));
11552+ }
11553+ // Make sure we support all of the features behind the channel type.
11554+ if channel_type.requires_unknown_bits_from(&our_supported_features) {
11555+ return Err(ChannelError::close("Channel Type contains unsupported features".to_owned()));
1157511556 }
11557+ let announce_for_forwarding = if (common_fields.channel_flags & 1) == 1 { true } else { false };
11558+ if channel_type.requires_scid_privacy() && announce_for_forwarding {
11559+ return Err(ChannelError::close("SCID Alias/Privacy Channel Type cannot be set on a public channel".to_owned()));
11560+ }
11561+ Ok(channel_type.clone())
1157611562}
1157711563
1157811564impl<SP: Deref> InboundV1Channel<SP>
@@ -11596,7 +11582,7 @@ where
1159611582
1159711583 // First check the channel type is known, failing before we do anything else if we don't
1159811584 // support this channel type.
11599- let channel_type = channel_type_from_open_channel(&msg.common_fields, their_features, our_supported_features)?;
11585+ let channel_type = channel_type_from_open_channel(&msg.common_fields, our_supported_features)?;
1160011586
1160111587 let holder_selected_channel_reserve_satoshis = get_holder_selected_channel_reserve_satoshis(msg.common_fields.funding_satoshis, config);
1160211588 let counterparty_pubkeys = ChannelPublicKeys {
@@ -11993,13 +11979,7 @@ where
1199311979 let holder_selected_channel_reserve_satoshis = get_v2_channel_reserve_satoshis(
1199411980 channel_value_satoshis, MIN_CHAN_DUST_LIMIT_SATOSHIS);
1199511981
11996- // First check the channel type is known, failing before we do anything else if we don't
11997- // support this channel type.
11998- if msg.common_fields.channel_type.is_none() {
11999- return Err(ChannelError::close(format!("Rejecting V2 channel {} missing channel_type",
12000- msg.common_fields.temporary_channel_id)))
12001- }
12002- let channel_type = channel_type_from_open_channel(&msg.common_fields, their_features, our_supported_features)?;
11982+ let channel_type = channel_type_from_open_channel(&msg.common_fields, our_supported_features)?;
1200311983
1200411984 let counterparty_pubkeys = ChannelPublicKeys {
1200511985 funding_pubkey: msg.common_fields.funding_pubkey,
0 commit comments