Skip to content

Commit 585bb07

Browse files
Log and panic when fallen behind remote commitment number
1 parent 1e25979 commit 585bb07

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4236,8 +4236,25 @@ impl<SP: Deref> Channel<SP> where
42364236
} else {
42374237
Some(self.get_last_revoke_and_ack())
42384238
}
4239+
} else if self.context.cur_holder_commitment_transaction_number > msg.next_remote_commitment_number {
4240+
// The remote has attempted to reestablish with a very old state, return an error.
4241+
return Err(ChannelError::Close("Peer attempted to reestablish channel with a very old local commitment transaction".to_owned()));
42394242
} else {
4240-
return Err(ChannelError::Close("Peer attempted to reestablish channel with a very old local commitment transaction".to_owned()));
4243+
// Our local state has fallen behind the remote state.
4244+
macro_rules! log_and_panic {
4245+
($err_msg: expr) => {
4246+
log_error!(logger, $err_msg, &self.context.channel_id, log_pubkey!(self.context.counterparty_node_id));
4247+
panic!($err_msg, &self.context.channel_id, log_pubkey!(self.context.counterparty_node_id));
4248+
}
4249+
}
4250+
log_and_panic!("We have fallen behind - we have received proof that if we broadcast our counterparty is going to claim all our funds.\n\
4251+
This implies you have restarted with lost ChannelMonitor and ChannelManager state, the first of which is a violation of the LDK chain::Watch requirements.\n\
4252+
More specifically, this means you have a bug in your implementation that can cause loss of funds, or you are running with an old backup, which is unsafe.\n\
4253+
If you have restored from an old backup and wish to force-close channels and return to operation, you should start up, call\n\
4254+
ChannelManager::force_close_without_broadcasting_txn on channel {} with counterparty {} or\n\
4255+
ChannelManager::force_close_all_channels_without_broadcasting_txn, then reconnect to peer(s).\n\
4256+
Note that due to a long-standing bug in lnd you may have to reach out to peers running lnd-based nodes to ask them to manually force-close channels\n\
4257+
See https://github.com/lightningdevkit/rust-lightning/issues/1565 for more info.");
42414258
};
42424259

42434260
// We increment cur_counterparty_commitment_transaction_number only upon receipt of

0 commit comments

Comments
 (0)