Skip to content

Commit a9dce9c

Browse files
committed
Convert timer_tick_occurred to a second-long timer
1. Previously, timer_tick_occurred was designed to be called every minute, leading to TIMER_LIMITS set in minutes. 2. However, this restricted the ability to set timer_tick length in smaller durations. 3. This commit updates timer_tick_occurred to be called every second instead of every minute. 4. All TIMER_LIMITS are adjusted accordingly to reflect this change. 5. Additionally, a test is updated to ensure successful compilation post-update.
1 parent f610d41 commit a9dce9c

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub struct BackgroundProcessor {
9393
}
9494

9595
#[cfg(not(test))]
96-
const FRESHNESS_TIMER: u64 = 60;
96+
const FRESHNESS_TIMER: u64 = 1;
9797
#[cfg(test)]
9898
const FRESHNESS_TIMER: u64 = 1;
9999

@@ -960,7 +960,7 @@ mod tests {
960960
use lightning_rapid_gossip_sync::RapidGossipSync;
961961
use super::{BackgroundProcessor, GossipSync, FRESHNESS_TIMER};
962962

963-
const EVENT_DEADLINE: u64 = 5 * FRESHNESS_TIMER;
963+
const EVENT_DEADLINE: u64 = 5 * 60 * FRESHNESS_TIMER;
964964

965965
#[derive(Clone, Hash, PartialEq, Eq)]
966966
struct TestDescriptor{}

lightning/src/ln/channel.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -968,9 +968,9 @@ pub(super) enum ChannelUpdateStatus {
968968
/// We've announced the channel as enabled and are connected to our peer.
969969
Enabled,
970970
/// Our channel is no longer live, but we haven't announced the channel as disabled yet.
971-
DisabledStaged(u8),
971+
DisabledStaged(u16),
972972
/// Our channel is live again, but we haven't announced the channel as enabled yet.
973-
EnabledStaged(u8),
973+
EnabledStaged(u16),
974974
/// We've announced the channel as disabled.
975975
Disabled,
976976
}
@@ -1160,23 +1160,23 @@ pub(crate) const MIN_AFFORDABLE_HTLC_COUNT: usize = 4;
11601160
/// number of ticks to allow forwarding HTLCs by nodes that have yet to receive the new
11611161
/// ChannelUpdate prompted by the config update. This value was determined as follows:
11621162
///
1163-
/// * The expected interval between ticks (1 minute).
1163+
/// * The expected interval between ticks (1 second).
11641164
/// * The average convergence delay of updates across the network, i.e., ~300 seconds on average
11651165
/// for a node to see an update as seen on `<https://arxiv.org/pdf/2205.12737.pdf>`.
11661166
/// * `EXPIRE_PREV_CONFIG_TICKS` = convergence_delay / tick_interval
1167-
pub(crate) const EXPIRE_PREV_CONFIG_TICKS: usize = 5;
1167+
pub(crate) const EXPIRE_PREV_CONFIG_TICKS: usize = 5 * 60;
11681168

11691169
/// The number of ticks that may elapse while we're waiting for a response to a
11701170
/// [`msgs::RevokeAndACK`] or [`msgs::ChannelReestablish`] message before we attempt to disconnect
11711171
/// them.
11721172
///
11731173
/// See [`ChannelContext::sent_message_awaiting_response`] for more information.
1174-
pub(crate) const DISCONNECT_PEER_AWAITING_RESPONSE_TICKS: usize = 2;
1174+
pub(crate) const DISCONNECT_PEER_AWAITING_RESPONSE_TICKS: usize = 2 * 60;
11751175

11761176
/// The number of ticks that may elapse while we're waiting for an unfunded outbound/inbound channel
11771177
/// to be promoted to a [`Channel`] since the unfunded channel was created. An unfunded channel
11781178
/// exceeding this age limit will be force-closed and purged from memory.
1179-
pub(crate) const UNFUNDED_CHANNEL_AGE_LIMIT_TICKS: usize = 60;
1179+
pub(crate) const UNFUNDED_CHANNEL_AGE_LIMIT_TICKS: usize = 60 * 60;
11801180

11811181
/// Number of blocks needed for an output from a coinbase transaction to be spendable.
11821182
pub(crate) const COINBASE_MATURITY: u32 = 100;
@@ -3608,7 +3608,7 @@ pub(super) struct Channel<SP: Deref> where SP::Target: SignerProvider {
36083608
/// The number of ticks before the channel is forced closed if
36093609
/// no progress on closing_signed negotiation is being made.
36103610
/// An unprogressed channel that exceeds this limit will be abandoned.
3611-
const UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS: i32 = 1;
3611+
pub(crate) const UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS: i32 = 1 * 60;
36123612

36133613
#[cfg(any(test, fuzzing))]
36143614
struct CommitmentTxInfoCached {
@@ -5716,7 +5716,7 @@ impl<SP: Deref> Channel<SP> where
57165716

57175717
/// Checks if the closing_signed negotiation is making appropriate progress, possibly returning
57185718
/// an Err if no progress is being made and the channel should be force-closed instead.
5719-
/// Should be called on a one-minute timer.
5719+
/// Should be called on a one-second timer.
57205720
pub fn timer_check_closing_negotiation_progress(&mut self) -> Result<(), ChannelError> {
57215721
if self.closing_negotiation_ready() {
57225722
if self.context.closing_signed_in_flight {

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ pub(super) struct InboundChannelRequest {
957957

958958
/// The number of ticks that may elapse while we're waiting for an unaccepted inbound channel to be
959959
/// accepted. An unaccepted channel that exceeds this limit will be abandoned.
960-
const UNACCEPTED_INBOUND_CHANNEL_AGE_LIMIT_TICKS: i32 = 2;
960+
const UNACCEPTED_INBOUND_CHANNEL_AGE_LIMIT_TICKS: i32 = 2 * 60;
961961

962962
/// Stores a PaymentSecret and any other data we may need to validate an inbound payment is
963963
/// actually ours and not some duplicate HTLC sent to us by a node along the route.
@@ -2260,15 +2260,15 @@ const CHECK_CLTV_EXPIRY_SANITY: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRA
22602260
const CHECK_CLTV_EXPIRY_SANITY_2: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - 2*CLTV_CLAIM_BUFFER;
22612261

22622262
/// The number of ticks of [`ChannelManager::timer_tick_occurred`] until expiry of incomplete MPPs
2263-
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
2263+
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3 * 60;
22642264

22652265
/// The number of ticks of [`ChannelManager::timer_tick_occurred`] where a peer is disconnected
22662266
/// until we mark the channel disabled and gossip the update.
2267-
pub(crate) const DISABLE_GOSSIP_TICKS: u8 = 10;
2267+
pub(crate) const DISABLE_GOSSIP_TICKS: u16 = 10 * 60;
22682268

22692269
/// The number of ticks of [`ChannelManager::timer_tick_occurred`] where a peer is connected until
22702270
/// we mark the channel enabled and gossip the update.
2271-
pub(crate) const ENABLE_GOSSIP_TICKS: u8 = 5;
2271+
pub(crate) const ENABLE_GOSSIP_TICKS: u16 = 5 * 60;
22722272

22732273
/// The maximum number of unfunded channels we can have per-peer before we start rejecting new
22742274
/// (inbound) ones. The number of peers with unfunded channels is limited separately in

lightning/src/ln/shutdown_tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//! Tests of our shutdown and closing_signed negotiation logic as well as some assorted force-close
1111
//! handling tests.
1212
13+
use crate::ln::channel::UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS;
1314
use crate::sign::{EntropySource, SignerProvider};
1415
use crate::chain::ChannelMonitorUpdateStatus;
1516
use crate::chain::transaction::OutPoint;
@@ -1161,8 +1162,9 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
11611162
assert_eq!(nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1);
11621163
}
11631164

1164-
nodes[1].node.timer_tick_occurred();
1165-
nodes[1].node.timer_tick_occurred();
1165+
for _ in 0..UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS + 1 {
1166+
nodes[1].node.timer_tick_occurred();
1167+
}
11661168

11671169
let txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
11681170
assert_eq!(txn.len(), 1);

0 commit comments

Comments
 (0)