Skip to content

Commit 41232f5

Browse files
committed
f improve legibility as arik suggested
1 parent 1049ac3 commit 41232f5

File tree

1 file changed

+44
-40
lines changed

1 file changed

+44
-40
lines changed

lightning/src/ln/channel.rs

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3502,48 +3502,52 @@ impl<Signer: Sign> Channel<Signer> {
35023502
}
35033503

35043504
fn check_get_funding_locked(&mut self, height: u32) -> Option<msgs::FundingLocked> {
3505-
if self.funding_tx_confirmation_height > 0 {
3506-
let funding_tx_confirmations = height as i64 - self.funding_tx_confirmation_height as i64 + 1;
3507-
if funding_tx_confirmations <= 0 {
3508-
self.funding_tx_confirmation_height = 0;
3509-
}
3505+
if self.funding_tx_confirmation_height <= 0 {
3506+
return None;
3507+
}
35103508

3511-
if funding_tx_confirmations >= self.minimum_depth as i64 {
3512-
let non_shutdown_state = self.channel_state & (!MULTI_STATE_FLAGS);
3513-
let need_commitment_update = if non_shutdown_state == ChannelState::FundingSent as u32 {
3514-
self.channel_state |= ChannelState::OurFundingLocked as u32;
3515-
true
3516-
} else if non_shutdown_state == (ChannelState::FundingSent as u32 | ChannelState::TheirFundingLocked as u32) {
3517-
self.channel_state = ChannelState::ChannelFunded as u32 | (self.channel_state & MULTI_STATE_FLAGS);
3518-
self.update_time_counter += 1;
3519-
true
3520-
} else if non_shutdown_state == (ChannelState::FundingSent as u32 | ChannelState::OurFundingLocked as u32) {
3521-
// We got a reorg but not enough to trigger a force close, just update
3522-
// funding_tx_confirmed_in and return.
3523-
false
3524-
} else if self.channel_state < ChannelState::ChannelFunded as u32 {
3525-
panic!("Started confirming a channel in a state pre-FundingSent?: {}", self.channel_state);
3526-
} else {
3527-
// We got a reorg but not enough to trigger a force close, just update
3528-
// funding_tx_confirmed_in and return.
3529-
false
3530-
};
3509+
let funding_tx_confirmations = height as i64 - self.funding_tx_confirmation_height as i64 + 1;
3510+
if funding_tx_confirmations <= 0 {
3511+
self.funding_tx_confirmation_height = 0;
3512+
}
35313513

3532-
//TODO: Note that this must be a duplicate of the previous commitment point they sent us,
3533-
//as otherwise we will have a commitment transaction that they can't revoke (well, kinda,
3534-
//they can by sending two revoke_and_acks back-to-back, but not really). This appears to be
3535-
//a protocol oversight, but I assume I'm just missing something.
3536-
if need_commitment_update {
3537-
if self.channel_state & (ChannelState::MonitorUpdateFailed as u32) == 0 {
3538-
let next_per_commitment_point = self.holder_signer.get_per_commitment_point(self.cur_holder_commitment_transaction_number, &self.secp_ctx);
3539-
return Some(msgs::FundingLocked {
3540-
channel_id: self.channel_id,
3541-
next_per_commitment_point,
3542-
});
3543-
} else {
3544-
self.monitor_pending_funding_locked = true;
3545-
}
3546-
}
3514+
if funding_tx_confirmations < self.minimum_depth as i64 {
3515+
return None;
3516+
}
3517+
3518+
let non_shutdown_state = self.channel_state & (!MULTI_STATE_FLAGS);
3519+
let need_commitment_update = if non_shutdown_state == ChannelState::FundingSent as u32 {
3520+
self.channel_state |= ChannelState::OurFundingLocked as u32;
3521+
true
3522+
} else if non_shutdown_state == (ChannelState::FundingSent as u32 | ChannelState::TheirFundingLocked as u32) {
3523+
self.channel_state = ChannelState::ChannelFunded as u32 | (self.channel_state & MULTI_STATE_FLAGS);
3524+
self.update_time_counter += 1;
3525+
true
3526+
} else if non_shutdown_state == (ChannelState::FundingSent as u32 | ChannelState::OurFundingLocked as u32) {
3527+
// We got a reorg but not enough to trigger a force close, just update
3528+
// funding_tx_confirmed_in and return.
3529+
false
3530+
} else if self.channel_state < ChannelState::ChannelFunded as u32 {
3531+
panic!("Started confirming a channel in a state pre-FundingSent?: {}", self.channel_state);
3532+
} else {
3533+
// We got a reorg but not enough to trigger a force close, just update
3534+
// funding_tx_confirmed_in and return.
3535+
false
3536+
};
3537+
3538+
//TODO: Note that this must be a duplicate of the previous commitment point they sent us,
3539+
//as otherwise we will have a commitment transaction that they can't revoke (well, kinda,
3540+
//they can by sending two revoke_and_acks back-to-back, but not really). This appears to be
3541+
//a protocol oversight, but I assume I'm just missing something.
3542+
if need_commitment_update {
3543+
if self.channel_state & (ChannelState::MonitorUpdateFailed as u32) == 0 {
3544+
let next_per_commitment_point = self.holder_signer.get_per_commitment_point(self.cur_holder_commitment_transaction_number, &self.secp_ctx);
3545+
return Some(msgs::FundingLocked {
3546+
channel_id: self.channel_id,
3547+
next_per_commitment_point,
3548+
});
3549+
} else {
3550+
self.monitor_pending_funding_locked = true;
35473551
}
35483552
}
35493553
None

0 commit comments

Comments
 (0)