Skip to content

Commit 1905570

Browse files
committed
Clarify when height is the *current* vs a *confirmation* height
1 parent 496eb45 commit 1905570

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ impl OnchainEventEntry {
370370
conf_threshold
371371
}
372372

373-
fn has_reached_confirmation_threshold(&self, height: u32) -> bool {
374-
height >= self.confirmation_threshold()
373+
fn has_reached_confirmation_threshold(&self, best_block: &BestBlock) -> bool {
374+
best_block.height() >= self.confirmation_threshold()
375375
}
376376
}
377377

@@ -1856,7 +1856,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
18561856
} else if htlc.0.cltv_expiry > self.best_block.height() + 1 {
18571857
// Don't broadcast HTLC-Timeout transactions immediately as they don't meet the
18581858
// current locktime requirements on-chain. We will broadcast them in
1859-
// `block_confirmed` when `would_broadcast_at_height` returns true.
1859+
// `block_confirmed` when `should_broadcast_holder_commitment_txn` returns true.
18601860
// Note that we add + 1 as transactions are broadcastable when they can be
18611861
// confirmed in the next block.
18621862
continue;
@@ -2035,7 +2035,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
20352035
{
20362036
debug_assert!(self.best_block.height() >= conf_height);
20372037

2038-
let should_broadcast = self.would_broadcast_at_height(self.best_block.height(), logger);
2038+
let should_broadcast = self.should_broadcast_holder_commitment_txn(logger);
20392039
if should_broadcast {
20402040
let funding_outp = HolderFundingOutput::build(self.funding_redeemscript.clone());
20412041
let commitment_package = PackageTemplate::build_package(self.funding_info.0.txid.clone(), self.funding_info.0.index as u32, PackageSolvingData::HolderFundingOutput(funding_outp), self.best_block.height(), false, self.best_block.height());
@@ -2056,7 +2056,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
20562056
self.onchain_events_awaiting_threshold_conf.drain(..).collect::<Vec<_>>();
20572057
let mut onchain_events_reaching_threshold_conf = Vec::new();
20582058
for entry in onchain_events_awaiting_threshold_conf {
2059-
if entry.has_reached_confirmation_threshold(self.best_block.height()) {
2059+
if entry.has_reached_confirmation_threshold(&self.best_block) {
20602060
onchain_events_reaching_threshold_conf.push(entry);
20612061
} else {
20622062
self.onchain_events_awaiting_threshold_conf.push(entry);
@@ -2213,7 +2213,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
22132213
false
22142214
}
22152215

2216-
fn would_broadcast_at_height<L: Deref>(&self, height: u32, logger: &L) -> bool where L::Target: Logger {
2216+
fn should_broadcast_holder_commitment_txn<L: Deref>(&self, logger: &L) -> bool where L::Target: Logger {
22172217
// We need to consider all HTLCs which are:
22182218
// * in any unrevoked counterparty commitment transaction, as they could broadcast said
22192219
// transactions and we'd end up in a race, or
@@ -2224,6 +2224,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
22242224
// to the source, and if we don't fail the channel we will have to ensure that the next
22252225
// updates that peer sends us are update_fails, failing the channel if not. It's probably
22262226
// easier to just fail the channel as this case should be rare enough anyway.
2227+
let height = self.best_block.height();
22272228
macro_rules! scan_commitment {
22282229
($htlcs: expr, $holder_tx: expr) => {
22292230
for ref htlc in $htlcs {

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ enum InboundHTLCState {
114114
/// commitment transaction without it as otherwise we'll have to force-close the channel to
115115
/// claim it before the timeout (obviously doesn't apply to revoked HTLCs that we can't claim
116116
/// anyway). That said, ChannelMonitor does this for us (see
117-
/// ChannelMonitor::would_broadcast_at_height) so we actually remove the HTLC from our own
118-
/// local state before then, once we're sure that the next commitment_signed and
117+
/// ChannelMonitor::should_broadcast_holder_commitment_txn) so we actually remove the HTLC from
118+
/// our own local state before then, once we're sure that the next commitment_signed and
119119
/// ChannelMonitor::provide_latest_local_commitment_tx will not include this HTLC.
120120
LocalRemoved(InboundHTLCRemovalReason),
121121
}

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ pub const MIN_FINAL_CLTV_EXPIRY: u32 = HTLC_FAIL_BACK_BUFFER + 3;
626626
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;
627627

628628
// Check for ability of an attacker to make us fail on-chain by delaying an HTLC claim. See
629-
// ChannelMontior::would_broadcast_at_height for a description of why this is needed.
629+
// ChannelMonitor::should_broadcast_holder_commitment_txn for a description of why this is needed.
630630
#[deny(const_err)]
631631
#[allow(dead_code)]
632632
const CHECK_CLTV_EXPIRY_SANITY_2: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - 2*CLTV_CLAIM_BUFFER;

0 commit comments

Comments
 (0)