Skip to content

Commit c5e01ae

Browse files
committed
Fix reachable unwrap on non-channel_type manual channel acceptance
If we receive an `OpenChannel` message without a `channel_type` with `manually_accept_inbound_channels` set, we will `unwrap()` `None`. This is uncommon these days as most nodes support `channel_type`, but sadly is rather trivial for a peer to hit for those with manual channel acceptance enabled. Reported in and fixes lightningdevkit#2804. Luckily, the updated `full_stack_target` has no issue reaching this issue quickly.
1 parent 0ebe02f commit c5e01ae

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lightning/src/ln/channel.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6845,6 +6845,16 @@ 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(msg: &msgs::OpenChannel) -> ChannelTypeFeatures {
6851+
if let Some(features) = &msg.channel_type {
6852+
features.clone()
6853+
} else {
6854+
ChannelTypeFeatures::only_static_remote_key()
6855+
}
6856+
}
6857+
68486858
impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
68496859
/// Creates a new channel from a remote sides' request for one.
68506860
/// Assumes chain_hash has already been checked and corresponds with what we expect!
@@ -6884,7 +6894,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
68846894
channel_type.clone()
68856895
} else {
68866896
let channel_type = ChannelTypeFeatures::from_init(&their_features);
6887-
if channel_type != ChannelTypeFeatures::only_static_remote_key() {
6897+
if channel_type != channel_type_from_open_channel(msg) {
68886898
return Err(ChannelError::Close("Only static_remote_key is supported for non-negotiated channel types".to_owned()));
68896899
}
68906900
channel_type

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::events::{Event, EventHandler, EventsProvider, MessageSendEvent, Messa
4343
// Since this struct is returned in `list_channels` methods, expose it here in case users want to
4444
// construct one themselves.
4545
use crate::ln::{inbound_payment, ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
46-
use crate::ln::channel::{Channel, ChannelPhase, ChannelContext, ChannelError, ChannelUpdateStatus, ShutdownResult, UnfundedChannelContext, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext};
46+
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelContext, ChannelError, ChannelUpdateStatus, ShutdownResult, UnfundedChannelContext, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext};
4747
use crate::ln::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
4848
#[cfg(any(feature = "_test_utils", test))]
4949
use crate::ln::features::Bolt11InvoiceFeatures;
@@ -6176,7 +6176,7 @@ where
61766176
counterparty_node_id: counterparty_node_id.clone(),
61776177
funding_satoshis: msg.funding_satoshis,
61786178
push_msat: msg.push_msat,
6179-
channel_type: msg.channel_type.clone().unwrap(),
6179+
channel_type: channel::channel_type_from_open_channel(&msg),
61806180
}, None));
61816181
peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest {
61826182
open_channel_msg: msg.clone(),

0 commit comments

Comments
 (0)