Skip to content

Commit 233d2a1

Browse files
committed
Add constant for HTLC failure anti-reorg delay
1 parent 6f57c17 commit 233d2a1

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/ln/channelmanager.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use secp256k1;
2222
use chain::chaininterface::{BroadcasterInterface,ChainListener,ChainWatchInterface,FeeEstimator};
2323
use chain::transaction::OutPoint;
2424
use ln::channel::{Channel, ChannelError};
25-
use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, ManyChannelMonitor, CLTV_CLAIM_BUFFER, HTLC_FAIL_TIMEOUT_BLOCKS};
25+
use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, ManyChannelMonitor, CLTV_CLAIM_BUFFER, HTLC_FAIL_TIMEOUT_BLOCKS, HTLC_FAIL_ANTI_REORG_DELAY};
2626
use ln::router::{Route,RouteHop};
2727
use ln::msgs;
2828
use ln::msgs::{ChannelMessageHandler, DecodeError, HandleError};
@@ -341,16 +341,17 @@ pub struct ChannelManager {
341341
/// ie the node we forwarded the payment on to should always have enough room to reliably time out
342342
/// the HTLC via a full update_fail_htlc/commitment_signed dance before we hit the
343343
/// CLTV_CLAIM_BUFFER point (we static assert that its at least 3 blocks more).
344-
const CLTV_EXPIRY_DELTA: u16 = 6 * 24 * 2; //TODO?
344+
const CLTV_EXPIRY_DELTA: u16 = 6 * 12; //TODO?
345345
const CLTV_FAR_FAR_AWAY: u32 = 6 * 24 * 7; //TODO?
346346

347-
// Check that our CLTV_EXPIRY is at least CLTV_CLAIM_BUFFER + 2*HTLC_FAIL_TIMEOUT_BLOCKS, ie that
348-
// if the next-hop peer fails the HTLC within HTLC_FAIL_TIMEOUT_BLOCKS then we'll still have
349-
// HTLC_FAIL_TIMEOUT_BLOCKS left to fail it backwards ourselves before hitting the
350-
// CLTV_CLAIM_BUFFER point and failing the channel on-chain to time out the HTLC.
347+
// Check that our CLTV_EXPIRY is at least CLTV_CLAIM_BUFFER + 2*HTLC_FAIL_TIMEOUT_BLOCKS +
348+
// HTLC_FAIL_ANTI_REORG_DELAY, ie that if the next-hop peer fails the HTLC within
349+
// HTLC_FAIL_TIMEOUT_BLOCKS then we'll still have HTLC_FAIL_TIMEOUT_BLOCKS left to fail it
350+
// backwards ourselves before hitting the CLTV_CLAIM_BUFFER point and failing the channel
351+
// on-chain to time out the HTLC.
351352
#[deny(const_err)]
352353
#[allow(dead_code)]
353-
const CHECK_CLTV_EXPIRY_SANITY: u32 = CLTV_EXPIRY_DELTA as u32 - 2*HTLC_FAIL_TIMEOUT_BLOCKS - CLTV_CLAIM_BUFFER;
354+
const CHECK_CLTV_EXPIRY_SANITY: u32 = CLTV_EXPIRY_DELTA as u32 - 2*HTLC_FAIL_TIMEOUT_BLOCKS - CLTV_CLAIM_BUFFER - HTLC_FAIL_ANTI_REORG_DELAY;
354355

355356
// Check for ability of an attacker to make us fail on-chain by delaying inbound claim. See
356357
// ChannelMontior::would_broadcast_at_height for a description of why this is needed.

src/ln/channelmonitor.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ pub(crate) const CLTV_CLAIM_BUFFER: u32 = 6;
295295
/// network and done a full update_fail_htlc/commitment_signed dance (+ we've updated all our
296296
/// copies of ChannelMonitors, including watchtowers).
297297
pub(crate) const HTLC_FAIL_TIMEOUT_BLOCKS: u32 = 3;
298+
/// Number of blocks we wait on seeing a confirmed HTLC-Timeout or previous revoked commitment
299+
/// transaction before we fail corresponding inbound HTLCs. This prevents us from failing backwards
300+
/// and then getting a reorg resulting in us losing money.
301+
//TODO: We currently dont actually use this...we should
302+
pub(crate) const HTLC_FAIL_ANTI_REORG_DELAY: u32 = 6;
298303

299304
#[derive(Clone, PartialEq)]
300305
enum Storage {

0 commit comments

Comments
 (0)