-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle missing case in reestablish local commitment number checks #2721
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4152,14 +4152,15 @@ impl<SP: Deref> Channel<SP> where | |
return Err(ChannelError::Close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned())); | ||
} | ||
|
||
let our_commitment_transaction = INITIAL_COMMITMENT_NUMBER - self.context.cur_holder_commitment_transaction_number - 1; | ||
if msg.next_remote_commitment_number > 0 { | ||
let expected_point = self.context.holder_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - msg.next_remote_commitment_number + 1, &self.context.secp_ctx); | ||
let given_secret = SecretKey::from_slice(&msg.your_last_per_commitment_secret) | ||
.map_err(|_| ChannelError::Close("Peer sent a garbage channel_reestablish with unparseable secret key".to_owned()))?; | ||
if expected_point != PublicKey::from_secret_key(&self.context.secp_ctx, &given_secret) { | ||
return Err(ChannelError::Close("Peer sent a garbage channel_reestablish with secret key not matching the commitment height provided".to_owned())); | ||
} | ||
if msg.next_remote_commitment_number > INITIAL_COMMITMENT_NUMBER - self.context.cur_holder_commitment_transaction_number { | ||
if msg.next_remote_commitment_number > our_commitment_transaction { | ||
macro_rules! log_and_panic { | ||
($err_msg: expr) => { | ||
log_error!(logger, $err_msg, &self.context.channel_id, log_pubkey!(self.context.counterparty_node_id)); | ||
|
@@ -4179,11 +4180,12 @@ impl<SP: Deref> Channel<SP> where | |
|
||
// Before we change the state of the channel, we check if the peer is sending a very old | ||
// commitment transaction number, if yes we send a warning message. | ||
let our_commitment_transaction = INITIAL_COMMITMENT_NUMBER - self.context.cur_holder_commitment_transaction_number - 1; | ||
if msg.next_remote_commitment_number + 1 < our_commitment_transaction { | ||
return Err( | ||
ChannelError::Warn(format!("Peer attempted to reestablish channel with a very old local commitment transaction: {} (received) vs {} (expected)", msg.next_remote_commitment_number, our_commitment_transaction)) | ||
); | ||
if msg.next_remote_commitment_number + 1 < our_commitment_transaction { | ||
return Err(ChannelError::Warn(format!( | ||
"Peer attempted to reestablish channel with a very old local commitment transaction: {} (received) vs {} (expected)", | ||
msg.next_remote_commitment_number, | ||
our_commitment_transaction | ||
))); | ||
} | ||
|
||
// Go ahead and unmark PeerDisconnected as various calls we may make check for it (and all | ||
|
@@ -4225,19 +4227,24 @@ impl<SP: Deref> Channel<SP> where | |
}); | ||
} | ||
|
||
let required_revoke = if msg.next_remote_commitment_number + 1 == INITIAL_COMMITMENT_NUMBER - self.context.cur_holder_commitment_transaction_number { | ||
let required_revoke = if msg.next_remote_commitment_number == our_commitment_transaction { | ||
// Remote isn't waiting on any RevokeAndACK from us! | ||
// Note that if we need to repeat our ChannelReady we'll do that in the next if block. | ||
None | ||
} else if msg.next_remote_commitment_number + 1 == (INITIAL_COMMITMENT_NUMBER - 1) - self.context.cur_holder_commitment_transaction_number { | ||
} else if msg.next_remote_commitment_number + 1 == our_commitment_transaction { | ||
if self.context.channel_state & (ChannelState::MonitorUpdateInProgress as u32) != 0 { | ||
self.context.monitor_pending_revoke_and_ack = true; | ||
None | ||
} else { | ||
Some(self.get_last_revoke_and_ack()) | ||
} | ||
} else { | ||
return Err(ChannelError::Close("Peer attempted to reestablish channel with a very old local commitment transaction".to_owned())); | ||
debug_assert!(false, "All values should have been handled in the four cases above"); | ||
return Err(ChannelError::Close(format!( | ||
wpaulino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"Peer attempted to reestablish channel expecting a future local commitment transaction: {} (received) vs {} (expected)", | ||
msg.next_remote_commitment_number, | ||
our_commitment_transaction | ||
))); | ||
}; | ||
|
||
// We increment cur_counterparty_commitment_transaction_number only upon receipt of | ||
|
@@ -4295,8 +4302,18 @@ impl<SP: Deref> Channel<SP> where | |
order: self.context.resend_order.clone(), | ||
}) | ||
} | ||
} else if msg.next_local_commitment_number < next_counterparty_commitment_number { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the case before this is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its an else if and and the intent is to capture any "they're behind us" case (that we cannot recover from, which is handled in the above conditionals). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just think it'd be more clear if this was There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, oh, okay so that's where the disagreement is. So the statement in the error message (even if not closing in response, or the "very" part of the comment) is correct with or without the - 1. Given the |
||
Err(ChannelError::Close(format!( | ||
"Peer attempted to reestablish channel with a very old remote commitment transaction: {} (received) vs {} (expected)", | ||
msg.next_local_commitment_number, | ||
next_counterparty_commitment_number, | ||
))) | ||
} else { | ||
Err(ChannelError::Close("Peer attempted to reestablish channel with a very old remote commitment transaction".to_owned())) | ||
Err(ChannelError::Close(format!( | ||
"Peer attempted to reestablish channel with a future remote commitment transaction: {} (received) vs {} (expected)", | ||
msg.next_local_commitment_number, | ||
next_counterparty_commitment_number, | ||
))) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
somewhat poor choice for a variable name that's a number/index, and not an actual tx