Skip to content

Commit eaff313

Browse files
committed
Clarify when height is the *current* vs a *confirmation* height
1 parent 642f5af commit eaff313

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;
@@ -2030,7 +2030,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
20302030
F::Target: FeeEstimator,
20312031
L::Target: Logger,
20322032
{
2033-
let should_broadcast = self.would_broadcast_at_height(self.best_block.height(), logger);
2033+
let should_broadcast = self.should_broadcast(logger);
20342034
if should_broadcast {
20352035
let funding_outp = HolderFundingOutput::build(self.funding_redeemscript.clone());
20362036
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());
@@ -2051,7 +2051,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
20512051
self.onchain_events_awaiting_threshold_conf.drain(..).collect::<Vec<_>>();
20522052
let mut onchain_events_reaching_threshold_conf = Vec::new();
20532053
for entry in onchain_events_awaiting_threshold_conf {
2054-
if entry.has_reached_confirmation_threshold(self.best_block.height()) {
2054+
if entry.has_reached_confirmation_threshold(&self.best_block) {
20552055
onchain_events_reaching_threshold_conf.push(entry);
20562056
} else {
20572057
self.onchain_events_awaiting_threshold_conf.push(entry);
@@ -2209,7 +2209,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
22092209
false
22102210
}
22112211

2212-
fn would_broadcast_at_height<L: Deref>(&self, height: u32, logger: &L) -> bool where L::Target: Logger {
2212+
fn should_broadcast<L: Deref>(&self, logger: &L) -> bool where L::Target: Logger {
22132213
// We need to consider all HTLCs which are:
22142214
// * in any unrevoked counterparty commitment transaction, as they could broadcast said
22152215
// transactions and we'd end up in a race, or
@@ -2220,6 +2220,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
22202220
// to the source, and if we don't fail the channel we will have to ensure that the next
22212221
// updates that peer sends us are update_fails, failing the channel if not. It's probably
22222222
// easier to just fail the channel as this case should be rare enough anyway.
2223+
let height = self.best_block.height();
22232224
macro_rules! scan_commitment {
22242225
($htlcs: expr, $holder_tx: expr) => {
22252226
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)