diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index a929c9f4cfb..7c81b4a43bd 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -5489,7 +5489,7 @@ impl Channel { /// A not-yet-funded outbound (from holder) channel using V1 channel establishment. pub(super) struct OutboundV1Channel { pub context: ChannelContext, - pub pending_context: UnfundedChannelContext, + pub unfunded_context: UnfundedChannelContext, } impl OutboundV1Channel { @@ -5687,7 +5687,7 @@ impl OutboundV1Channel { blocked_monitor_updates: Vec::new(), }, - pending_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 } + unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 } }) } @@ -5986,7 +5986,7 @@ impl OutboundV1Channel { /// A not-yet-funded inbound (from counterparty) channel using V1 channel establishment. pub(super) struct InboundV1Channel { pub context: ChannelContext, - pub pending_context: UnfundedChannelContext, + pub unfunded_context: UnfundedChannelContext, } impl InboundV1Channel { @@ -6315,7 +6315,7 @@ impl InboundV1Channel { blocked_monitor_updates: Vec::new(), }, - pending_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 } + unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 } }; Ok(chan) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 38de434aa58..704d2423767 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -80,6 +80,8 @@ use core::ops::Deref; pub use crate::ln::outbound_payment::{PaymentSendFailure, Retry, RetryableSendFailure, RecipientOnionFields}; use crate::ln::script::ShutdownScript; +use super::channel::UnfundedChannelContext; + // We hold various information about HTLC relay in the HTLC objects in Channel itself: // // Upon receipt of an HTLC from a peer, we'll give it a PendingHTLCStatus indicating if it should @@ -4410,26 +4412,24 @@ where true }); - let force_close_expired_unfunded_channel = |chan_id: &[u8; 32], chan_context: &mut ChannelContext<::Signer>| { - log_error!(self.logger, "Force-closing pending outbound channel {} for not establishing in a timely manner", log_bytes!(&chan_id[..])); - self.issue_channel_close_events(&chan_context, ClosureReason::HolderForceClosed); - self.finish_force_close_channel(chan_context.force_shutdown(false)); - false - }; - peer_state.outbound_v1_channel_by_id.retain(|chan_id, chan| { - if chan.pending_context.should_expire_unfunded_channel() { - force_close_expired_unfunded_channel(chan_id, &mut chan.context) + let process_unfunded_channel_tick = | + chan_id: &[u8; 32], + chan_context: &mut ChannelContext<::Signer>, + unfunded_chan_context: &mut UnfundedChannelContext, + | { + chan_context.maybe_expire_prev_config(); + if unfunded_chan_context.should_expire_unfunded_channel() { + log_error!(self.logger, "Force-closing pending outbound channel {} for not establishing in a timely manner", log_bytes!(&chan_id[..])); + update_maps_on_chan_removal!(self, &chan_context); + self.issue_channel_close_events(&chan_context, ClosureReason::HolderForceClosed); + self.finish_force_close_channel(chan_context.force_shutdown(false)); + false } else { true } - }); - peer_state.inbound_v1_channel_by_id.retain(|chan_id, chan| { - if chan.pending_context.should_expire_unfunded_channel() { - force_close_expired_unfunded_channel(chan_id, &mut chan.context) - } else { - true - } - }); + }; + peer_state.outbound_v1_channel_by_id.retain(|chan_id, chan| process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context)); + peer_state.inbound_v1_channel_by_id.retain(|chan_id, chan| process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context)); if peer_state.ok_to_remove(true) { pending_peers_awaiting_removal.push(counterparty_node_id);