Skip to content
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

Refactor handle_accept_channel to wrapper error handling function #151

Closed

Conversation

ariard
Copy link

@ariard ariard commented Sep 5, 2018

Fill in HandleError actions

match channel_state.by_id.get_mut(&msg.temporary_channel_id) {
Some(chan) => {
if chan.get_their_node_id() != *their_node_id {
return Err(MsgHandleErrInternal::disconnect_peer_with_err_msg("Got a message for a channel from the wrong node!", msg.temporary_channel_id.clone()));
Copy link
Author

Choose a reason for hiding this comment

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

A node giving us message for a channel it doesn't own seems to me either a malicious node or a busted one. Disconnect it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd be ok with that, but we need to be consistent and I know we do it differently elsewhere. I think we need to come up with some vaguely consistent concept of disconnect vs just error message and I really have no idea what it should be. I was thinking earlier today there's probably situations (like maybe this) where we'd want to disconnect if they do something obnoxious but not DoS-y but only if we dont have an open channel with them. It wouldnt be worth breaking a channel over, but if they're a random peer then maybe it would be worth disconnecting. Not really sure how to handle it, but it may make sense to think about removing the distinction between Disconnect and error message for an Error type that is used in Channel/ChannelManager and then convert that to HandleError in the ChannelManager macro when returning.

In any case, all of that is obviously out-of-scope for this PR and probably only makes sense as a refactor after all the moves-into-internal-function refactors here are done. Maybe just open an issue for it, put it on the TODO list and not worry about it now?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, out-of-scope for now, done with #153

@@ -155,6 +155,23 @@ impl MsgHandleErrInternal {
needs_channel_force_close: true,
}
}

#[inline]
fn disconnect_peer_with_err_msg(err: &'static str, channel_id: [u8; 32]) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we keep the naming consistent and mention close/no-close in the fn name as thats the most important distinction (also in your use-case here you need no-close, cause a random third-party sent us a message for the wrong channel so we shouldn't close it on the actual peer's channel).

Copy link
Author

Choose a reason for hiding this comment

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

Remove it but I keep the comment on my side, if I need it again in a coming commits

@TheBlueMatt
Copy link
Collaborator

Looks good aside from the two comments there. As an aside I was thinking that while we go through these refactors we should go ahead and (in separate commits) make sure we fill in all the cases with action: None with Some() so that we can drop the Option<> soon, since we're re-reading it all anyway. I think this PR qualifies but just making note in case you feel up to that.

@ariard
Copy link
Author

ariard commented Sep 6, 2018

Splitted in two commits. Still feeling than disconnect_peer, channel_closure could be a combination of flags on top of an error message?
Sure, will try to fulfill all the cases of action:None in the ongoing refactoring to drop Option<> asap!

Some(chan) => {
if chan.get_their_node_id() != *their_node_id {
//TODO: see issue #153 , need a consistent behavior on obnoxious behavior from random node
return Err(MsgHandleErrInternal::from_no_close(HandleError{err: "Got a message for a channel from the wrong node!", action: Some(msgs::ErrorAction::IgnoreError)}));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oops, well it needs to be consistent but either between SendErrorMessage or Disconnect with an ErrorMessage specified. IgnoreError isnt really correct either way.

chan.accept_channel(&msg).map_err(|e| MsgHandleErrInternal::from_maybe_close(e))?;
(chan.get_value_satoshis(), chan.get_funding_redeemscript().to_v0_p2wsh(), chan.get_user_id())
},
None => return Err(MsgHandleErrInternal::from_no_close(HandleError{err: "Failed to find corresponding channel", action: Some(msgs::ErrorAction::IgnoreError)}))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should also be the ErrorMessage/Disconnect you had earlier, same as above (and also covered in #153).

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Sorry for the confusion, looks good, though!

TheBlueMatt added a commit that referenced this pull request Sep 6, 2018
Refactor handle_accept_channel to wrapper error handling function
@TheBlueMatt
Copy link
Collaborator

Merged with the commits squashed so we dont have commits that fail to build.

@TheBlueMatt TheBlueMatt closed this Sep 6, 2018
@ariard ariard deleted the channel_manager_refactor branch September 7, 2018 22:13
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.

None yet

2 participants