Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lightning-background-processor/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ pub struct BackgroundProcessor {
}

#[cfg(not(test))]
const FRESHNESS_TIMER: u64 = 60;
const FRESHNESS_TIMER: u64 = 1;
#[cfg(test)]
const FRESHNESS_TIMER: u64 = 1;

Expand DownExpand Up@@ -933,7 +933,7 @@ mod tests {
use lightning::events::{Event, PathFailure, MessageSendEventsProvider, MessageSendEvent};
use lightning::{get_event_msg, get_event};
use lightning::ln::types::{PaymentHash, ChannelId};
use lightning::ln::channelmanager;
use lightning::ln::channelmanager::{self, TICKS_PER_MINUTE};
use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChainParameters, MIN_CLTV_EXPIRY_DELTA, PaymentId};
use lightning::ln::features::{ChannelFeatures, NodeFeatures};
use lightning::ln::functional_test_utils::*;
Expand All@@ -960,7 +960,7 @@ mod tests {
use lightning_rapid_gossip_sync::RapidGossipSync;
use super::{BackgroundProcessor, GossipSync, FRESHNESS_TIMER};

const EVENT_DEADLINE: u64 = 5 * FRESHNESS_TIMER;
const EVENT_DEADLINE: u64 = 5 * TICKS_PER_MINUTE as u64 * FRESHNESS_TIMER;

#[derive(Clone, Hash, PartialEq, Eq)]
struct TestDescriptor{}
Expand Down
27 changes: 19 additions & 8 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,7 @@ use crate::sync::Mutex;
use crate::sign::type_resolver::ChannelSignerType;

use super::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use super::channelmanager::TICKS_PER_MINUTE;

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

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

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

/// Number of blocks needed for an output from a coinbase transaction to be spendable.
pub(crate) const COINBASE_MATURITY: u32 = 100;
Expand DownExpand Up@@ -3601,8 +3602,15 @@ pub(super) struct Channel<SP: Deref> where SP::Target: SignerProvider {
pub context: ChannelContext<SP>,
#[cfg(any(dual_funding, splicing))]
pub dual_funding_channel_context: Option<DualFundingChannelContext>,
/// Number of ticks before channel is force closed if closing_signed negotiation stalls.
timer_ticks: i32,
}

/// The number of ticks before the channel is forced closed if
/// no progress on closing_signed negotiation is being made.
/// An unprogressed channel that exceeds this limit will be abandoned.
pub(crate) const UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS: i32 = 1 * TICKS_PER_MINUTE as i32;

#[cfg(any(test, fuzzing))]
struct CommitmentTxInfoCached {
fee: u64,
Expand DownExpand Up@@ -5709,12 +5717,12 @@ impl<SP: Deref> Channel<SP> where

/// Checks if the closing_signed negotiation is making appropriate progress, possibly returning
/// an Err if no progress is being made and the channel should be force-closed instead.
/// Should be called on a one-minute timer.
/// Should be called on a one-second timer.
pub fn timer_check_closing_negotiation_progress(&mut self) -> Result<(), ChannelError> {
if self.closing_negotiation_ready() {
if self.context.closing_signed_in_flight {
return Err(ChannelError::Close("closing_signed negotiation failed to finish within two timer ticks".to_owned()));
} else {
} else if { self.timer_ticks -= 1 ; self.timer_ticks } <= 0 {
self.context.closing_signed_in_flight = true;
}
}
Expand DownExpand Up@@ -7790,6 +7798,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
context: self.context,
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
};

let need_channel_ready = channel.check_get_channel_ready(0).is_some();
Expand DownExpand Up@@ -8080,6 +8089,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
context: self.context,
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
};
let need_channel_ready = channel.check_get_channel_ready(0).is_some();
channel.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
Expand DownExpand Up@@ -9389,6 +9399,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
},
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
})
}
}
Expand Down
12 changes: 8 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -957,7 +957,7 @@ pub(super) struct InboundChannelRequest {

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

/// Stores a PaymentSecret and any other data we may need to validate an inbound payment is
/// actually ours and not some duplicate HTLC sent to us by a node along the route.
Expand DownExpand Up@@ -2259,16 +2259,20 @@ const CHECK_CLTV_EXPIRY_SANITY: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRA
#[allow(dead_code)]
const CHECK_CLTV_EXPIRY_SANITY_2: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - 2*CLTV_CLAIM_BUFFER;

/// Constant that keeps track of the number of times [`ChannelManager::timer_tick_occurred`]
/// is called every minute.
pub const TICKS_PER_MINUTE: u8 = 60;

/// The number of ticks of [`ChannelManager::timer_tick_occurred`] until expiry of incomplete MPPs
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3 * TICKS_PER_MINUTE;

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

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

/// The maximum number of unfunded channels we can have per-peer before we start rejecting new
/// (inbound) ones. The number of peers with unfunded channels is limited separately in
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@
//! Tests of our shutdown and closing_signed negotiation logic as well as some assorted force-close
//! handling tests.

use crate::ln::channel::UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS;
use crate::sign::{EntropySource, SignerProvider};
use crate::chain::ChannelMonitorUpdateStatus;
use crate::chain::transaction::OutPoint;
Expand DownExpand Up@@ -1161,8 +1162,9 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
assert_eq!(nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1);
}

nodes[1].node.timer_tick_occurred();
nodes[1].node.timer_tick_occurred();
for _ in 0..UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS + 1 {
nodes[1].node.timer_tick_occurred();
}

let txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
assert_eq!(txn.len(), 1);
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Make timer_tick_occurred a second long timer by shaavan · Pull Request #3065 · lightningdevkit/rust-lightning · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lightning-background-processor/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ pub struct BackgroundProcessor {
}

#[cfg(not(test))]
const FRESHNESS_TIMER: u64 = 60;
const FRESHNESS_TIMER: u64 = 1;
#[cfg(test)]
const FRESHNESS_TIMER: u64 = 1;

Expand DownExpand Up@@ -933,7 +933,7 @@ mod tests {
use lightning::events::{Event, PathFailure, MessageSendEventsProvider, MessageSendEvent};
use lightning::{get_event_msg, get_event};
use lightning::ln::types::{PaymentHash, ChannelId};
use lightning::ln::channelmanager;
use lightning::ln::channelmanager::{self, TICKS_PER_MINUTE};
use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChainParameters, MIN_CLTV_EXPIRY_DELTA, PaymentId};
use lightning::ln::features::{ChannelFeatures, NodeFeatures};
use lightning::ln::functional_test_utils::*;
Expand All@@ -960,7 +960,7 @@ mod tests {
use lightning_rapid_gossip_sync::RapidGossipSync;
use super::{BackgroundProcessor, GossipSync, FRESHNESS_TIMER};

const EVENT_DEADLINE: u64 = 5 * FRESHNESS_TIMER;
const EVENT_DEADLINE: u64 = 5 * TICKS_PER_MINUTE as u64 * FRESHNESS_TIMER;

#[derive(Clone, Hash, PartialEq, Eq)]
struct TestDescriptor{}
Expand Down
27 changes: 19 additions & 8 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,7 @@ use crate::sync::Mutex;
use crate::sign::type_resolver::ChannelSignerType;

use super::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use super::channelmanager::TICKS_PER_MINUTE;

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

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

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

/// Number of blocks needed for an output from a coinbase transaction to be spendable.
pub(crate) const COINBASE_MATURITY: u32 = 100;
Expand DownExpand Up@@ -3601,8 +3602,15 @@ pub(super) struct Channel<SP: Deref> where SP::Target: SignerProvider {
pub context: ChannelContext<SP>,
#[cfg(any(dual_funding, splicing))]
pub dual_funding_channel_context: Option<DualFundingChannelContext>,
/// Number of ticks before channel is force closed if closing_signed negotiation stalls.
timer_ticks: i32,
}

/// The number of ticks before the channel is forced closed if
/// no progress on closing_signed negotiation is being made.
/// An unprogressed channel that exceeds this limit will be abandoned.
pub(crate) const UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS: i32 = 1 * TICKS_PER_MINUTE as i32;

#[cfg(any(test, fuzzing))]
struct CommitmentTxInfoCached {
fee: u64,
Expand DownExpand Up@@ -5709,12 +5717,12 @@ impl<SP: Deref> Channel<SP> where

/// Checks if the closing_signed negotiation is making appropriate progress, possibly returning
/// an Err if no progress is being made and the channel should be force-closed instead.
/// Should be called on a one-minute timer.
/// Should be called on a one-second timer.
pub fn timer_check_closing_negotiation_progress(&mut self) -> Result<(), ChannelError> {
if self.closing_negotiation_ready() {
if self.context.closing_signed_in_flight {
return Err(ChannelError::Close("closing_signed negotiation failed to finish within two timer ticks".to_owned()));
} else {
} else if { self.timer_ticks -= 1 ; self.timer_ticks } <= 0 {
self.context.closing_signed_in_flight = true;
}
}
Expand DownExpand Up@@ -7790,6 +7798,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
context: self.context,
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
};

let need_channel_ready = channel.check_get_channel_ready(0).is_some();
Expand DownExpand Up@@ -8080,6 +8089,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
context: self.context,
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
};
let need_channel_ready = channel.check_get_channel_ready(0).is_some();
channel.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
Expand DownExpand Up@@ -9389,6 +9399,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
},
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
})
}
}
Expand Down
12 changes: 8 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -957,7 +957,7 @@ pub(super) struct InboundChannelRequest {

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

/// Stores a PaymentSecret and any other data we may need to validate an inbound payment is
/// actually ours and not some duplicate HTLC sent to us by a node along the route.
Expand DownExpand Up@@ -2259,16 +2259,20 @@ const CHECK_CLTV_EXPIRY_SANITY: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRA
#[allow(dead_code)]
const CHECK_CLTV_EXPIRY_SANITY_2: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - 2*CLTV_CLAIM_BUFFER;

/// Constant that keeps track of the number of times [`ChannelManager::timer_tick_occurred`]
/// is called every minute.
pub const TICKS_PER_MINUTE: u8 = 60;

/// The number of ticks of [`ChannelManager::timer_tick_occurred`] until expiry of incomplete MPPs
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3 * TICKS_PER_MINUTE;

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

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

/// The maximum number of unfunded channels we can have per-peer before we start rejecting new
/// (inbound) ones. The number of peers with unfunded channels is limited separately in
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@
//! Tests of our shutdown and closing_signed negotiation logic as well as some assorted force-close
//! handling tests.

use crate::ln::channel::UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS;
use crate::sign::{EntropySource, SignerProvider};
use crate::chain::ChannelMonitorUpdateStatus;
use crate::chain::transaction::OutPoint;
Expand DownExpand Up@@ -1161,8 +1162,9 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
assert_eq!(nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1);
}

nodes[1].node.timer_tick_occurred();
nodes[1].node.timer_tick_occurred();
for _ in 0..UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS + 1 {
nodes[1].node.timer_tick_occurred();
}

let txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
assert_eq!(txn.len(), 1);
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Make timer_tick_occurred a second long timer by shaavan · Pull Request #3065 · lightningdevkit/rust-lightning · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lightning-background-processor/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ pub struct BackgroundProcessor {
}

#[cfg(not(test))]
const FRESHNESS_TIMER: u64 = 60;
const FRESHNESS_TIMER: u64 = 1;
#[cfg(test)]
const FRESHNESS_TIMER: u64 = 1;

Expand DownExpand Up@@ -933,7 +933,7 @@ mod tests {
use lightning::events::{Event, PathFailure, MessageSendEventsProvider, MessageSendEvent};
use lightning::{get_event_msg, get_event};
use lightning::ln::types::{PaymentHash, ChannelId};
use lightning::ln::channelmanager;
use lightning::ln::channelmanager::{self, TICKS_PER_MINUTE};
use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChainParameters, MIN_CLTV_EXPIRY_DELTA, PaymentId};
use lightning::ln::features::{ChannelFeatures, NodeFeatures};
use lightning::ln::functional_test_utils::*;
Expand All@@ -960,7 +960,7 @@ mod tests {
use lightning_rapid_gossip_sync::RapidGossipSync;
use super::{BackgroundProcessor, GossipSync, FRESHNESS_TIMER};

const EVENT_DEADLINE: u64 = 5 * FRESHNESS_TIMER;
const EVENT_DEADLINE: u64 = 5 * TICKS_PER_MINUTE as u64 * FRESHNESS_TIMER;

#[derive(Clone, Hash, PartialEq, Eq)]
struct TestDescriptor{}
Expand Down
27 changes: 19 additions & 8 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,7 @@ use crate::sync::Mutex;
use crate::sign::type_resolver::ChannelSignerType;

use super::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use super::channelmanager::TICKS_PER_MINUTE;

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

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

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

/// Number of blocks needed for an output from a coinbase transaction to be spendable.
pub(crate) const COINBASE_MATURITY: u32 = 100;
Expand DownExpand Up@@ -3601,8 +3602,15 @@ pub(super) struct Channel<SP: Deref> where SP::Target: SignerProvider {
pub context: ChannelContext<SP>,
#[cfg(any(dual_funding, splicing))]
pub dual_funding_channel_context: Option<DualFundingChannelContext>,
/// Number of ticks before channel is force closed if closing_signed negotiation stalls.
timer_ticks: i32,
}

/// The number of ticks before the channel is forced closed if
/// no progress on closing_signed negotiation is being made.
/// An unprogressed channel that exceeds this limit will be abandoned.
pub(crate) const UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS: i32 = 1 * TICKS_PER_MINUTE as i32;

#[cfg(any(test, fuzzing))]
struct CommitmentTxInfoCached {
fee: u64,
Expand DownExpand Up@@ -5709,12 +5717,12 @@ impl<SP: Deref> Channel<SP> where

/// Checks if the closing_signed negotiation is making appropriate progress, possibly returning
/// an Err if no progress is being made and the channel should be force-closed instead.
/// Should be called on a one-minute timer.
/// Should be called on a one-second timer.
pub fn timer_check_closing_negotiation_progress(&mut self) -> Result<(), ChannelError> {
if self.closing_negotiation_ready() {
if self.context.closing_signed_in_flight {
return Err(ChannelError::Close("closing_signed negotiation failed to finish within two timer ticks".to_owned()));
} else {
} else if { self.timer_ticks -= 1 ; self.timer_ticks } <= 0 {
self.context.closing_signed_in_flight = true;
}
}
Expand DownExpand Up@@ -7790,6 +7798,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
context: self.context,
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
};

let need_channel_ready = channel.check_get_channel_ready(0).is_some();
Expand DownExpand Up@@ -8080,6 +8089,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
context: self.context,
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
};
let need_channel_ready = channel.check_get_channel_ready(0).is_some();
channel.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
Expand DownExpand Up@@ -9389,6 +9399,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
},
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
})
}
}
Expand Down
12 changes: 8 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -957,7 +957,7 @@ pub(super) struct InboundChannelRequest {

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

/// Stores a PaymentSecret and any other data we may need to validate an inbound payment is
/// actually ours and not some duplicate HTLC sent to us by a node along the route.
Expand DownExpand Up@@ -2259,16 +2259,20 @@ const CHECK_CLTV_EXPIRY_SANITY: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRA
#[allow(dead_code)]
const CHECK_CLTV_EXPIRY_SANITY_2: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - 2*CLTV_CLAIM_BUFFER;

/// Constant that keeps track of the number of times [`ChannelManager::timer_tick_occurred`]
/// is called every minute.
pub const TICKS_PER_MINUTE: u8 = 60;

/// The number of ticks of [`ChannelManager::timer_tick_occurred`] until expiry of incomplete MPPs
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3 * TICKS_PER_MINUTE;

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

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

/// The maximum number of unfunded channels we can have per-peer before we start rejecting new
/// (inbound) ones. The number of peers with unfunded channels is limited separately in
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@
//! Tests of our shutdown and closing_signed negotiation logic as well as some assorted force-close
//! handling tests.

use crate::ln::channel::UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS;
use crate::sign::{EntropySource, SignerProvider};
use crate::chain::ChannelMonitorUpdateStatus;
use crate::chain::transaction::OutPoint;
Expand DownExpand Up@@ -1161,8 +1162,9 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
assert_eq!(nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1);
}

nodes[1].node.timer_tick_occurred();
nodes[1].node.timer_tick_occurred();
for _ in 0..UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS + 1 {
nodes[1].node.timer_tick_occurred();
}

let txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
assert_eq!(txn.len(), 1);
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Make timer_tick_occurred a second long timer by shaavan · Pull Request #3065 · lightningdevkit/rust-lightning · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lightning-background-processor/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ pub struct BackgroundProcessor {
}

#[cfg(not(test))]
const FRESHNESS_TIMER: u64 = 60;
const FRESHNESS_TIMER: u64 = 1;
#[cfg(test)]
const FRESHNESS_TIMER: u64 = 1;

Expand DownExpand Up@@ -933,7 +933,7 @@ mod tests {
use lightning::events::{Event, PathFailure, MessageSendEventsProvider, MessageSendEvent};
use lightning::{get_event_msg, get_event};
use lightning::ln::types::{PaymentHash, ChannelId};
use lightning::ln::channelmanager;
use lightning::ln::channelmanager::{self, TICKS_PER_MINUTE};
use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChainParameters, MIN_CLTV_EXPIRY_DELTA, PaymentId};
use lightning::ln::features::{ChannelFeatures, NodeFeatures};
use lightning::ln::functional_test_utils::*;
Expand All@@ -960,7 +960,7 @@ mod tests {
use lightning_rapid_gossip_sync::RapidGossipSync;
use super::{BackgroundProcessor, GossipSync, FRESHNESS_TIMER};

const EVENT_DEADLINE: u64 = 5 * FRESHNESS_TIMER;
const EVENT_DEADLINE: u64 = 5 * TICKS_PER_MINUTE as u64 * FRESHNESS_TIMER;

#[derive(Clone, Hash, PartialEq, Eq)]
struct TestDescriptor{}
Expand Down
27 changes: 19 additions & 8 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,7 @@ use crate::sync::Mutex;
use crate::sign::type_resolver::ChannelSignerType;

use super::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use super::channelmanager::TICKS_PER_MINUTE;

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

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

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

/// Number of blocks needed for an output from a coinbase transaction to be spendable.
pub(crate) const COINBASE_MATURITY: u32 = 100;
Expand DownExpand Up@@ -3601,8 +3602,15 @@ pub(super) struct Channel<SP: Deref> where SP::Target: SignerProvider {
pub context: ChannelContext<SP>,
#[cfg(any(dual_funding, splicing))]
pub dual_funding_channel_context: Option<DualFundingChannelContext>,
/// Number of ticks before channel is force closed if closing_signed negotiation stalls.
timer_ticks: i32,
}

/// The number of ticks before the channel is forced closed if
/// no progress on closing_signed negotiation is being made.
/// An unprogressed channel that exceeds this limit will be abandoned.
pub(crate) const UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS: i32 = 1 * TICKS_PER_MINUTE as i32;

#[cfg(any(test, fuzzing))]
struct CommitmentTxInfoCached {
fee: u64,
Expand DownExpand Up@@ -5709,12 +5717,12 @@ impl<SP: Deref> Channel<SP> where

/// Checks if the closing_signed negotiation is making appropriate progress, possibly returning
/// an Err if no progress is being made and the channel should be force-closed instead.
/// Should be called on a one-minute timer.
/// Should be called on a one-second timer.
pub fn timer_check_closing_negotiation_progress(&mut self) -> Result<(), ChannelError> {
if self.closing_negotiation_ready() {
if self.context.closing_signed_in_flight {
return Err(ChannelError::Close("closing_signed negotiation failed to finish within two timer ticks".to_owned()));
} else {
} else if { self.timer_ticks -= 1 ; self.timer_ticks } <= 0 {
self.context.closing_signed_in_flight = true;
}
}
Expand DownExpand Up@@ -7790,6 +7798,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
context: self.context,
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
};

let need_channel_ready = channel.check_get_channel_ready(0).is_some();
Expand DownExpand Up@@ -8080,6 +8089,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
context: self.context,
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
};
let need_channel_ready = channel.check_get_channel_ready(0).is_some();
channel.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
Expand DownExpand Up@@ -9389,6 +9399,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
},
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
})
}
}
Expand Down
12 changes: 8 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -957,7 +957,7 @@ pub(super) struct InboundChannelRequest {

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

/// Stores a PaymentSecret and any other data we may need to validate an inbound payment is
/// actually ours and not some duplicate HTLC sent to us by a node along the route.
Expand DownExpand Up@@ -2259,16 +2259,20 @@ const CHECK_CLTV_EXPIRY_SANITY: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRA
#[allow(dead_code)]
const CHECK_CLTV_EXPIRY_SANITY_2: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - 2*CLTV_CLAIM_BUFFER;

/// Constant that keeps track of the number of times [`ChannelManager::timer_tick_occurred`]
/// is called every minute.
pub const TICKS_PER_MINUTE: u8 = 60;

/// The number of ticks of [`ChannelManager::timer_tick_occurred`] until expiry of incomplete MPPs
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3 * TICKS_PER_MINUTE;

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

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

/// The maximum number of unfunded channels we can have per-peer before we start rejecting new
/// (inbound) ones. The number of peers with unfunded channels is limited separately in
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@
//! Tests of our shutdown and closing_signed negotiation logic as well as some assorted force-close
//! handling tests.

use crate::ln::channel::UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS;
use crate::sign::{EntropySource, SignerProvider};
use crate::chain::ChannelMonitorUpdateStatus;
use crate::chain::transaction::OutPoint;
Expand DownExpand Up@@ -1161,8 +1162,9 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
assert_eq!(nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1);
}

nodes[1].node.timer_tick_occurred();
nodes[1].node.timer_tick_occurred();
for _ in 0..UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS + 1 {
nodes[1].node.timer_tick_occurred();
}

let txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
assert_eq!(txn.len(), 1);
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Make timer_tick_occurred a second long timer by shaavan · Pull Request #3065 · lightningdevkit/rust-lightning · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lightning-background-processor/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ pub struct BackgroundProcessor {
}

#[cfg(not(test))]
const FRESHNESS_TIMER: u64 = 60;
const FRESHNESS_TIMER: u64 = 1;
#[cfg(test)]
const FRESHNESS_TIMER: u64 = 1;

Expand DownExpand Up@@ -933,7 +933,7 @@ mod tests {
use lightning::events::{Event, PathFailure, MessageSendEventsProvider, MessageSendEvent};
use lightning::{get_event_msg, get_event};
use lightning::ln::types::{PaymentHash, ChannelId};
use lightning::ln::channelmanager;
use lightning::ln::channelmanager::{self, TICKS_PER_MINUTE};
use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChainParameters, MIN_CLTV_EXPIRY_DELTA, PaymentId};
use lightning::ln::features::{ChannelFeatures, NodeFeatures};
use lightning::ln::functional_test_utils::*;
Expand All@@ -960,7 +960,7 @@ mod tests {
use lightning_rapid_gossip_sync::RapidGossipSync;
use super::{BackgroundProcessor, GossipSync, FRESHNESS_TIMER};

const EVENT_DEADLINE: u64 = 5 * FRESHNESS_TIMER;
const EVENT_DEADLINE: u64 = 5 * TICKS_PER_MINUTE as u64 * FRESHNESS_TIMER;

#[derive(Clone, Hash, PartialEq, Eq)]
struct TestDescriptor{}
Expand Down
27 changes: 19 additions & 8 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,7 @@ use crate::sync::Mutex;
use crate::sign::type_resolver::ChannelSignerType;

use super::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use super::channelmanager::TICKS_PER_MINUTE;

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

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

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

/// Number of blocks needed for an output from a coinbase transaction to be spendable.
pub(crate) const COINBASE_MATURITY: u32 = 100;
Expand DownExpand Up@@ -3601,8 +3602,15 @@ pub(super) struct Channel<SP: Deref> where SP::Target: SignerProvider {
pub context: ChannelContext<SP>,
#[cfg(any(dual_funding, splicing))]
pub dual_funding_channel_context: Option<DualFundingChannelContext>,
/// Number of ticks before channel is force closed if closing_signed negotiation stalls.
timer_ticks: i32,
}

/// The number of ticks before the channel is forced closed if
/// no progress on closing_signed negotiation is being made.
/// An unprogressed channel that exceeds this limit will be abandoned.
pub(crate) const UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS: i32 = 1 * TICKS_PER_MINUTE as i32;

#[cfg(any(test, fuzzing))]
struct CommitmentTxInfoCached {
fee: u64,
Expand DownExpand Up@@ -5709,12 +5717,12 @@ impl<SP: Deref> Channel<SP> where

/// Checks if the closing_signed negotiation is making appropriate progress, possibly returning
/// an Err if no progress is being made and the channel should be force-closed instead.
/// Should be called on a one-minute timer.
/// Should be called on a one-second timer.
pub fn timer_check_closing_negotiation_progress(&mut self) -> Result<(), ChannelError> {
if self.closing_negotiation_ready() {
if self.context.closing_signed_in_flight {
return Err(ChannelError::Close("closing_signed negotiation failed to finish within two timer ticks".to_owned()));
} else {
} else if { self.timer_ticks -= 1 ; self.timer_ticks } <= 0 {
self.context.closing_signed_in_flight = true;
}
}
Expand DownExpand Up@@ -7790,6 +7798,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
context: self.context,
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
};

let need_channel_ready = channel.check_get_channel_ready(0).is_some();
Expand DownExpand Up@@ -8080,6 +8089,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
context: self.context,
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
};
let need_channel_ready = channel.check_get_channel_ready(0).is_some();
channel.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
Expand DownExpand Up@@ -9389,6 +9399,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
},
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
})
}
}
Expand Down
12 changes: 8 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -957,7 +957,7 @@ pub(super) struct InboundChannelRequest {

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

/// Stores a PaymentSecret and any other data we may need to validate an inbound payment is
/// actually ours and not some duplicate HTLC sent to us by a node along the route.
Expand DownExpand Up@@ -2259,16 +2259,20 @@ const CHECK_CLTV_EXPIRY_SANITY: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRA
#[allow(dead_code)]
const CHECK_CLTV_EXPIRY_SANITY_2: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - 2*CLTV_CLAIM_BUFFER;

/// Constant that keeps track of the number of times [`ChannelManager::timer_tick_occurred`]
/// is called every minute.
pub const TICKS_PER_MINUTE: u8 = 60;

/// The number of ticks of [`ChannelManager::timer_tick_occurred`] until expiry of incomplete MPPs
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3 * TICKS_PER_MINUTE;

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

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

/// The maximum number of unfunded channels we can have per-peer before we start rejecting new
/// (inbound) ones. The number of peers with unfunded channels is limited separately in
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@
//! Tests of our shutdown and closing_signed negotiation logic as well as some assorted force-close
//! handling tests.

use crate::ln::channel::UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS;
use crate::sign::{EntropySource, SignerProvider};
use crate::chain::ChannelMonitorUpdateStatus;
use crate::chain::transaction::OutPoint;
Expand DownExpand Up@@ -1161,8 +1162,9 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
assert_eq!(nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1);
}

nodes[1].node.timer_tick_occurred();
nodes[1].node.timer_tick_occurred();
for _ in 0..UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS + 1 {
nodes[1].node.timer_tick_occurred();
}

let txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
assert_eq!(txn.len(), 1);
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Make timer_tick_occurred a second long timer by shaavan · Pull Request #3065 · lightningdevkit/rust-lightning · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lightning-background-processor/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ pub struct BackgroundProcessor {
}

#[cfg(not(test))]
const FRESHNESS_TIMER: u64 = 60;
const FRESHNESS_TIMER: u64 = 1;
#[cfg(test)]
const FRESHNESS_TIMER: u64 = 1;

Expand DownExpand Up@@ -933,7 +933,7 @@ mod tests {
use lightning::events::{Event, PathFailure, MessageSendEventsProvider, MessageSendEvent};
use lightning::{get_event_msg, get_event};
use lightning::ln::types::{PaymentHash, ChannelId};
use lightning::ln::channelmanager;
use lightning::ln::channelmanager::{self, TICKS_PER_MINUTE};
use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChainParameters, MIN_CLTV_EXPIRY_DELTA, PaymentId};
use lightning::ln::features::{ChannelFeatures, NodeFeatures};
use lightning::ln::functional_test_utils::*;
Expand All@@ -960,7 +960,7 @@ mod tests {
use lightning_rapid_gossip_sync::RapidGossipSync;
use super::{BackgroundProcessor, GossipSync, FRESHNESS_TIMER};

const EVENT_DEADLINE: u64 = 5 * FRESHNESS_TIMER;
const EVENT_DEADLINE: u64 = 5 * TICKS_PER_MINUTE as u64 * FRESHNESS_TIMER;

#[derive(Clone, Hash, PartialEq, Eq)]
struct TestDescriptor{}
Expand Down
27 changes: 19 additions & 8 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,7 @@ use crate::sync::Mutex;
use crate::sign::type_resolver::ChannelSignerType;

use super::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use super::channelmanager::TICKS_PER_MINUTE;

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

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

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

/// Number of blocks needed for an output from a coinbase transaction to be spendable.
pub(crate) const COINBASE_MATURITY: u32 = 100;
Expand DownExpand Up@@ -3601,8 +3602,15 @@ pub(super) struct Channel<SP: Deref> where SP::Target: SignerProvider {
pub context: ChannelContext<SP>,
#[cfg(any(dual_funding, splicing))]
pub dual_funding_channel_context: Option<DualFundingChannelContext>,
/// Number of ticks before channel is force closed if closing_signed negotiation stalls.
timer_ticks: i32,
}

/// The number of ticks before the channel is forced closed if
/// no progress on closing_signed negotiation is being made.
/// An unprogressed channel that exceeds this limit will be abandoned.
pub(crate) const UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS: i32 = 1 * TICKS_PER_MINUTE as i32;

#[cfg(any(test, fuzzing))]
struct CommitmentTxInfoCached {
fee: u64,
Expand DownExpand Up@@ -5709,12 +5717,12 @@ impl<SP: Deref> Channel<SP> where

/// Checks if the closing_signed negotiation is making appropriate progress, possibly returning
/// an Err if no progress is being made and the channel should be force-closed instead.
/// Should be called on a one-minute timer.
/// Should be called on a one-second timer.
pub fn timer_check_closing_negotiation_progress(&mut self) -> Result<(), ChannelError> {
if self.closing_negotiation_ready() {
if self.context.closing_signed_in_flight {
return Err(ChannelError::Close("closing_signed negotiation failed to finish within two timer ticks".to_owned()));
} else {
} else if { self.timer_ticks -= 1 ; self.timer_ticks } <= 0 {
self.context.closing_signed_in_flight = true;
}
}
Expand DownExpand Up@@ -7790,6 +7798,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
context: self.context,
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
};

let need_channel_ready = channel.check_get_channel_ready(0).is_some();
Expand DownExpand Up@@ -8080,6 +8089,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
context: self.context,
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
};
let need_channel_ready = channel.check_get_channel_ready(0).is_some();
channel.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
Expand DownExpand Up@@ -9389,6 +9399,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
},
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
})
}
}
Expand Down
12 changes: 8 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -957,7 +957,7 @@ pub(super) struct InboundChannelRequest {

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

/// Stores a PaymentSecret and any other data we may need to validate an inbound payment is
/// actually ours and not some duplicate HTLC sent to us by a node along the route.
Expand DownExpand Up@@ -2259,16 +2259,20 @@ const CHECK_CLTV_EXPIRY_SANITY: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRA
#[allow(dead_code)]
const CHECK_CLTV_EXPIRY_SANITY_2: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - 2*CLTV_CLAIM_BUFFER;

/// Constant that keeps track of the number of times [`ChannelManager::timer_tick_occurred`]
/// is called every minute.
pub const TICKS_PER_MINUTE: u8 = 60;

/// The number of ticks of [`ChannelManager::timer_tick_occurred`] until expiry of incomplete MPPs
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3 * TICKS_PER_MINUTE;

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

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

/// The maximum number of unfunded channels we can have per-peer before we start rejecting new
/// (inbound) ones. The number of peers with unfunded channels is limited separately in
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@
//! Tests of our shutdown and closing_signed negotiation logic as well as some assorted force-close
//! handling tests.

use crate::ln::channel::UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS;
use crate::sign::{EntropySource, SignerProvider};
use crate::chain::ChannelMonitorUpdateStatus;
use crate::chain::transaction::OutPoint;
Expand DownExpand Up@@ -1161,8 +1162,9 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
assert_eq!(nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1);
}

nodes[1].node.timer_tick_occurred();
nodes[1].node.timer_tick_occurred();
for _ in 0..UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS + 1 {
nodes[1].node.timer_tick_occurred();
}

let txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
assert_eq!(txn.len(), 1);
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Make timer_tick_occurred a second long timer by shaavan · Pull Request #3065 · lightningdevkit/rust-lightning · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lightning-background-processor/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ pub struct BackgroundProcessor {
}

#[cfg(not(test))]
const FRESHNESS_TIMER: u64 = 60;
const FRESHNESS_TIMER: u64 = 1;
#[cfg(test)]
const FRESHNESS_TIMER: u64 = 1;

Expand DownExpand Up@@ -933,7 +933,7 @@ mod tests {
use lightning::events::{Event, PathFailure, MessageSendEventsProvider, MessageSendEvent};
use lightning::{get_event_msg, get_event};
use lightning::ln::types::{PaymentHash, ChannelId};
use lightning::ln::channelmanager;
use lightning::ln::channelmanager::{self, TICKS_PER_MINUTE};
use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChainParameters, MIN_CLTV_EXPIRY_DELTA, PaymentId};
use lightning::ln::features::{ChannelFeatures, NodeFeatures};
use lightning::ln::functional_test_utils::*;
Expand All@@ -960,7 +960,7 @@ mod tests {
use lightning_rapid_gossip_sync::RapidGossipSync;
use super::{BackgroundProcessor, GossipSync, FRESHNESS_TIMER};

const EVENT_DEADLINE: u64 = 5 * FRESHNESS_TIMER;
const EVENT_DEADLINE: u64 = 5 * TICKS_PER_MINUTE as u64 * FRESHNESS_TIMER;

#[derive(Clone, Hash, PartialEq, Eq)]
struct TestDescriptor{}
Expand Down
27 changes: 19 additions & 8 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,7 @@ use crate::sync::Mutex;
use crate::sign::type_resolver::ChannelSignerType;

use super::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
use super::channelmanager::TICKS_PER_MINUTE;

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

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

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

/// Number of blocks needed for an output from a coinbase transaction to be spendable.
pub(crate) const COINBASE_MATURITY: u32 = 100;
Expand DownExpand Up@@ -3601,8 +3602,15 @@ pub(super) struct Channel<SP: Deref> where SP::Target: SignerProvider {
pub context: ChannelContext<SP>,
#[cfg(any(dual_funding, splicing))]
pub dual_funding_channel_context: Option<DualFundingChannelContext>,
/// Number of ticks before channel is force closed if closing_signed negotiation stalls.
timer_ticks: i32,
}

/// The number of ticks before the channel is forced closed if
/// no progress on closing_signed negotiation is being made.
/// An unprogressed channel that exceeds this limit will be abandoned.
pub(crate) const UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS: i32 = 1 * TICKS_PER_MINUTE as i32;

#[cfg(any(test, fuzzing))]
struct CommitmentTxInfoCached {
fee: u64,
Expand DownExpand Up@@ -5709,12 +5717,12 @@ impl<SP: Deref> Channel<SP> where

/// Checks if the closing_signed negotiation is making appropriate progress, possibly returning
/// an Err if no progress is being made and the channel should be force-closed instead.
/// Should be called on a one-minute timer.
/// Should be called on a one-second timer.
pub fn timer_check_closing_negotiation_progress(&mut self) -> Result<(), ChannelError> {
if self.closing_negotiation_ready() {
if self.context.closing_signed_in_flight {
return Err(ChannelError::Close("closing_signed negotiation failed to finish within two timer ticks".to_owned()));
} else {
} else if { self.timer_ticks -= 1 ; self.timer_ticks } <= 0 {
self.context.closing_signed_in_flight = true;
}
}
Expand DownExpand Up@@ -7790,6 +7798,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
context: self.context,
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
};

let need_channel_ready = channel.check_get_channel_ready(0).is_some();
Expand DownExpand Up@@ -8080,6 +8089,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
context: self.context,
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
};
let need_channel_ready = channel.check_get_channel_ready(0).is_some();
channel.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
Expand DownExpand Up@@ -9389,6 +9399,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
},
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
timer_ticks: UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS,
})
}
}
Expand Down
12 changes: 8 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -957,7 +957,7 @@ pub(super) struct InboundChannelRequest {

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

/// Stores a PaymentSecret and any other data we may need to validate an inbound payment is
/// actually ours and not some duplicate HTLC sent to us by a node along the route.
Expand DownExpand Up@@ -2259,16 +2259,20 @@ const CHECK_CLTV_EXPIRY_SANITY: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRA
#[allow(dead_code)]
const CHECK_CLTV_EXPIRY_SANITY_2: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - 2*CLTV_CLAIM_BUFFER;

/// Constant that keeps track of the number of times [`ChannelManager::timer_tick_occurred`]
/// is called every minute.
pub const TICKS_PER_MINUTE: u8 = 60;

/// The number of ticks of [`ChannelManager::timer_tick_occurred`] until expiry of incomplete MPPs
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3 * TICKS_PER_MINUTE;

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

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

/// The maximum number of unfunded channels we can have per-peer before we start rejecting new
/// (inbound) ones. The number of peers with unfunded channels is limited separately in
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/ln/shutdown_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@
//! Tests of our shutdown and closing_signed negotiation logic as well as some assorted force-close
//! handling tests.

use crate::ln::channel::UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS;
use crate::sign::{EntropySource, SignerProvider};
use crate::chain::ChannelMonitorUpdateStatus;
use crate::chain::transaction::OutPoint;
Expand DownExpand Up@@ -1161,8 +1162,9 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
assert_eq!(nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1);
}

nodes[1].node.timer_tick_occurred();
nodes[1].node.timer_tick_occurred();
for _ in 0..UNPROGRESS_CLOSING_SIGNED_NEGOTIATION_AGE_LIMIT_TICKS + 1 {
nodes[1].node.timer_tick_occurred();
}

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