Skip to content

Commit 1316265

Browse files
committed
Remove block_connected de-duplication logic
Calling block_connected for the same block was necessary when clients were expected to re-fetch filtered blocks with relevant transactions. At the time, all listeners were notified of the connected block again for re-scanning. Thus, de-duplication logic was put in place. However, this requirement is no longer applicable for ChannelManager as of commit bd39b20, so remove this logic.
1 parent fec8553 commit 1316265

File tree

1 file changed

+44
-46
lines changed

1 file changed

+44
-46
lines changed

lightning/src/ln/channel.rs

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,7 @@ pub(super) struct Channel<Signer: Sign> {
368368
/// could miss the funding_tx_confirmed_in block as well, but it serves as a useful fallback.
369369
funding_tx_confirmed_in: Option<BlockHash>,
370370
short_channel_id: Option<u64>,
371-
/// Used to deduplicate block_connected callbacks, also used to verify consistency during
372-
/// ChannelManager deserialization (hence pub(super))
371+
/// Used to verify consistency during ChannelManager deserialization (hence pub(super)).
373372
pub(super) last_block_connected: BlockHash,
374373
funding_tx_confirmations: u64,
375374

@@ -3517,12 +3516,12 @@ impl<Signer: Sign> Channel<Signer> {
35173516
_ => true
35183517
}
35193518
});
3520-
let non_shutdown_state = self.channel_state & (!MULTI_STATE_FLAGS);
3521-
if header.block_hash() != self.last_block_connected {
3522-
if self.funding_tx_confirmations > 0 {
3523-
self.funding_tx_confirmations += 1;
3524-
}
3519+
3520+
if self.funding_tx_confirmations > 0 {
3521+
self.funding_tx_confirmations += 1;
35253522
}
3523+
3524+
let non_shutdown_state = self.channel_state & (!MULTI_STATE_FLAGS);
35263525
if non_shutdown_state & !(ChannelState::TheirFundingLocked as u32) == ChannelState::FundingSent as u32 {
35273526
for &(index_in_block, tx) in txdata.iter() {
35283527
let funding_txo = self.get_funding_txo().unwrap();
@@ -3568,46 +3567,45 @@ impl<Signer: Sign> Channel<Signer> {
35683567
}
35693568
}
35703569
}
3571-
if header.block_hash() != self.last_block_connected {
3572-
self.last_block_connected = header.block_hash();
3573-
self.update_time_counter = cmp::max(self.update_time_counter, header.time);
3574-
if self.funding_tx_confirmations > 0 {
3575-
if self.funding_tx_confirmations == self.minimum_depth as u64 {
3576-
let need_commitment_update = if non_shutdown_state == ChannelState::FundingSent as u32 {
3577-
self.channel_state |= ChannelState::OurFundingLocked as u32;
3578-
true
3579-
} else if non_shutdown_state == (ChannelState::FundingSent as u32 | ChannelState::TheirFundingLocked as u32) {
3580-
self.channel_state = ChannelState::ChannelFunded as u32 | (self.channel_state & MULTI_STATE_FLAGS);
3581-
self.update_time_counter += 1;
3582-
true
3583-
} else if non_shutdown_state == (ChannelState::FundingSent as u32 | ChannelState::OurFundingLocked as u32) {
3584-
// We got a reorg but not enough to trigger a force close, just update
3585-
// funding_tx_confirmed_in and return.
3586-
false
3587-
} else if self.channel_state < ChannelState::ChannelFunded as u32 {
3588-
panic!("Started confirming a channel in a state pre-FundingSent?: {}", self.channel_state);
3570+
3571+
self.last_block_connected = header.block_hash();
3572+
self.update_time_counter = cmp::max(self.update_time_counter, header.time);
3573+
if self.funding_tx_confirmations > 0 {
3574+
if self.funding_tx_confirmations == self.minimum_depth as u64 {
3575+
let need_commitment_update = if non_shutdown_state == ChannelState::FundingSent as u32 {
3576+
self.channel_state |= ChannelState::OurFundingLocked as u32;
3577+
true
3578+
} else if non_shutdown_state == (ChannelState::FundingSent as u32 | ChannelState::TheirFundingLocked as u32) {
3579+
self.channel_state = ChannelState::ChannelFunded as u32 | (self.channel_state & MULTI_STATE_FLAGS);
3580+
self.update_time_counter += 1;
3581+
true
3582+
} else if non_shutdown_state == (ChannelState::FundingSent as u32 | ChannelState::OurFundingLocked as u32) {
3583+
// We got a reorg but not enough to trigger a force close, just update
3584+
// funding_tx_confirmed_in and return.
3585+
false
3586+
} else if self.channel_state < ChannelState::ChannelFunded as u32 {
3587+
panic!("Started confirming a channel in a state pre-FundingSent?: {}", self.channel_state);
3588+
} else {
3589+
// We got a reorg but not enough to trigger a force close, just update
3590+
// funding_tx_confirmed_in and return.
3591+
false
3592+
};
3593+
self.funding_tx_confirmed_in = Some(self.last_block_connected);
3594+
3595+
//TODO: Note that this must be a duplicate of the previous commitment point they sent us,
3596+
//as otherwise we will have a commitment transaction that they can't revoke (well, kinda,
3597+
//they can by sending two revoke_and_acks back-to-back, but not really). This appears to be
3598+
//a protocol oversight, but I assume I'm just missing something.
3599+
if need_commitment_update {
3600+
if self.channel_state & (ChannelState::MonitorUpdateFailed as u32) == 0 {
3601+
let next_per_commitment_point = self.holder_signer.get_per_commitment_point(self.cur_holder_commitment_transaction_number, &self.secp_ctx);
3602+
return Ok((Some(msgs::FundingLocked {
3603+
channel_id: self.channel_id,
3604+
next_per_commitment_point,
3605+
}), timed_out_htlcs));
35893606
} else {
3590-
// We got a reorg but not enough to trigger a force close, just update
3591-
// funding_tx_confirmed_in and return.
3592-
false
3593-
};
3594-
self.funding_tx_confirmed_in = Some(self.last_block_connected);
3595-
3596-
//TODO: Note that this must be a duplicate of the previous commitment point they sent us,
3597-
//as otherwise we will have a commitment transaction that they can't revoke (well, kinda,
3598-
//they can by sending two revoke_and_acks back-to-back, but not really). This appears to be
3599-
//a protocol oversight, but I assume I'm just missing something.
3600-
if need_commitment_update {
3601-
if self.channel_state & (ChannelState::MonitorUpdateFailed as u32) == 0 {
3602-
let next_per_commitment_point = self.holder_signer.get_per_commitment_point(self.cur_holder_commitment_transaction_number, &self.secp_ctx);
3603-
return Ok((Some(msgs::FundingLocked {
3604-
channel_id: self.channel_id,
3605-
next_per_commitment_point,
3606-
}), timed_out_htlcs));
3607-
} else {
3608-
self.monitor_pending_funding_locked = true;
3609-
return Ok((None, timed_out_htlcs));
3610-
}
3607+
self.monitor_pending_funding_locked = true;
3608+
return Ok((None, timed_out_htlcs));
36113609
}
36123610
}
36133611
}

0 commit comments

Comments
 (0)