Skip to content

Commit f610d41

Browse files
committed
Introduce a new timer constant for timer_check_closing_negotiation_progress
1. This function implicitly assumed expiry after 1 timer_tick_occurred. 2. Introduce an explicit timer tick so that the TIMER_LIMIT can be set to an arbitrary number. 3. This addition is utilized in the following commit.
1 parent 1890e80 commit f610d41

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3601,8 +3601,15 @@ pub(super) struct Channel<SP: Deref> where SP::Target: SignerProvider {
36013601
pub context: ChannelContext<SP>,
36023602
#[cfg(any(dual_funding, splicing))]
36033603
pub dual_funding_channel_context: Option<DualFundingChannelContext>,
3604+
/// Number of ticks before channel is force closed if closing_signed negotiation stalls.
3605+
timer_ticks: i32,
36043606
}
36053607

3608+
/// The number of ticks before the channel is forced closed if
3609+
/// no progress on closing_signed negotiation is being made.
3610+
/// An unprogressed channel that exceeds this limit will be abandoned.
3611+
const UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS: i32 = 1;
3612+
36063613
#[cfg(any(test, fuzzing))]
36073614
struct CommitmentTxInfoCached {
36083615
fee: u64,
@@ -5714,7 +5721,7 @@ impl<SP: Deref> Channel<SP> where
57145721
if self.closing_negotiation_ready() {
57155722
if self.context.closing_signed_in_flight {
57165723
return Err(ChannelError::Close("closing_signed negotiation failed to finish within two timer ticks".to_owned()));
5717-
} else {
5724+
} else if { self.timer_ticks -= 1 ; self.timer_ticks } <= 0 {
57185725
self.context.closing_signed_in_flight = true;
57195726
}
57205727
}
@@ -7790,6 +7797,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
77907797
context: self.context,
77917798
#[cfg(any(dual_funding, splicing))]
77927799
dual_funding_channel_context: None,
7800+
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
77937801
};
77947802

77957803
let need_channel_ready = channel.check_get_channel_ready(0).is_some();
@@ -8080,6 +8088,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
80808088
context: self.context,
80818089
#[cfg(any(dual_funding, splicing))]
80828090
dual_funding_channel_context: None,
8091+
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
80838092
};
80848093
let need_channel_ready = channel.check_get_channel_ready(0).is_some();
80858094
channel.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
@@ -9389,6 +9398,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
93899398
},
93909399
#[cfg(any(dual_funding, splicing))]
93919400
dual_funding_channel_context: None,
9401+
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
93929402
})
93939403
}
93949404
}

0 commit comments

Comments
 (0)