@@ -6845,6 +6845,41 @@ pub(super) struct InboundV1Channel<SP: Deref> where SP::Target: SignerProvider {
68456845 pub unfunded_context: UnfundedChannelContext,
68466846}
68476847
6848+ /// Fetches the [`ChannelTypeFeatures`] that will be used for a channel built from a given
6849+ /// [`msgs::OpenChannel`].
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())
6874+ } else {
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)
6880+ }
6881+ }
6882+
68486883impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
68496884 /// Creates a new channel from a remote sides' request for one.
68506885 /// Assumes chain_hash has already been checked and corresponds with what we expect!
@@ -6863,32 +6898,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
68636898
68646899 // First check the channel type is known, failing before we do anything else if we don't
68656900 // support this channel type.
6866- let channel_type = if let Some(channel_type) = &msg.channel_type {
6867- if channel_type.supports_any_optional_bits() {
6868- return Err(ChannelError::Close("Channel Type field contained optional bits - this is not allowed".to_owned()));
6869- }
6870-
6871- // We only support the channel types defined by the `ChannelManager` in
6872- // `provided_channel_type_features`. The channel type must always support
6873- // `static_remote_key`.
6874- if !channel_type.requires_static_remote_key() {
6875- return Err(ChannelError::Close("Channel Type was not understood - we require static remote key".to_owned()));
6876- }
6877- // Make sure we support all of the features behind the channel type.
6878- if !channel_type.is_subset(our_supported_features) {
6879- return Err(ChannelError::Close("Channel Type contains unsupported features".to_owned()));
6880- }
6881- if channel_type.requires_scid_privacy() && announced_channel {
6882- return Err(ChannelError::Close("SCID Alias/Privacy Channel Type cannot be set on a public channel".to_owned()));
6883- }
6884- channel_type.clone()
6885- } else {
6886- let channel_type = ChannelTypeFeatures::from_init(&their_features);
6887- if channel_type != ChannelTypeFeatures::only_static_remote_key() {
6888- return Err(ChannelError::Close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
6889- }
6890- channel_type
6891- };
6901+ let channel_type = channel_type_from_open_channel(msg, their_features, our_supported_features)?;
68926902
68936903 let channel_keys_id = signer_provider.generate_channel_keys_id(true, msg.funding_satoshis, user_id);
68946904 let holder_signer = signer_provider.derive_channel_signer(msg.funding_satoshis, channel_keys_id);
0 commit comments