-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
peer: Ignore unknown P2P messages #1671
Conversation
This would make it possible for old versions (that contain this change) to talk with newer versions without requiring a protocol version increment. Fixes btcsuite#1661
Pull Request Test Coverage Report for Build 405504879
💛 - Coveralls |
Concept ACK |
1 similar comment
Concept ACK |
Concept ACK. Would definitely prefer to see some test cases around this. Taking a look at the error handling now. |
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.
Think this needs a test case, I wrote one here: vasild#1 but feel free to modify as needed.
As for the strings.Contains
, I agree it seems ineloquent. While we do this in tests (see: mempool_test
and csv_fork_test
), It's probably not the best solution here.
One solution might be to add a custom error type in wire/error
or reuse the MessageError
and check Func
@jakesyl, thanks for the test! I added it to this PR. (I think it upset the CI) |
Looks like we need to run If you could do that and push that’d be awesome otherwise I’ll get to it tomorrow (it’s 4:30 am here 💤) |
7141bda
to
ac83f0d
Compare
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’m good to go here. Would like to get another review and see if anyone else has concerns over the error check, but it not lgtm
Depending on interpretation, this itself is a departure from the "Bitcoin P2P protocol" (w/e that's defined) or we're simply filling in behavior which was previously undefined. |
@@ -1348,6 +1349,13 @@ out: | |||
continue | |||
} | |||
|
|||
// Ignore unknown messages to ease future extensibility. |
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.
Ideally when creating the peer object itself, the caller is able to specify if they wish to permit unknown message or not, as the caller may wish to adhere to a stricter interpretation of what exactly constitutes the Bitcoin P2P protocol.
Also it seems this change should wait on the development of this draft BIP: https://github.com/sdaftuar/bips/blob/2020-08-generalized-feature-negotiation/bip-p2p-feature-negotiation.mediawiki
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 think the comment is a reference to https://github.com/benjyz/bitcoinArchive/blob/master/bitcoin0.1/src/main.cpp#L2035-L2039. But I agree for the library this should be extensible
I am not sure if it is defined anywhere whether unknown messages should be ignored or not. My impression is that it is not defined, so I guess this is more "filling in behavior". Bitcoin Core ignores unknown messages. |
I think it's still relevant since it sets us up to be able to gracefully handle any other new messages introduced. |
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.
Commented some improvements re concurrency and go error types. I think this can land and have those be follow up changes if the OP isn't still active.
@@ -481,6 +508,11 @@ func TestPeerListeners(t *testing.T) { | |||
} | |||
} | |||
|
|||
outPeer.QueueMessage(&UnknownMessage{}, nil) |
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.
This should pass in a done channel so it can properly synchronize the assertion below. Can address this in a follow up change if the OP has abandoned the PR.
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 am not sure how to translate that suggestion to Go code 😭
@@ -1348,6 +1349,13 @@ out: | |||
continue | |||
} | |||
|
|||
// Ignore unknown messages to ease future extensibility. | |||
// Check if the error originated from wire/message.go:makeEmptyMessage(). | |||
if strings.Contains(err.Error(), "unhandled command") { |
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.
Should turn this into a concrete error so we can use errors.Is
here instead.
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.
According to:
Lines 142 to 146 in 7070d53
Errors | |
Errors returned by this package are either the raw errors provided by underlying | |
calls to read/write from streams such as io.EOF, io.ErrUnexpectedEOF, and | |
io.ErrShortWrite, or of type wire.MessageError. This allows the caller to |
and given that the error is returned by makeEmptyMessage()
from wire/message.go
, I guess it should be wire.MessageError
, right? It looks like error.Is
is not applicable to it?
Or do you think that ErrUnhandledCommand = errors.New("unhandled command")
should be planted somewhere, e.g. in wire/message.go
and used, probably in violation of the comment above?
Doc for wire pkg suggests no position |
This would make it possible for old versions (that contain this change)
to talk with newer versions without requiring a protocol version
increment.
Fixes #1661
Untested and probably a Go expert would devise a more robust way to do that.