Skip to content

Commit 850460d

Browse files
author
Antoine Riard
committed
Move get_height_timer out of OnchainTxHandler
1 parent c406a74 commit 850460d

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

lightning/src/chain/onchain_utils.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,3 +868,17 @@ pub(crate) fn compute_output_value<F: Deref, L: Deref>(predicted_weight: usize,
868868
}
869869
None
870870
}
871+
872+
/// In LN, output claimed are time-sensitive, which means we have to spend them before reaching some timelock expiration. At in-channel
873+
/// output detection, we generate a first version of a claim tx and associate to it a height timer. A height timer is an absolute block
874+
/// height than once reached we should generate a new bumped "version" of the claim tx to be sure than we safely claim outputs before
875+
/// than our counterparty can do it too. If timelock expires soon, height timer is going to be scale down in consequence to increase
876+
/// frequency of the bump and so increase our bets of success.
877+
pub(crate) fn get_height_timer(current_height: u32, timelock_expiration: u32) -> u32 {
878+
if timelock_expiration <= current_height + 3 {
879+
return current_height + 1
880+
} else if timelock_expiration - current_height <= 15 {
881+
return current_height + 3
882+
}
883+
current_height + 15
884+
}

lightning/src/chain/onchaintx.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -321,20 +321,6 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
321321
}
322322
}
323323

324-
/// In LN, output claimed are time-sensitive, which means we have to spend them before reaching some timelock expiration. At in-channel
325-
/// output detection, we generate a first version of a claim tx and associate to it a height timer. A height timer is an absolute block
326-
/// height than once reached we should generate a new bumped "version" of the claim tx to be sure than we safely claim outputs before
327-
/// than our counterparty can do it too. If timelock expires soon, height timer is going to be scale down in consequence to increase
328-
/// frequency of the bump and so increase our bets of success.
329-
fn get_height_timer(current_height: u32, timelock_expiration: u32) -> u32 {
330-
if timelock_expiration <= current_height + 3 {
331-
return current_height + 1
332-
} else if timelock_expiration - current_height <= 15 {
333-
return current_height + 3
334-
}
335-
current_height + 15
336-
}
337-
338324
/// Lightning security model (i.e being able to redeem/timeout HTLC or penalize coutnerparty onchain) lays on the assumption of claim transactions getting confirmed before timelock expiration
339325
/// (CSV or CLTV following cases). In case of high-fee spikes, claim tx may stuck in the mempool, so you need to bump its feerate quickly using Replace-By-Fee or Child-Pay-For-Parent.
340326
/// Panics if there are signing errors, because signing operations in reaction to on-chain events
@@ -347,7 +333,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
347333

348334
// Compute new height timer to decide when we need to regenerate a new bumped version of the claim tx (if we
349335
// didn't receive confirmation of it before, or not enough reorg-safe depth on top of it).
350-
let new_timer = Some(Self::get_height_timer(height, cached_request.timelock()));
336+
let new_timer = Some(onchain_utils::get_height_timer(height, cached_request.timelock()));
351337
let amt = cached_request.package_amount();
352338
if cached_request.is_malleable() {
353339
let predicted_weight = cached_request.package_weight(&self.destination_script);

0 commit comments

Comments
 (0)