@@ -3679,6 +3679,20 @@ impl<Signer: Sign> Channel<Signer> {
3679
3679
}
3680
3680
}
3681
3681
3682
+ /// Check if the we are trying to reestablish a connection with a peer with an old commitment
3683
+ /// transaction that it is not possible recovered.
3684
+ ///
3685
+ /// If the peer is not out of sync we return an empty result, otherwise just the channel error to sent.
3686
+ fn try_reestablish_when_peer_is_late ( & mut self , msg : & msgs:: ChannelReestablish ) -> Result < ( ) , ChannelError > {
3687
+ let _our_commitment_transaction = INITIAL_COMMITMENT_NUMBER - self . cur_holder_commitment_transaction_number - 1 ;
3688
+ if msg. next_remote_commitment_number < _our_commitment_transaction {
3689
+ return Err (
3690
+ ChannelError :: Warn ( format ! ( "bad reestablish revocation_number: {} (received) vs {} (expected)" , msg. next_remote_commitment_number, _our_commitment_transaction) )
3691
+ ) ;
3692
+ }
3693
+ Ok ( ( ) )
3694
+ }
3695
+
3682
3696
/// May panic if some calls other than message-handling calls (which will all Err immediately)
3683
3697
/// have been called between remove_uncommitted_htlcs_and_mark_paused and this call.
3684
3698
pub fn channel_reestablish < L : Deref > ( & mut self , msg : & msgs:: ChannelReestablish , logger : & L ,
@@ -3715,6 +3729,12 @@ impl<Signer: Sign> Channel<Signer> {
3715
3729
}
3716
3730
}
3717
3731
3732
+ // Before change the state of the channel we check if the peer are sending a very old
3733
+ // commitment transaction number, if yes we send an error (warning message).
3734
+ if let Err ( err_msg) = self . try_reestablish_when_peer_is_late ( msg) {
3735
+ return Err ( err_msg) ;
3736
+ }
3737
+
3718
3738
// Go ahead and unmark PeerDisconnected as various calls we may make check for it (and all
3719
3739
// remaining cases either succeed or ErrorMessage-fail).
3720
3740
self . channel_state &= !( ChannelState :: PeerDisconnected as u32 ) ;
0 commit comments