Skip to content

Commit ccf8d44

Browse files
committed
Correct confirmation target constant definitions
`CLTV_CLAIM_BUFFER`'s definition stated "this is an upper bound on how many blocks we think it can take us to get a transaction confirmed". This was mostly okay for pre-anchor channels, where we broadcasted HTLC claim transactions at the same time as the commitment transactions themselves, but for anchor channels we can no longer do that - HTLC transactions are always CSV 1'd. Further, when we do go to broadcast HTLC transactions, we start the feerate estimate for them back at the users' feerate estimator, rather than whatever feerate we ended up using to get the commitment transaction confirmed. While we should maybe consider changing that, for now that means that we really need to run the whole "get a transaction confirmed" process from start to finish *twice* in order to claim an HTLC. Thus, `CLTV_CLAIM_BUFFER` is here redefined to be two times "the upper bound on how many blocks we think it can take for us to get a transaction confirmed", with a new `MAX_BLOCKS_FOR_CONF` constant defining the expected max blocks.
1 parent ac74d96 commit ccf8d44

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lightning/src/chain/channelmonitor.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,15 @@ pub(crate) const COUNTERPARTY_CLAIMABLE_WITHIN_BLOCKS_PINNABLE: u32 = 12;
228228
/// expiring at the same time.
229229
const _: () = assert!(CLTV_CLAIM_BUFFER > COUNTERPARTY_CLAIMABLE_WITHIN_BLOCKS_PINNABLE);
230230

231+
/// The upper bound on how many blocks we think it can take for us to get a transaction confirmed.
232+
pub(crate) const MAX_BLOCKS_FOR_CONF: u32 = 9;
233+
231234
/// If an HTLC expires within this many blocks, force-close the channel to broadcast the
232235
/// HTLC-Success transaction.
233-
/// In other words, this is an upper bound on how many blocks we think it can take us to get a
234-
/// transaction confirmed (and we use it in a few more, equivalent, places).
235-
pub(crate) const CLTV_CLAIM_BUFFER: u32 = 18;
236+
///
237+
/// This is two times [`MAX_BLOCKS_FOR_CONF`] as we need to first get the commitment transaction
238+
/// confirmed, then get an HTLC transaction confirmed.
239+
pub(crate) const CLTV_CLAIM_BUFFER: u32 = MAX_BLOCKS_FOR_CONF * 2;
236240
/// Number of blocks by which point we expect our counterparty to have seen new blocks on the
237241
/// network and done a full update_fail_htlc/commitment_signed dance (+ we've updated all our
238242
/// copies of ChannelMonitors, including watchtowers). We could enforce the contract by failing

lightning/src/ln/channelmanager.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use crate::blinded_path::payment::{AsyncBolt12OfferContext, BlindedPaymentPath,
4040
use crate::chain;
4141
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
4242
use crate::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
43-
use crate::chain::channelmonitor::{Balance, ChannelMonitor, ChannelMonitorUpdate, WithChannelMonitor, ChannelMonitorUpdateStep, HTLC_FAIL_BACK_BUFFER, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY, MonitorEvent};
43+
use crate::chain::channelmonitor::{Balance, ChannelMonitor, ChannelMonitorUpdate, WithChannelMonitor, ChannelMonitorUpdateStep, HTLC_FAIL_BACK_BUFFER, MAX_BLOCKS_FOR_CONF, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY, MonitorEvent};
4444
use crate::chain::transaction::{OutPoint, TransactionData};
4545
use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFunds, ClosureReason, HTLCDestination, PaymentFailureReason, ReplayEvent};
4646
// Since this struct is returned in `list_channels` methods, expose it here in case users want to
@@ -2855,12 +2855,12 @@ pub const MIN_FINAL_CLTV_EXPIRY_DELTA: u16 = HTLC_FAIL_BACK_BUFFER as u16 + 3;
28552855
// force-close on us.
28562856
// In other words, if the next-hop peer fails HTLC LATENCY_GRACE_PERIOD_BLOCKS after our
28572857
// CLTV_CLAIM_BUFFER (because that's how many blocks we allow them after expiry), we'll still have
2858-
// CLTV_CLAIM_BUFFER + ANTI_REORG_DELAY left to get two transactions on chain and the second
2858+
// 2*MAX_BLOCKS_FOR_CONF + ANTI_REORG_DELAY left to get two transactions on chain and the second
28592859
// fully locked in before the peer force-closes on us (LATENCY_GRACE_PERIOD_BLOCKS before the
28602860
// expiry, i.e. assuming the peer force-closes right at the expiry and we're behind by
28612861
// LATENCY_GRACE_PERIOD_BLOCKS).
28622862
const _CHECK_CLTV_EXPIRY_SANITY: () = assert!(
2863-
MIN_CLTV_EXPIRY_DELTA as u32 >= 2*LATENCY_GRACE_PERIOD_BLOCKS + CLTV_CLAIM_BUFFER + ANTI_REORG_DELAY
2863+
MIN_CLTV_EXPIRY_DELTA as u32 >= 2*LATENCY_GRACE_PERIOD_BLOCKS + 2*MAX_BLOCKS_FOR_CONF + ANTI_REORG_DELAY
28642864
);
28652865

28662866
// Check that our MIN_CLTV_EXPIRY_DELTA gives us enough time to get the HTLC preimage back to our

0 commit comments

Comments
 (0)