Skip to content

Commit 19b775a

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 fa5b252 commit 19b775a

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
@@ -5465,6 +5465,24 @@ where
54655465
self.counterparty_cur_commitment_point = Some(counterparty_cur_commitment_point_override);
54665466
self.get_initial_counterparty_commitment_signature(funding, logger)
54675467
}
5468+
5469+
fn check_funding_meets_minimum_depth(&self, funding: &mut FundingScope, height: u32) -> bool {
5470+
if funding.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
5471+
return false;
5472+
}
5473+
5474+
let funding_tx_confirmations =
5475+
height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
5476+
if funding_tx_confirmations <= 0 {
5477+
funding.funding_tx_confirmation_height = 0;
5478+
}
5479+
5480+
if funding_tx_confirmations < self.minimum_depth.unwrap_or(0) as i64 {
5481+
return false;
5482+
}
5483+
5484+
return true;
5485+
}
54685486
}
54695487

54705488
// Internal utility functions for channels
@@ -8779,16 +8797,7 @@ where
87798797
// Called:
87808798
// * always when a new block/transactions are confirmed with the new height
87818799
// * when funding is signed with a height of 0
8782-
if self.funding.funding_tx_confirmation_height == 0 && self.context.minimum_depth != Some(0) {
8783-
return None;
8784-
}
8785-
8786-
let funding_tx_confirmations = height as i64 - self.funding.funding_tx_confirmation_height as i64 + 1;
8787-
if funding_tx_confirmations <= 0 {
8788-
self.funding.funding_tx_confirmation_height = 0;
8789-
}
8790-
8791-
if funding_tx_confirmations < self.context.minimum_depth.unwrap_or(0) as i64 {
8800+
if !self.context.check_funding_meets_minimum_depth(&mut self.funding, height) {
87928801
return None;
87938802
}
87948803

0 commit comments

Comments
 (0)