@@ -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.
4545use 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::{Channel, ChannelPhase, ChannelContext, ChannelError, ChannelUpdateStatus, ShutdownResult, UnconfirmedChannelContext, UnfundedChannelContext, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext};
4747use crate::ln::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
4848#[cfg(any(feature = "_test_utils", test))]
4949use crate::ln::features::Bolt11InvoiceFeatures;
@@ -4831,23 +4831,33 @@ where
48314831 chan_id: &ChannelId,
48324832 context: &mut ChannelContext<SP>,
48334833 unfunded_context: &mut UnfundedChannelContext,
4834+ unconfirmed_context: &mut Option<&mut UnconfirmedChannelContext>,
48344835 pending_msg_events: &mut Vec<MessageSendEvent>,
48354836 counterparty_node_id: PublicKey,
4837+ is_connected: bool
48364838 | {
48374839 context.maybe_expire_prev_config();
4838- if unfunded_context.should_expire_unfunded_channel() {
4840+ let should_expire_unconfirmed_channel = match unconfirmed_context {
4841+ Some(unconfirmed_context) => unconfirmed_context.should_expire_unconfirmed_channel(is_connected),
4842+ None => false,
4843+ };
4844+ let should_expire_unfunded_channel = unfunded_context.should_expire_unfunded_channel();
4845+ if should_expire_unconfirmed_channel || should_expire_unfunded_channel {
48394846 let logger = WithChannelContext::from(&self.logger, context);
4840- log_error!(logger,
4841- "Force-closing pending channel with ID {} for not establishing in a timely manner", chan_id);
4847+ log_error!(logger, "Force-closing pending channel with ID {} for not establishing in a timely manner", chan_id);
48424848 update_maps_on_chan_removal!(self, &context);
4843- self.issue_channel_close_events(&context, ClosureReason::HolderForceClosed);
4849+ if should_expire_unconfirmed_channel {
4850+ self.issue_channel_close_events(&context, ClosureReason::DisconnectedPeer);
4851+ } else {
4852+ self.issue_channel_close_events(&context, ClosureReason::HolderForceClosed);
4853+ }
48444854 shutdown_channels.push(context.force_shutdown(false));
48454855 pending_msg_events.push(MessageSendEvent::HandleError {
48464856 node_id: counterparty_node_id,
48474857 action: msgs::ErrorAction::SendErrorMessage {
48484858 msg: msgs::ErrorMessage {
48494859 channel_id: *chan_id,
4850- data: "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned(),
4860+ data: "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned()
48514861 },
48524862 },
48534863 });
@@ -4862,6 +4872,7 @@ where
48624872 for (counterparty_node_id, peer_state_mutex) in per_peer_state.iter() {
48634873 let mut peer_state_lock = peer_state_mutex.lock().unwrap();
48644874 let peer_state = &mut *peer_state_lock;
4875+ let peer_connected = peer_state.is_connected.clone();
48654876 let pending_msg_events = &mut peer_state.pending_msg_events;
48664877 let counterparty_node_id = *counterparty_node_id;
48674878 peer_state.channel_by_id.retain(|chan_id, phase| {
@@ -4939,12 +4950,12 @@ where
49394950 true
49404951 },
49414952 ChannelPhase::UnfundedInboundV1(chan) => {
4942- process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
4943- pending_msg_events, counterparty_node_id)
4953+ process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context, &mut None,
4954+ pending_msg_events, counterparty_node_id, peer_connected )
49444955 },
49454956 ChannelPhase::UnfundedOutboundV1(chan) => {
4946- process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
4947- pending_msg_events, counterparty_node_id)
4957+ process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context, &mut Some(&mut chan.unconfirmed_context),
4958+ pending_msg_events, counterparty_node_id, peer_connected )
49484959 },
49494960 }
49504961 });
0 commit comments