Skip to content

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

Conversation

SWvheerden
Copy link
Contributor

I added additional checks for the funding_created, funding_signed and funding_locked messages.
This is to ensure 100% coverage of BOLT2 spec. I added tests for the channel id, to ensure the received channel id is correct.

This is in relation to #129

@@ -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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -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});
Copy link
Contributor

@yuntai yuntai Sep 19, 2018

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChannelManager handles an incorrect channel_id and channel_id collision.

Copy link
Contributor Author

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.

@SWvheerden
Copy link
Contributor Author

closing this, as this only checks the ID, which is checked before this by the channel_mananger making this redundant.

@SWvheerden SWvheerden closed this Sep 20, 2018
@SWvheerden SWvheerden deleted the Add-BOLT-2-spec-checks-for-funding-messages branch September 20, 2018 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants