Skip to content

Commit dd0164a

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 fc88b9f commit dd0164a

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
@@ -5003,6 +5003,23 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
50035003
self.counterparty_cur_commitment_point = Some(counterparty_cur_commitment_point_override);
50045004
self.get_initial_counterparty_commitment_signature(funding, logger)
50055005
}
5006+
5007+
fn check_funding_meets_minimum_depth(&self, funding: &mut FundingScope, height: u32) -> bool {
5008+
if funding.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
5009+
return false;
5010+
}
5011+
5012+
let funding_tx_confirmations = height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
5013+
if funding_tx_confirmations <= 0 {
5014+
funding.funding_tx_confirmation_height = 0;
5015+
}
5016+
5017+
if funding_tx_confirmations < self.minimum_depth.unwrap_or(0) as i64 {
5018+
return false;
5019+
}
5020+
5021+
return true;
5022+
}
50065023
}
50075024

50085025
// Internal utility functions for channels
@@ -8340,16 +8357,7 @@ impl<SP: Deref> FundedChannel<SP> where
83408357
// Called:
83418358
// * always when a new block/transactions are confirmed with the new height
83428359
// * when funding is signed with a height of 0
8343-
if self.funding.funding_tx_confirmation_height == 0 && self.context.minimum_depth != Some(0) {
8344-
return None;
8345-
}
8346-
8347-
let funding_tx_confirmations = height as i64 - self.funding.funding_tx_confirmation_height as i64 + 1;
8348-
if funding_tx_confirmations <= 0 {
8349-
self.funding.funding_tx_confirmation_height = 0;
8350-
}
8351-
8352-
if funding_tx_confirmations < self.context.minimum_depth.unwrap_or(0) as i64 {
8360+
if !self.context.check_funding_meets_minimum_depth(&mut self.funding, height) {
83538361
return None;
83548362
}
83558363

0 commit comments

Comments
 (0)