Skip to content

Commit 9342ed3

Browse files
author
Antoine Riard
committed
Document exactly our CLTV sanitization policy for final incoming HTLCs
We want to avoid a third-party channel closure, where a random node by sending us a payment expiring at current height, would trigger our onchain logic to close the channel due to a near-expiration. PaymentReceived and unknown HTLC cancellation must happen before LATENCY_GRACE_PERIOD_BLOCKS.
1 parent 43a197d commit 9342ed3

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

lightning/src/ln/channel.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,8 +1711,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
17111711
return Err(ChannelError::Close("Remote provided CLTV expiry in seconds instead of block height"));
17121712
}
17131713

1714-
//TODO: Check msg.cltv_expiry further? Do this in channel manager?
1715-
17161714
if self.channel_state & ChannelState::LocalShutdownSent as u32 != 0 {
17171715
if let PendingHTLCStatus::Forward(_) = pending_forward_state {
17181716
panic!("ChannelManager shouldn't be trying to add a forwardable HTLC after we've started closing");

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,10 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref> ChannelMan
987987

988988
// OUR PAYMENT!
989989
// final_expiry_too_soon
990+
// Final node can't rely on checking a CLTV_EXPIRY_DELTA which enforces by its own length CLTV_CLAIM_BUFFER so make sure
991+
// we don't accept incoming HTLC we wouldn't have time to claim with a worst-case broadcast scenario
992+
// Also, in case of unknown payment hash, makes sure payment logic has time to fail backward HTLC before our onchain
993+
// logic trigger a channel closure.
990994
if (msg.cltv_expiry as u64) < self.latest_block_height.load(Ordering::Acquire) as u64 + (CLTV_CLAIM_BUFFER + LATENCY_GRACE_PERIOD_BLOCKS) as u64 {
991995
return_err!("The final CLTV expiry is too soon to handle", 17, &[0;0]);
992996
}

lightning/src/util/events.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ pub enum Event {
5252
/// Indicates we've received money! Just gotta dig out that payment preimage and feed it to
5353
/// ChannelManager::claim_funds to get it....
5454
/// Note that if the preimage is not known or the amount paid is incorrect, you must call
55-
/// ChannelManager::fail_htlc_backwards to free up resources for this HTLC.
55+
/// ChannelManager::fail_htlc_backwards to free up resources for this HTLC before
56+
/// LATENCY_GRACE_PERIOD_BLOCKS to avoid any channel-closure by onchain monitoring.
5657
/// The amount paid should be considered 'incorrect' when it is less than or more than twice
5758
/// the amount expected.
5859
PaymentReceived {

0 commit comments

Comments
 (0)