Skip to content

Commit 6bbbce8

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 4b4ce81 commit 6bbbce8

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

lightning/src/ln/channel.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -4864,6 +4864,23 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
48644864
self.counterparty_cur_commitment_point = Some(counterparty_cur_commitment_point_override);
48654865
self.get_initial_counterparty_commitment_signature(funding, logger)
48664866
}
4867+
4868+
fn check_funding_confirmations(&self, funding: &mut FundingScope, height: u32) -> bool {
4869+
if funding.funding_tx_confirmation_height == 0 && funding.minimum_depth != Some(0) {
4870+
return false;
4871+
}
4872+
4873+
let funding_tx_confirmations = height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
4874+
if funding_tx_confirmations <= 0 {
4875+
funding.funding_tx_confirmation_height = 0;
4876+
}
4877+
4878+
if funding_tx_confirmations < funding.minimum_depth.unwrap_or(0) as i64 {
4879+
return false;
4880+
}
4881+
4882+
return true;
4883+
}
48674884
}
48684885

48694886
// Internal utility functions for channels
@@ -8094,16 +8111,7 @@ impl<SP: Deref> FundedChannel<SP> where
80948111
// Called:
80958112
// * always when a new block/transactions are confirmed with the new height
80968113
// * when funding is signed with a height of 0
8097-
if self.funding.funding_tx_confirmation_height == 0 && self.funding.minimum_depth != Some(0) {
8098-
return None;
8099-
}
8100-
8101-
let funding_tx_confirmations = height as i64 - self.funding.funding_tx_confirmation_height as i64 + 1;
8102-
if funding_tx_confirmations <= 0 {
8103-
self.funding.funding_tx_confirmation_height = 0;
8104-
}
8105-
8106-
if funding_tx_confirmations < self.funding.minimum_depth.unwrap_or(0) as i64 {
8114+
if !self.context.check_funding_confirmations(&mut self.funding, height) {
81078115
return None;
81088116
}
81098117

0 commit comments

Comments
 (0)