Skip to content

Commit e2b8063

Browse files
committed
f do the channel type calculation in the new method instead
1 parent 66e0f4b commit e2b8063

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

lightning/src/ln/channel.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6170,13 +6170,21 @@ where
61706170

61716171
// If we're doing manual acceptance checks on the channel, then defer creation until we're sure we want to accept.
61726172
if self.default_configuration.manually_accept_inbound_channels {
6173+
let channel_type_res = channel::channel_type_from_open_channel(
6174+
&msg, &peer_state.latest_features, &self.channel_type_features()
6175+
);
6176+
let channel_type = match channel_type_res {
6177+
Ok(channel_type) => channel_type,
6178+
Err(e) =>
6179+
return Err(MsgHandleErrInternal::from_chan_no_close(e, msg.temporary_channel_id)),
6180+
};
61736181
let mut pending_events = self.pending_events.lock().unwrap();
61746182
pending_events.push_back((events::Event::OpenChannelRequest {
61756183
temporary_channel_id: msg.temporary_channel_id.clone(),
61766184
counterparty_node_id: counterparty_node_id.clone(),
61776185
funding_satoshis: msg.funding_satoshis,
61786186
push_msat: msg.push_msat,
6179-
channel_type: channel::channel_type_from_open_channel(&msg),
6187+
channel_type,
61806188
}, None));
61816189
peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest {
61826190
open_channel_msg: msg.clone(),

0 commit comments

Comments
 (0)