Skip to content

Commit f9ad4a0

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 ac39850 commit f9ad4a0

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
@@ -5481,7 +5481,7 @@ where
54815481
self.get_initial_counterparty_commitment_signature(funding, logger)
54825482
}
54835483

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

54875487
if funding.funding_tx_confirmation_height == 0 && minimum_depth != Some(0) {
@@ -5490,10 +5490,6 @@ where
54905490

54915491
let funding_tx_confirmations =
54925492
height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
5493-
if funding_tx_confirmations <= 0 {
5494-
funding.funding_tx_confirmation_height = 0;
5495-
}
5496-
54975493
if funding_tx_confirmations < minimum_depth.unwrap_or(0) as i64 {
54985494
return false;
54995495
}
@@ -8814,7 +8810,7 @@ where
88148810
// Called:
88158811
// * always when a new block/transactions are confirmed with the new height
88168812
// * when funding is signed with a height of 0
8817-
if !self.context.check_funding_meets_minimum_depth(&mut self.funding, height) {
8813+
if !self.context.check_funding_meets_minimum_depth(&self.funding, height) {
88188814
return None;
88198815
}
88208816

@@ -9022,6 +9018,12 @@ where
90229018

90239019
self.context.update_time_counter = cmp::max(self.context.update_time_counter, highest_header_time);
90249020

9021+
// Check if the funding transaction was unconfirmed
9022+
let funding_tx_confirmations = self.funding.get_funding_tx_confirmations(height);
9023+
if funding_tx_confirmations == 0 {
9024+
self.funding.funding_tx_confirmation_height = 0;
9025+
}
9026+
90259027
if let Some(channel_ready) = self.check_get_channel_ready(height, logger) {
90269028
let announcement_sigs = if let Some((chain_hash, node_signer, user_config)) = chain_node_signer {
90279029
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
@@ -9032,13 +9034,6 @@ where
90329034

90339035
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||
90349036
self.context.channel_state.is_our_channel_ready() {
9035-
let mut funding_tx_confirmations = height as i64 - self.funding.funding_tx_confirmation_height as i64 + 1;
9036-
if self.funding.funding_tx_confirmation_height == 0 {
9037-
// Note that check_get_channel_ready may reset funding_tx_confirmation_height to
9038-
// zero if it has been reorged out, however in either case, our state flags
9039-
// indicate we've already sent a channel_ready
9040-
funding_tx_confirmations = 0;
9041-
}
90429037

90439038
// If we've sent channel_ready (or have both sent and received channel_ready), and
90449039
// the funding transaction has become unconfirmed,
@@ -9082,6 +9077,7 @@ where
90829077
// larger. If we don't know that time has moved forward, we can just set it to the last
90839078
// time we saw and it will be ignored.
90849079
let best_time = self.context.update_time_counter;
9080+
90859081
match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
90869082
Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
90879083
assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");

0 commit comments

Comments
 (0)