Skip to content

Commit 8f9289d

Browse files
committed
f - update option_channel_type error msg
1 parent 6d6511b commit 8f9289d

File tree

3 files changed

+31
-32
lines changed

3 files changed

+31
-32
lines changed

fuzz/src/full_stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
10661066
ext_from_hex("0010 03000000000000000000000000000000", &mut test);
10671067
// inbound read from peer id 0 of len 32
10681068
ext_from_hex("030020", &mut test);
1069-
// init message (type 16) with static_remotekey required, no channel_type/anchors/taproot, and other bits optional and mac
1069+
// init message (type 16) with static_remotekey required, no anchors/taproot, and other bits optional and mac
10701070
ext_from_hex("0010 00021aaa 0008aaa218aa2a0a9aaa 03000000000000000000000000000000", &mut test);
10711071

10721072
// inbound read from peer id 0 of len 18
@@ -1167,7 +1167,7 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
11671167
ext_from_hex("0010 01000000000000000000000000000000", &mut test);
11681168
// inbound read from peer id 1 of len 32
11691169
ext_from_hex("030120", &mut test);
1170-
// init message (type 16) with static_remotekey required, no channel_type/anchors/taproot, and other bits optional and mac
1170+
// init message (type 16) with static_remotekey required, no anchors/taproot, and other bits optional and mac
11711171
ext_from_hex("0010 00021aaa 0008aaa218aa2a0a9aaa 01000000000000000000000000000000", &mut test);
11721172

11731173
// create outbound channel to peer 1 for 50k sat

lightning/src/ln/channel.rs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3838,12 +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 {
3846-
return Err(ChannelError::close("channel_type assumed to be supported".to_owned()));
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()));
38473845
}
38483846

38493847
if common_fields.dust_limit_satoshis > 21000000 * 100000000 {
@@ -11538,30 +11536,29 @@ where
1153811536
pub(super) fn channel_type_from_open_channel(
1153911537
common_fields: &msgs::CommonOpenChannelFields, our_supported_features: &ChannelTypeFeatures
1154011538
) -> Result<ChannelTypeFeatures, ChannelError> {
11541-
if let Some(channel_type) = &common_fields.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-
}
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()))?;
1154511541

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()));
11556-
}
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())
11562-
} else {
11563-
return Err(ChannelError::close("channel_type assumed to be supported".to_owned()));
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()));
11556+
}
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()));
1156411560
}
11561+
Ok(channel_type.clone())
1156511562
}
1156611563

1156711564
impl<SP: Deref> InboundV1Channel<SP>

lightning/src/ln/msgs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ pub struct CommonOpenChannelFields {
242242
/// Optionally, a request to pre-set the to-channel-initiator output's scriptPubkey for when we
243243
/// collaboratively close
244244
pub shutdown_scriptpubkey: Option<ScriptBuf>,
245-
/// The channel type that this channel will represent
245+
/// The channel type that this channel will represent. As defined in the latest
246+
/// specification, this field is required. However, it is an `Option` for legacy reasons.
246247
pub channel_type: Option<ChannelTypeFeatures>,
247248
}
248249

@@ -353,7 +354,8 @@ pub struct CommonAcceptChannelFields {
353354
/// Optionally, a request to pre-set the to-channel-acceptor output's scriptPubkey for when we
354355
/// collaboratively close
355356
pub shutdown_scriptpubkey: Option<ScriptBuf>,
356-
/// The channel type that this channel will represent
357+
/// The channel type that this channel will represent. As defined in the latest
358+
/// specification, this field is required. However, it is an `Option` for legacy reasons.
357359
///
358360
/// This is required to match the equivalent field in [`OpenChannel`] or [`OpenChannelV2`]'s
359361
/// [`CommonOpenChannelFields::channel_type`].

0 commit comments

Comments
 (0)