@@ -2840,19 +2840,34 @@ pub(super) const CLTV_FAR_FAR_AWAY: u32 = 14 * 24 * 6;
28402840// a payment was being routed, so we add an extra block to be safe.
28412841pub const MIN_FINAL_CLTV_EXPIRY_DELTA: u16 = HTLC_FAIL_BACK_BUFFER as u16 + 3;
28422842
2843- // Check that our CLTV_EXPIRY is at least CLTV_CLAIM_BUFFER + ANTI_REORG_DELAY + LATENCY_GRACE_PERIOD_BLOCKS,
2844- // ie that if the next-hop peer fails the HTLC within
2845- // LATENCY_GRACE_PERIOD_BLOCKS then we'll still have CLTV_CLAIM_BUFFER left to timeout it onchain,
2846- // then waiting ANTI_REORG_DELAY to be reorg-safe on the outbound HLTC and
2847- // failing the corresponding htlc backward, and us now seeing the last block of ANTI_REORG_DELAY before
2848- // LATENCY_GRACE_PERIOD_BLOCKS.
2849- #[allow(dead_code)]
2850- const CHECK_CLTV_EXPIRY_SANITY: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - CLTV_CLAIM_BUFFER - ANTI_REORG_DELAY - LATENCY_GRACE_PERIOD_BLOCKS;
2851-
2852- // Check for ability of an attacker to make us fail on-chain by delaying an HTLC claim. See
2853- // ChannelMonitor::should_broadcast_holder_commitment_txn for a description of why this is needed.
2854- #[allow(dead_code)]
2855- const CHECK_CLTV_EXPIRY_SANITY_2: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - 2*CLTV_CLAIM_BUFFER;
2843+ // Check that our MIN_CLTV_EXPIRY_DELTA gives us enough time to get everything on chain and locked
2844+ // in with enough time left to fail the corresponding HTLC back to our inbound edge before they
2845+ // force-close on us.
2846+ // In other words, if the next-hop peer fails HTLC LATENCY_GRACE_PERIOD_BLOCKS after our
2847+ // CLTV_CLAIM_BUFFER (because that's how many blocks we allow them after expiry), we'll still have
2848+ // CLTV_CLAIM_BUFFER + ANTI_REORG_DELAY left to get two transactions on chain and the second
2849+ // fully locked in before the peer force-closes on us (LATENCY_GRACE_PERIOD_BLOCKS before the
2850+ // expiry, i.e. assuming the peer force-closes right at the expiry and we're behind by
2851+ // LATENCY_GRACE_PERIOD_BLOCKS).
2852+ const _CHECK_CLTV_EXPIRY_SANITY: () = assert!(
2853+ MIN_CLTV_EXPIRY_DELTA as u32 >= 2*LATENCY_GRACE_PERIOD_BLOCKS + CLTV_CLAIM_BUFFER + ANTI_REORG_DELAY
2854+ );
2855+
2856+ // Check that our MIN_CLTV_EXPIRY_DELTA gives us enough time to get the HTLC preimage back to our
2857+ // counterparty if the outbound edge gives us the preimage only one block before we'd force-close
2858+ // the channel.
2859+ // ie they provide the preimage LATENCY_GRACE_PERIOD_BLOCKS - 1 after the HTLC expires, then we
2860+ // pass the preimage back, which takes LATENCY_GRACE_PERIOD_BLOCKS to complete, and we want to make
2861+ // sure this all happens at least N blocks before the inbound HTLC expires (where N is the
2862+ // counterparty's CLTV_CLAIM_BUFFER or equivalent).
2863+ const _ASSUMED_COUNTERPARTY_CLTV_CLAIM_BUFFER: u32 = 6 * 6;
2864+
2865+ const _CHECK_COUNTERPARTY_REALISTIC: () =
2866+ assert!(_ASSUMED_COUNTERPARTY_CLTV_CLAIM_BUFFER >= CLTV_CLAIM_BUFFER);
2867+
2868+ const _CHECK_CLTV_EXPIRY_OFFCHAIN: () = assert!(
2869+ MIN_CLTV_EXPIRY_DELTA as u32 >= 2*LATENCY_GRACE_PERIOD_BLOCKS - 1 + _ASSUMED_COUNTERPARTY_CLTV_CLAIM_BUFFER
2870+ );
28562871
28572872/// The number of ticks of [`ChannelManager::timer_tick_occurred`] until expiry of incomplete MPPs
28582873pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
0 commit comments