Skip to content

Commit 7ae6fdc

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 637fb88 commit 7ae6fdc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lightning/src/ln/channel.rs

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

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+
36823696
/// May panic if some calls other than message-handling calls (which will all Err immediately)
36833697
/// have been called between remove_uncommitted_htlcs_and_mark_paused and this call.
36843698
pub fn channel_reestablish<L: Deref>(&mut self, msg: &msgs::ChannelReestablish, logger: &L,
@@ -3715,6 +3729,12 @@ impl<Signer: Sign> Channel<Signer> {
37153729
}
37163730
}
37173731

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+
37183738
// Go ahead and unmark PeerDisconnected as various calls we may make check for it (and all
37193739
// remaining cases either succeed or ErrorMessage-fail).
37203740
self.channel_state &= !(ChannelState::PeerDisconnected as u32);

0 commit comments

Comments
 (0)