Skip to content

Commit 9a344b6

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 9a344b6

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 3 additions & 3 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

@@ -933,7 +933,7 @@ mod tests {
933933
use lightning::events::{Event, PathFailure, MessageSendEventsProvider, MessageSendEvent};
934934
use lightning::{get_event_msg, get_event};
935935
use lightning::ln::types::{PaymentHash, ChannelId};
936-
use lightning::ln::channelmanager;
936+
use lightning::ln::channelmanager::{self, TICKS_PER_MINUTE};
937937
use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChainParameters, MIN_CLTV_EXPIRY_DELTA, PaymentId};
938938
use lightning::ln::features::{ChannelFeatures, NodeFeatures};
939939
use lightning::ln::functional_test_utils::*;
@@ -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 * TICKS_PER_MINUTE as u64 * FRESHNESS_TIMER;
964964

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

lightning/src/ln/channel.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use crate::sync::Mutex;
5656
use crate::sign::type_resolver::ChannelSignerType;
5757

5858
use super::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
59+
use super::channelmanager::TICKS_PER_MINUTE;
5960

6061
#[cfg(test)]
6162
pub struct ChannelValueStat {
@@ -968,9 +969,9 @@ pub(super) enum ChannelUpdateStatus {
968969
/// We've announced the channel as enabled and are connected to our peer.
969970
Enabled,
970971
/// Our channel is no longer live, but we haven't announced the channel as disabled yet.
971-
DisabledStaged(u8),
972+
DisabledStaged(u16),
972973
/// Our channel is live again, but we haven't announced the channel as enabled yet.
973-
EnabledStaged(u8),
974+
EnabledStaged(u16),
974975
/// We've announced the channel as disabled.
975976
Disabled,
976977
}
@@ -1160,23 +1161,23 @@ pub(crate) const MIN_AFFORDABLE_HTLC_COUNT: usize = 4;
11601161
/// number of ticks to allow forwarding HTLCs by nodes that have yet to receive the new
11611162
/// ChannelUpdate prompted by the config update. This value was determined as follows:
11621163
///
1163-
/// * The expected interval between ticks (1 minute).
1164+
/// * The expected interval between ticks (1 second).
11641165
/// * The average convergence delay of updates across the network, i.e., ~300 seconds on average
11651166
/// for a node to see an update as seen on `<https://arxiv.org/pdf/2205.12737.pdf>`.
11661167
/// * `EXPIRE_PREV_CONFIG_TICKS` = convergence_delay / tick_interval
1167-
pub(crate) const EXPIRE_PREV_CONFIG_TICKS: usize = 5;
1168+
pub(crate) const EXPIRE_PREV_CONFIG_TICKS: usize = 5 * TICKS_PER_MINUTE as usize;
11681169

11691170
/// The number of ticks that may elapse while we're waiting for a response to a
11701171
/// [`msgs::RevokeAndACK`] or [`msgs::ChannelReestablish`] message before we attempt to disconnect
11711172
/// them.
11721173
///
11731174
/// See [`ChannelContext::sent_message_awaiting_response`] for more information.
1174-
pub(crate) const DISCONNECT_PEER_AWAITING_RESPONSE_TICKS: usize = 2;
1175+
pub(crate) const DISCONNECT_PEER_AWAITING_RESPONSE_TICKS: usize = 2 * TICKS_PER_MINUTE as usize;
11751176

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

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

36133614
#[cfg(any(test, fuzzing))]
36143615
struct CommitmentTxInfoCached {
@@ -5716,7 +5717,7 @@ impl<SP: Deref> Channel<SP> where
57165717

57175718
/// Checks if the closing_signed negotiation is making appropriate progress, possibly returning
57185719
/// 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.
5720+
/// Should be called on a one-second timer.
57205721
pub fn timer_check_closing_negotiation_progress(&mut self) -> Result<(), ChannelError> {
57215722
if self.closing_negotiation_ready() {
57225723
if self.context.closing_signed_in_flight {

lightning/src/ln/channelmanager.rs

Lines changed: 8 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 * TICKS_PER_MINUTE as i32;
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.
@@ -2259,16 +2259,20 @@ const CHECK_CLTV_EXPIRY_SANITY: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRA
22592259
#[allow(dead_code)]
22602260
const CHECK_CLTV_EXPIRY_SANITY_2: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - 2*CLTV_CLAIM_BUFFER;
22612261

2262+
/// Constant that keeps track of the number of times [`ChannelManager::timer_tick_occurred`]
2263+
/// is called every minute.
2264+
pub const TICKS_PER_MINUTE: u8 = 60;
2265+
22622266
/// The number of ticks of [`ChannelManager::timer_tick_occurred`] until expiry of incomplete MPPs
2263-
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
2267+
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3 * TICKS_PER_MINUTE;
22642268

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

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

22732277
/// The maximum number of unfunded channels we can have per-peer before we start rejecting new
22742278
/// (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)