Skip to content

Commit 240384c

Browse files
committed
allow optional data loss protect
1 parent b14baa0 commit 240384c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/ln/channel.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,20 @@ impl Channel {
22752275
return Err(ChannelError::Close("Peer sent a garbage channel_reestablish"));
22762276
}
22772277

2278+
//Check for dataloss fields and fail channel
2279+
if let Some(ref data_loss) = msg.data_loss_protect {
2280+
//check if provided signature is a valid signature from us
2281+
if chan_utils::build_commitment_secret(self.local_keys.commitment_seed, msg.next_remote_commitment_number-1) != data_loss.your_last_per_commitment_secret{
2282+
return Err(ChannelError::Close("Peer sent a garbage channel_reestablish with secret key not from us"));
2283+
}
2284+
//check if we have fallen beind
2285+
//We should not broadcast commitment transaction
2286+
if msg.next_remote_commitment_number > self.cur_local_commitment_transaction_number{
2287+
return Err(ChannelError::Close("We have fallen behind and we cannot catch up, need to close channel but not publish commitment"));
2288+
}
2289+
//TODO check dataloss.my_current_per_commitment_point
2290+
}
2291+
22782292
// Go ahead and unmark PeerDisconnected as various calls we may make check for it (and all
22792293
// remaining cases either succeed or ErrorMessage-fail).
22802294
self.channel_state &= !(ChannelState::PeerDisconnected as u32);

0 commit comments

Comments
 (0)