@@ -879,6 +879,10 @@ pub(crate) const DISCONNECT_PEER_AWAITING_RESPONSE_TICKS: usize = 2;
879
879
/// exceeding this age limit will be force-closed and purged from memory.
880
880
pub(crate) const UNFUNDED_CHANNEL_AGE_LIMIT_TICKS: usize = 60;
881
881
882
+ /// The number of ticks that may elapse while we're waiting for a disconnected peer to reconnect,
883
+ /// before we try to close the associated outbound channel with them.
884
+ pub(crate) const DISCONNECTED_UNCONFIRMED_CHANNEL_AGE_LIMIT_TICKS: usize = 2;
885
+
882
886
/// Number of blocks needed for an output from a coinbase transaction to be spendable.
883
887
pub(crate) const COINBASE_MATURITY: u32 = 100;
884
888
@@ -919,6 +923,39 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
919
923
}
920
924
}
921
925
926
+ pub(super) struct UnconfirmedChannelContext {
927
+ /// A counter tracking how many ticks have elapsed since this unaccepted channel was
928
+ /// created. If this unaccepted channel reaches peer has yet to respond after reaching
929
+ /// `UNACCEPTED_CHANNEL_AGE_LIMIT_TICKS`, it will be force-closed and purged from memory.
930
+ ///
931
+ /// This is so that we don't keep outbound request around which have not been accepted
932
+ /// in a timely manner
933
+ ///
934
+ /// A counter tracking how many ticks have elapsed since this the peer associated to this
935
+ /// unconfimed outbound channel has been disconnected. If this unconfirmed channel associated
936
+ /// peer is still disconnected after reaching `DISCONNECTED_UNCONFIRMED_CHANNEL_AGE_LIMIT_TICKS`,
937
+ /// it will be force-closed and purged from memory.
938
+ ///
939
+ /// This is so that we don't keep the outbound request around for long whose associated peer
940
+ /// has disconnected in middle of channel creation handshake, and has not connected back yet.
941
+ unconfirmed_channel_age_ticks: usize,
942
+ }
943
+
944
+ impl UnconfirmedChannelContext {
945
+ /// Determines whether we should force-close and purge this unfunded channel from memory due to it
946
+ /// having reached the unfunded channel age limit.
947
+ ///
948
+ /// This should be called on every [`super::channelmanager::ChannelManager::timer_tick_occurred`].
949
+ pub fn should_expire_unconfirmed_channel(&mut self, peer_connected: bool) -> bool {
950
+ if peer_connected {
951
+ self.unconfirmed_channel_age_ticks = 0;
952
+ return false;
953
+ }
954
+ self.unconfirmed_channel_age_ticks += 1;
955
+ self.unconfirmed_channel_age_ticks >= DISCONNECTED_UNCONFIRMED_CHANNEL_AGE_LIMIT_TICKS
956
+ }
957
+ }
958
+
922
959
/// Contains all state common to unfunded inbound/outbound channels.
923
960
pub(super) struct UnfundedChannelContext {
924
961
/// A counter tracking how many ticks have elapsed since this unfunded channel was
@@ -6075,6 +6112,7 @@ impl<SP: Deref> Channel<SP> where
6075
6112
pub(super) struct OutboundV1Channel<SP: Deref> where SP::Target: SignerProvider {
6076
6113
pub context: ChannelContext<SP>,
6077
6114
pub unfunded_context: UnfundedChannelContext,
6115
+ pub unconfirmed_context: UnconfirmedChannelContext,
6078
6116
}
6079
6117
6080
6118
impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
@@ -6279,7 +6317,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
6279
6317
6280
6318
blocked_monitor_updates: Vec::new(),
6281
6319
},
6282
- unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 }
6320
+ unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 },
6321
+ unconfirmed_context: UnconfirmedChannelContext { unconfirmed_channel_age_ticks: 0 }
6283
6322
})
6284
6323
}
6285
6324
0 commit comments