Skip to content

Commit a64922b

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 801b58d commit a64922b

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
@@ -4854,6 +4854,23 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
48544854
self.counterparty_cur_commitment_point = Some(counterparty_cur_commitment_point_override);
48554855
self.get_initial_counterparty_commitment_signature(funding, logger)
48564856
}
4857+
4858+
fn check_funding_confirmations(&self, funding: &mut FundingScope, height: u32) -> bool {
4859+
if funding.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
4860+
return false;
4861+
}
4862+
4863+
let funding_tx_confirmations = height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
4864+
if funding_tx_confirmations <= 0 {
4865+
funding.funding_tx_confirmation_height = 0;
4866+
}
4867+
4868+
if funding_tx_confirmations < self.minimum_depth.unwrap_or(0) as i64 {
4869+
return false;
4870+
}
4871+
4872+
return true;
4873+
}
48574874
}
48584875

48594876
// Internal utility functions for channels
@@ -8084,16 +8101,7 @@ impl<SP: Deref> FundedChannel<SP> where
80848101
// Called:
80858102
// * always when a new block/transactions are confirmed with the new height
80868103
// * when funding is signed with a height of 0
8087-
if self.funding.funding_tx_confirmation_height == 0 && self.context.minimum_depth != Some(0) {
8088-
return None;
8089-
}
8090-
8091-
let funding_tx_confirmations = height as i64 - self.funding.funding_tx_confirmation_height as i64 + 1;
8092-
if funding_tx_confirmations <= 0 {
8093-
self.funding.funding_tx_confirmation_height = 0;
8094-
}
8095-
8096-
if funding_tx_confirmations < self.context.minimum_depth.unwrap_or(0) as i64 {
8104+
if !self.context.check_funding_confirmations(&mut self.funding, height) {
80978105
return None;
80988106
}
80998107

0 commit comments

Comments
 (0)