Skip to content

Commit a3bf741

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 dbd677b commit a3bf741

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

lightning/src/ln/channel.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5453,6 +5453,24 @@ where
54535453
self.counterparty_cur_commitment_point = Some(counterparty_cur_commitment_point_override);
54545454
self.get_initial_counterparty_commitment_signature(funding, logger)
54555455
}
5456+
5457+
fn check_funding_meets_minimum_depth(&self, funding: &mut FundingScope, height: u32) -> bool {
5458+
if funding.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
5459+
return false;
5460+
}
5461+
5462+
let funding_tx_confirmations =
5463+
height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
5464+
if funding_tx_confirmations <= 0 {
5465+
funding.funding_tx_confirmation_height = 0;
5466+
}
5467+
5468+
if funding_tx_confirmations < self.minimum_depth.unwrap_or(0) as i64 {
5469+
return false;
5470+
}
5471+
5472+
return true;
5473+
}
54565474
}
54575475

54585476
// Internal utility functions for channels
@@ -8735,16 +8753,7 @@ where
87358753
// Called:
87368754
// * always when a new block/transactions are confirmed with the new height
87378755
// * when funding is signed with a height of 0
8738-
if self.funding.funding_tx_confirmation_height == 0 && self.context.minimum_depth != Some(0) {
8739-
return None;
8740-
}
8741-
8742-
let funding_tx_confirmations = height as i64 - self.funding.funding_tx_confirmation_height as i64 + 1;
8743-
if funding_tx_confirmations <= 0 {
8744-
self.funding.funding_tx_confirmation_height = 0;
8745-
}
8746-
8747-
if funding_tx_confirmations < self.context.minimum_depth.unwrap_or(0) as i64 {
8756+
if !self.context.check_funding_meets_minimum_depth(&mut self.funding, height) {
87488757
return None;
87498758
}
87508759

0 commit comments

Comments
 (0)