Skip to content

Commit 9b5d5c3

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 5f3411a commit 9b5d5c3

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
@@ -4849,6 +4849,23 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
48494849
self.counterparty_cur_commitment_point = Some(counterparty_cur_commitment_point_override);
48504850
self.get_initial_counterparty_commitment_signature(funding, logger)
48514851
}
4852+
4853+
fn check_funding_confirmations(&self, funding: &mut FundingScope, height: u32) -> bool {
4854+
if funding.funding_tx_confirmation_height == 0 && self.minimum_depth != Some(0) {
4855+
return false;
4856+
}
4857+
4858+
let funding_tx_confirmations = height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
4859+
if funding_tx_confirmations <= 0 {
4860+
funding.funding_tx_confirmation_height = 0;
4861+
}
4862+
4863+
if funding_tx_confirmations < self.minimum_depth.unwrap_or(0) as i64 {
4864+
return false;
4865+
}
4866+
4867+
return true;
4868+
}
48524869
}
48534870

48544871
// Internal utility functions for channels
@@ -8079,16 +8096,7 @@ impl<SP: Deref> FundedChannel<SP> where
80798096
// Called:
80808097
// * always when a new block/transactions are confirmed with the new height
80818098
// * when funding is signed with a height of 0
8082-
if self.funding.funding_tx_confirmation_height == 0 && self.context.minimum_depth != Some(0) {
8083-
return None;
8084-
}
8085-
8086-
let funding_tx_confirmations = height as i64 - self.funding.funding_tx_confirmation_height as i64 + 1;
8087-
if funding_tx_confirmations <= 0 {
8088-
self.funding.funding_tx_confirmation_height = 0;
8089-
}
8090-
8091-
if funding_tx_confirmations < self.context.minimum_depth.unwrap_or(0) as i64 {
8099+
if !self.context.check_funding_confirmations(&mut self.funding, height) {
80928100
return None;
80938101
}
80948102

0 commit comments

Comments
 (0)