@@ -633,6 +633,10 @@ pub(crate) const DISCONNECT_PEER_AWAITING_RESPONSE_TICKS: usize = 2;
633
633
/// exceeding this age limit will be force-closed and purged from memory.
634
634
pub(crate) const UNFUNDED_CHANNEL_AGE_LIMIT_TICKS: usize = 60;
635
635
636
+ /// The number of ticks that may elapse while we're waiting for an outbound channel to be accepted by peer.
637
+ /// An unaccepted channel exceeding this age limit will be force-closed and purged from memory.
638
+ pub(crate) const UNACCEPTED_CHANNEL_AGE_LIMIT_TICKS: usize = 2;
639
+
636
640
/// Number of blocks needed for an output from a coinbase transaction to be spendable.
637
641
pub(crate) const COINBASE_MATURITY: u32 = 100;
638
642
@@ -673,6 +677,34 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
673
677
}
674
678
}
675
679
680
+ pub(super) struct UnacceptedChannelContext {
681
+ /// A counter tracking how many ticks have elapsed since this unaccepted channel was
682
+ /// created. If this unaccepted channel reaches peer has yet to respond after reaching
683
+ /// `UNACCEPTED_CHANNEL_AGE_LIMIT_TICKS`, it will be force-closed and purged from memory.
684
+ ///
685
+ /// This is so that we don't keep outbound request around which have not been accepted
686
+ /// in a timely manner
687
+ unaccepted_channel_age_ticks: usize,
688
+ is_channel_accepted: bool,
689
+ }
690
+
691
+ impl UnacceptedChannelContext {
692
+ /// Determines whether we should force-close and purge this unfunded channel from memory due to it
693
+ /// having reached the unfunded channel age limit.
694
+ ///
695
+ /// This should be called on every [`super::channelmanager::ChannelManager::timer_tick_occurred`].
696
+ pub fn should_expire_unaccepted_channel(&mut self) -> bool {
697
+ if self.is_channel_accepted { return false; }
698
+ self.unaccepted_channel_age_ticks += 1;
699
+ self.unaccepted_channel_age_ticks >= UNACCEPTED_CHANNEL_AGE_LIMIT_TICKS
700
+ }
701
+
702
+ /// Set channel status to accepted
703
+ pub fn channel_accepted(&mut self) {
704
+ self.is_channel_accepted = true;
705
+ }
706
+ }
707
+
676
708
/// Contains all state common to unfunded inbound/outbound channels.
677
709
pub(super) struct UnfundedChannelContext {
678
710
/// A counter tracking how many ticks have elapsed since this unfunded channel was
@@ -5948,6 +5980,7 @@ impl<SP: Deref> Channel<SP> where
5948
5980
pub(super) struct OutboundV1Channel<SP: Deref> where SP::Target: SignerProvider {
5949
5981
pub context: ChannelContext<SP>,
5950
5982
pub unfunded_context: UnfundedChannelContext,
5983
+ pub unaccepted_context: UnacceptedChannelContext,
5951
5984
}
5952
5985
5953
5986
impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
@@ -6152,7 +6185,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
6152
6185
6153
6186
blocked_monitor_updates: Vec::new(),
6154
6187
},
6155
- unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 }
6188
+ unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 },
6189
+ unaccepted_context: UnacceptedChannelContext { unaccepted_channel_age_ticks: 0, is_channel_accepted: false }
6156
6190
})
6157
6191
}
6158
6192
0 commit comments