-
Notifications
You must be signed in to change notification settings - Fork 407
Add bolt 2 spec checks for funding messages #190
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
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 |
---|---|---|
|
@@ -1300,6 +1300,9 @@ impl Channel { | |
if self.channel_outbound { | ||
return Err(HandleError{err: "Received funding_created for an outbound channel?", action: Some(msgs::ErrorAction::SendErrorMessage {msg: msgs::ErrorMessage {channel_id: self.channel_id, data: "Received funding_created for an outbound channel?".to_string()}})}); | ||
} | ||
if self.channel_id != msg.temporary_channel_id { | ||
return Err(HandleError{err: "temporary channel id in funding_created does not match open_channel message", action: Some(msgs::ErrorAction::SendErrorMessage {msg: msgs::ErrorMessage {channel_id: self.channel_id, data: "temporary channel id in funding_created does not match open_channel message".to_string()}})}); | ||
} | ||
if self.channel_state != (ChannelState::OurInitSent as u32 | ChannelState::TheirInitSent as u32) { | ||
// BOLT 2 says that if we disconnect before we send funding_signed we SHOULD NOT | ||
// remember the channel, so its safe to just send an error_message here and drop the | ||
|
@@ -1352,6 +1355,9 @@ impl Channel { | |
self.cur_local_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER { | ||
panic!("Should not have advanced channel commitment tx numbers prior to funding_created"); | ||
} | ||
if self.channel_monitor.funding_txo.clone().unwrap().0.to_channel_id() != msg.channel_id { | ||
return Err(HandleError{err: "Received incorrect channel_id in funding_signed message", action: None}); | ||
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. Given how things are structured it'd be very hard for someone to introduce a bug that will make this condition true, but if that ever happens it should be hard panic, not returning Err. 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 agree that it is very likely that it col be caused by a bug. But the remote could accidentally or intentionally send the incorrect id. 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. ChannelManager handles an incorrect channel_id and channel_id collision. 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. awesome, cwl then we dont have to check these. |
||
} | ||
|
||
let funding_script = self.get_funding_redeemscript(); | ||
|
||
|
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.
The method is called on self b/c this condition is true. So this if expression will never be false.
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.
I potentially have this wrong, but isnt msg the incoming message from the remote peer? Which means h=it could have it wrong
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.
channelmanager maintains a mapping from channel_id to channel struct, so if an unknown temporary_channel_id is received, it will be disregarded instead of this method being invoked.
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.
awesome, cwl then we dont have to check these.