Skip to content

Commit a4766dc

Browse files
committed
Clarify when height is the *current* vs a *confirmation* height
1 parent a8c425a commit a4766dc

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
@@ -372,8 +372,8 @@ impl OnchainEventEntry {
372372
conf_threshold
373373
}
374374

375-
fn has_reached_confirmation_threshold(&self, height: u32) -> bool {
376-
height >= self.confirmation_threshold()
375+
fn has_reached_confirmation_threshold(&self, best_block: &BestBlock) -> bool {
376+
best_block.height() >= self.confirmation_threshold()
377377
}
378378
}
379379

@@ -1860,7 +1860,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
18601860
} else if htlc.0.cltv_expiry > self.best_block.height() + 1 {
18611861
// Don't broadcast HTLC-Timeout transactions immediately as they don't meet the
18621862
// current locktime requirements on-chain. We will broadcast them in
1863-
// `block_confirmed` when `would_broadcast_at_height` returns true.
1863+
// `block_confirmed` when `should_broadcast` returns true.
18641864
// Note that we add + 1 as transactions are broadcastable when they can be
18651865
// confirmed in the next block.
18661866
continue;
@@ -2035,7 +2035,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
20352035
F::Target: FeeEstimator,
20362036
L::Target: Logger,
20372037
{
2038-
let should_broadcast = self.would_broadcast_at_height(self.best_block.height(), logger);
2038+
let should_broadcast = self.should_broadcast(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);
@@ -2214,7 +2214,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
22142214
false
22152215
}
22162216

2217-
fn would_broadcast_at_height<L: Deref>(&self, height: u32, logger: &L) -> bool where L::Target: Logger {
2217+
fn should_broadcast<L: Deref>(&self, logger: &L) -> bool where L::Target: Logger {
22182218
// We need to consider all HTLCs which are:
22192219
// * in any unrevoked counterparty commitment transaction, as they could broadcast said
22202220
// transactions and we'd end up in a race, or
@@ -2225,6 +2225,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
22252225
// to the source, and if we don't fail the channel we will have to ensure that the next
22262226
// updates that peer sends us are update_fails, failing the channel if not. It's probably
22272227
// easier to just fail the channel as this case should be rare enough anyway.
2228+
let height = self.best_block.height();
22282229
macro_rules! scan_commitment {
22292230
($htlcs: expr, $holder_tx: expr) => {
22302231
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) so we actually remove the HTLC from our own local state
118+
/// 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+
// ChannelMontior::should_broadcast 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)