Skip to content

Commit

Permalink
send warning when we have a old commitment transaction
Browse files Browse the repository at this point in the history
During a `channel_restablish` now we send a warning message when we have a old commitment transaction.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Apr 18, 2022
1 parent e0b9b74 commit 136171d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3679,6 +3679,21 @@ impl<Signer: Sign> Channel<Signer> {
}
}

/// Check if the we are trying to reestablish a connection when we have a
/// very old local commitment transaction.
///
/// If we are out of sync we return an empty result, otherwise just the channel error tu sent.
fn try_reestablish_when_we_are_late(&mut self, msg: &msgs::ChannelReestablish) -> Result<(), ChannelError> {
//FIXME(vincenzopalazzo) We receive the next commitment transaction to one to sent, so to be in sync we should
// be equal at list to the `next - 1`?
if (INITIAL_COMMITMENT_NUMBER - self.cur_holder_commitment_transaction_number) < msg.next_remote_commitment_number - 1 {
return Err(
ChannelError::Warn("we have a very old commitment transaction".to_owned())
);
}
Ok(())
}

/// May panic if some calls other than message-handling calls (which will all Err immediately)
/// have been called between remove_uncommitted_htlcs_and_mark_paused and this call.
pub fn channel_reestablish<L: Deref>(&mut self, msg: &msgs::ChannelReestablish, logger: &L,
Expand Down Expand Up @@ -3715,6 +3730,13 @@ impl<Signer: Sign> Channel<Signer> {
}
}

// Before change the state of the channel, we check if
// we have a very old local commitment transaction.
// this is more a sanity check!
if let Err(err_msg) = self.try_reestablish_when_we_are_late(msg) {
return Err(err_msg);
}

// Go ahead and unmark PeerDisconnected as various calls we may make check for it (and all
// remaining cases either succeed or ErrorMessage-fail).
self.channel_state &= !(ChannelState::PeerDisconnected as u32);
Expand Down

0 comments on commit 136171d

Please sign in to comment.