@@ -6847,11 +6847,36 @@ pub(super) struct InboundV1Channel<SP: Deref> where SP::Target: SignerProvider {
68476847
68486848/// Fetches the [`ChannelTypeFeatures`] that will be used for a channel built from a given
68496849/// [`msgs::OpenChannel`].
6850- pub(super) fn channel_type_from_open_channel(msg: &msgs::OpenChannel) -> ChannelTypeFeatures {
6851- 	if let Some(features) = &msg.channel_type {
6852- 		features.clone()
6850+ pub(super) fn channel_type_from_open_channel(
6851+ 	msg: &msgs::OpenChannel, their_features: &InitFeatures,
6852+ 	our_supported_features: &ChannelTypeFeatures
6853+ ) -> Result<ChannelTypeFeatures, ChannelError> {
6854+ 	if let Some(channel_type) = &msg.channel_type {
6855+ 		if channel_type.supports_any_optional_bits() {
6856+ 			return Err(ChannelError::Close("Channel Type field contained optional bits - this is not allowed".to_owned()));
6857+ 		}
6858+ 
6859+ 		// We only support the channel types defined by the `ChannelManager` in
6860+ 		// `provided_channel_type_features`. The channel type must always support
6861+ 		// `static_remote_key`.
6862+ 		if !channel_type.requires_static_remote_key() {
6863+ 			return Err(ChannelError::Close("Channel Type was not understood - we require static remote key".to_owned()));
6864+ 		}
6865+ 		// Make sure we support all of the features behind the channel type.
6866+ 		if !channel_type.is_subset(our_supported_features) {
6867+ 			return Err(ChannelError::Close("Channel Type contains unsupported features".to_owned()));
6868+ 		}
6869+ 		let announced_channel = if (msg.channel_flags & 1) == 1 { true } else { false };
6870+ 		if channel_type.requires_scid_privacy() && announced_channel {
6871+ 			return Err(ChannelError::Close("SCID Alias/Privacy Channel Type cannot be set on a public channel".to_owned()));
6872+ 		}
6873+ 		Ok(channel_type.clone())
68536874	} else {
6854- 		ChannelTypeFeatures::only_static_remote_key()
6875+ 		let channel_type = ChannelTypeFeatures::from_init(&their_features);
6876+ 		if channel_type != ChannelTypeFeatures::only_static_remote_key() {
6877+ 			return Err(ChannelError::Close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
6878+ 		}
6879+ 		Ok(channel_type)
68556880	}
68566881}
68576882
@@ -6873,32 +6898,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
68736898
68746899		// First check the channel type is known, failing before we do anything else if we don't
68756900		// support this channel type.
6876- 		let channel_type = if let Some(channel_type) = &msg.channel_type {
6877- 			if channel_type.supports_any_optional_bits() {
6878- 				return Err(ChannelError::Close("Channel Type field contained optional bits - this is not allowed".to_owned()));
6879- 			}
6880- 
6881- 			// We only support the channel types defined by the `ChannelManager` in
6882- 			// `provided_channel_type_features`. The channel type must always support
6883- 			// `static_remote_key`.
6884- 			if !channel_type.requires_static_remote_key() {
6885- 				return Err(ChannelError::Close("Channel Type was not understood - we require static remote key".to_owned()));
6886- 			}
6887- 			// Make sure we support all of the features behind the channel type.
6888- 			if !channel_type.is_subset(our_supported_features) {
6889- 				return Err(ChannelError::Close("Channel Type contains unsupported features".to_owned()));
6890- 			}
6891- 			if channel_type.requires_scid_privacy() && announced_channel {
6892- 				return Err(ChannelError::Close("SCID Alias/Privacy Channel Type cannot be set on a public channel".to_owned()));
6893- 			}
6894- 			channel_type.clone()
6895- 		} else {
6896- 			let channel_type = ChannelTypeFeatures::from_init(&their_features);
6897- 			if channel_type != channel_type_from_open_channel(msg) {
6898- 				return Err(ChannelError::Close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
6899- 			}
6900- 			channel_type
6901- 		};
6901+ 		let channel_type = channel_type_from_open_channel(msg, their_features, our_supported_features)?;
69026902
69036903		let channel_keys_id = signer_provider.generate_channel_keys_id(true, msg.funding_satoshis, user_id);
69046904		let holder_signer = signer_provider.derive_channel_signer(msg.funding_satoshis, channel_keys_id);
0 commit comments