Skip to content

Commit 86a5630

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 b38d28d commit 86a5630

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
@@ -5469,7 +5469,7 @@ where
54695469
self.get_initial_counterparty_commitment_signature(funding, logger)
54705470
}
54715471

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

54755475
if funding.funding_tx_confirmation_height == 0 && minimum_depth != Some(0) {
@@ -5478,10 +5478,6 @@ where
54785478

54795479
let funding_tx_confirmations =
54805480
height as i64 - funding.funding_tx_confirmation_height as i64 + 1;
5481-
if funding_tx_confirmations <= 0 {
5482-
funding.funding_tx_confirmation_height = 0;
5483-
}
5484-
54855481
if funding_tx_confirmations < minimum_depth.unwrap_or(0) as i64 {
54865482
return false;
54875483
}
@@ -8770,7 +8766,7 @@ where
87708766
// Called:
87718767
// * always when a new block/transactions are confirmed with the new height
87728768
// * when funding is signed with a height of 0
8773-
if !self.context.check_funding_meets_minimum_depth(&mut self.funding, height) {
8769+
if !self.context.check_funding_meets_minimum_depth(&self.funding, height) {
87748770
return None;
87758771
}
87768772

@@ -8974,6 +8970,12 @@ where
89748970

89758971
self.context.update_time_counter = cmp::max(self.context.update_time_counter, highest_header_time);
89768972

8973+
// Check if the funding transaction was unconfirmed
8974+
let funding_tx_confirmations = self.funding.get_funding_tx_confirmations(height);
8975+
if funding_tx_confirmations == 0 {
8976+
self.funding.funding_tx_confirmation_height = 0;
8977+
}
8978+
89778979
if let Some(channel_ready) = self.check_get_channel_ready(height, logger) {
89788980
let announcement_sigs = if let Some((chain_hash, node_signer, user_config)) = chain_node_signer {
89798981
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
@@ -8984,13 +8986,6 @@ where
89848986

89858987
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||
89868988
self.context.channel_state.is_our_channel_ready() {
8987-
let mut funding_tx_confirmations = height as i64 - self.funding.funding_tx_confirmation_height as i64 + 1;
8988-
if self.funding.funding_tx_confirmation_height == 0 {
8989-
// Note that check_get_channel_ready may reset funding_tx_confirmation_height to
8990-
// zero if it has been reorged out, however in either case, our state flags
8991-
// indicate we've already sent a channel_ready
8992-
funding_tx_confirmations = 0;
8993-
}
89948989

89958990
// If we've sent channel_ready (or have both sent and received channel_ready), and
89968991
// the funding transaction has become unconfirmed,
@@ -9034,6 +9029,7 @@ where
90349029
// larger. If we don't know that time has moved forward, we can just set it to the last
90359030
// time we saw and it will be ignored.
90369031
let best_time = self.context.update_time_counter;
9032+
90379033
match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
90389034
Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
90399035
assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");

0 commit comments

Comments
 (0)