Skip to content

Commit 9d7a0e6

Browse files
committed
Refactor funding tx confirmation check into helper
When checking if channel_ready should be sent, the funding transaction must reach minimum_depth confirmations. The same logic is needed for splicing a channel, so refactor it into a helper method.
1 parent 3c53384 commit 9d7a0e6

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

lightning/src/ln/channel.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5255,6 +5255,23 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
52555255
self.counterparty_cur_commitment_point = Some(counterparty_cur_commitment_point_override);
52565256
self.get_initial_counterparty_commitment_signature(funding, logger)
52575257
}
5258+
5259+
fn check_funding_meets_minimum_depth(&self, funding: &mut FundingScope, height: u32) -> bool {
5260+
if funding.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
5261+
return false;
5262+
}
5263+
5264+
let funding_tx_confirmations = height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
5265+
if funding_tx_confirmations <= 0 {
5266+
funding.funding_tx_confirmation_height = 0;
5267+
}
5268+
5269+
if funding_tx_confirmations < self.minimum_depth.unwrap_or(0) as i64 {
5270+
return false;
5271+
}
5272+
5273+
return true;
5274+
}
52585275
}
52595276

52605277
// Internal utility functions for channels
@@ -8459,16 +8476,7 @@ impl<SP: Deref> FundedChannel<SP> where
84598476
// Called:
84608477
// * always when a new block/transactions are confirmed with the new height
84618478
// * when funding is signed with a height of 0
8462-
if self.funding.funding_tx_confirmation_height == 0 && self.context.minimum_depth != Some(0) {
8463-
return None;
8464-
}
8465-
8466-
let funding_tx_confirmations = height as i64 - self.funding.funding_tx_confirmation_height as i64 + 1;
8467-
if funding_tx_confirmations <= 0 {
8468-
self.funding.funding_tx_confirmation_height = 0;
8469-
}
8470-
8471-
if funding_tx_confirmations < self.context.minimum_depth.unwrap_or(0) as i64 {
8479+
if !self.context.check_funding_meets_minimum_depth(&mut self.funding, height) {
84728480
return None;
84738481
}
84748482

0 commit comments

Comments
 (0)