Skip to content

Commit 811da64

Browse files
committed
Reset FundingScope::funding_tx_confirmation_height
FundingScope::funding_tx_confirmation_height is reset as part of calling ChannelContext::check_funding_meets_minimum_depth via FundedChannel::check_get_channel_ready. This side effect requires using mutable references to self when otherwise it would not be needed. Instead of reseting funding_tx_confirmation_height there, do so when unconfirming the funding transaction.
1 parent 038ab21 commit 811da64

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

lightning/src/ln/channel.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5271,18 +5271,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
52715271
self.get_initial_counterparty_commitment_signature(funding, logger)
52725272
}
52735273

5274-
fn check_funding_meets_minimum_depth(&self, funding: &mut FundingScope, height: u32) -> bool {
5274+
fn check_funding_meets_minimum_depth(&self, funding: &FundingScope, height: u32) -> bool {
52755275
let minimum_depth = funding.minimum_depth_override.or(self.minimum_depth);
52765276

52775277
if funding.funding_tx_confirmation_height == 0 && minimum_depth != Some(0) {
52785278
return false;
52795279
}
52805280

52815281
let funding_tx_confirmations = height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
5282-
if funding_tx_confirmations <= 0 {
5283-
funding.funding_tx_confirmation_height = 0;
5284-
}
5285-
52865282
if funding_tx_confirmations < minimum_depth.unwrap_or(0) as i64 {
52875283
return false;
52885284
}
@@ -8493,7 +8489,7 @@ impl<SP: Deref> FundedChannel<SP> where
84938489
// Called:
84948490
// * always when a new block/transactions are confirmed with the new height
84958491
// * when funding is signed with a height of 0
8496-
if !self.context.check_funding_meets_minimum_depth(&mut self.funding, height) {
8492+
if !self.context.check_funding_meets_minimum_depth(&self.funding, height) {
84978493
return None;
84988494
}
84998495

@@ -8693,6 +8689,12 @@ impl<SP: Deref> FundedChannel<SP> where
86938689

86948690
self.context.update_time_counter = cmp::max(self.context.update_time_counter, highest_header_time);
86958691

8692+
// Check if the funding transaction was unconfirmed
8693+
let funding_tx_confirmations = self.funding.get_funding_tx_confirmations(height);
8694+
if funding_tx_confirmations == 0 {
8695+
self.funding.funding_tx_confirmation_height = 0;
8696+
}
8697+
86968698
if let Some(channel_ready) = self.check_get_channel_ready(height, logger) {
86978699
let announcement_sigs = if let Some((chain_hash, node_signer, user_config)) = chain_node_signer {
86988700
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
@@ -8703,13 +8705,6 @@ impl<SP: Deref> FundedChannel<SP> where
87038705

87048706
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||
87058707
self.context.channel_state.is_our_channel_ready() {
8706-
let mut funding_tx_confirmations = height as i64 - self.funding.funding_tx_confirmation_height as i64 + 1;
8707-
if self.funding.funding_tx_confirmation_height == 0 {
8708-
// Note that check_get_channel_ready may reset funding_tx_confirmation_height to
8709-
// zero if it has been reorged out, however in either case, our state flags
8710-
// indicate we've already sent a channel_ready
8711-
funding_tx_confirmations = 0;
8712-
}
87138708

87148709
// If we've sent channel_ready (or have both sent and received channel_ready), and
87158710
// the funding transaction has become unconfirmed,
@@ -8752,6 +8747,7 @@ impl<SP: Deref> FundedChannel<SP> where
87528747
// larger. If we don't know that time has moved forward, we can just set it to the last
87538748
// time we saw and it will be ignored.
87548749
let best_time = self.context.update_time_counter;
8750+
87558751
match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
87568752
Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
87578753
assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");

0 commit comments

Comments
 (0)