Skip to content

Commit 136171d

Browse files
send warning when we have a old commitment transaction
During a `channel_restablish` now we send a warning message when we have a old commitment transaction. Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent e0b9b74 commit 136171d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lightning/src/ln/channel.rs

+22
Original file line numberDiff line numberDiff line change
@@ -3679,6 +3679,21 @@ impl<Signer: Sign> Channel<Signer> {
36793679
}
36803680
}
36813681

3682+
/// Check if the we are trying to reestablish a connection when we have a
3683+
/// very old local commitment transaction.
3684+
///
3685+
/// If we are out of sync we return an empty result, otherwise just the channel error tu sent.
3686+
fn try_reestablish_when_we_are_late(&mut self, msg: &msgs::ChannelReestablish) -> Result<(), ChannelError> {
3687+
//FIXME(vincenzopalazzo) We receive the next commitment transaction to one to sent, so to be in sync we should
3688+
// be equal at list to the `next - 1`?
3689+
if (INITIAL_COMMITMENT_NUMBER - self.cur_holder_commitment_transaction_number) < msg.next_remote_commitment_number - 1 {
3690+
return Err(
3691+
ChannelError::Warn("we have a very old commitment transaction".to_owned())
3692+
);
3693+
}
3694+
Ok(())
3695+
}
3696+
36823697
/// May panic if some calls other than message-handling calls (which will all Err immediately)
36833698
/// have been called between remove_uncommitted_htlcs_and_mark_paused and this call.
36843699
pub fn channel_reestablish<L: Deref>(&mut self, msg: &msgs::ChannelReestablish, logger: &L,
@@ -3715,6 +3730,13 @@ impl<Signer: Sign> Channel<Signer> {
37153730
}
37163731
}
37173732

3733+
// Before change the state of the channel, we check if
3734+
// we have a very old local commitment transaction.
3735+
// this is more a sanity check!
3736+
if let Err(err_msg) = self.try_reestablish_when_we_are_late(msg) {
3737+
return Err(err_msg);
3738+
}
3739+
37183740
// Go ahead and unmark PeerDisconnected as various calls we may make check for it (and all
37193741
// remaining cases either succeed or ErrorMessage-fail).
37203742
self.channel_state &= !(ChannelState::PeerDisconnected as u32);

0 commit comments

Comments
 (0)