Skip to content

Commit 3b56f5c

Browse files
committed
Use the new property UnconfirmedChannelContext
- If the peer corresponding to OutboundV1Channel has not connected back to us within two timer ticks, we remove the the OutboundChannel
1 parent 0ef9416 commit 3b56f5c

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 16 additions & 9 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::{Channel, ChannelPhase, ChannelContext, ChannelError, ChannelUpdateStatus, ShutdownResult, UnconfirmedChannelContext, 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;
@@ -4831,14 +4831,20 @@ 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);
48434849
self.issue_channel_close_events(&context, ClosureReason::HolderForceClosed);
48444850
shutdown_channels.push(context.force_shutdown(false));
@@ -4847,7 +4853,7 @@ where
48474853
action: msgs::ErrorAction::SendErrorMessage {
48484854
msg: msgs::ErrorMessage {
48494855
channel_id: *chan_id,
4850-
data: "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned(),
4856+
data: "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned()
48514857
},
48524858
},
48534859
});
@@ -4862,6 +4868,7 @@ where
48624868
for (counterparty_node_id, peer_state_mutex) in per_peer_state.iter() {
48634869
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
48644870
let peer_state = &mut *peer_state_lock;
4871+
let peer_connected = peer_state.is_connected.clone();
48654872
let pending_msg_events = &mut peer_state.pending_msg_events;
48664873
let counterparty_node_id = *counterparty_node_id;
48674874
peer_state.channel_by_id.retain(|chan_id, phase| {
@@ -4939,12 +4946,12 @@ where
49394946
true
49404947
},
49414948
ChannelPhase::UnfundedInboundV1(chan) => {
4942-
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
4943-
pending_msg_events, counterparty_node_id)
4949+
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context, &mut None,
4950+
pending_msg_events, counterparty_node_id, peer_connected)
49444951
},
49454952
ChannelPhase::UnfundedOutboundV1(chan) => {
4946-
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
4947-
pending_msg_events, counterparty_node_id)
4953+
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context, &mut Some(&mut chan.unconfirmed_context),
4954+
pending_msg_events, counterparty_node_id, peer_connected)
49484955
},
49494956
}
49504957
});

0 commit comments

Comments
 (0)