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

peer: Ignore unknown P2P messages #1671

Closed
wants to merge 2 commits into from

Conversation

vasild
Copy link

@vasild vasild commented Dec 4, 2020

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.

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
@coveralls
Copy link

coveralls commented Dec 4, 2020

Pull Request Test Coverage Report for Build 405504879

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • 16 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.01%) to 53.403%

Files with Coverage Reduction New Missed Lines %
connmgr/connmanager.go 3 86.07%
database/ffldb/blockio.go 4 92.62%
peer/peer.go 9 75.53%
Totals Coverage Status
Change from base Build 381748156: -0.01%
Covered Lines: 20830
Relevant Lines: 39005

💛 - Coveralls

@jonatack
Copy link

jonatack commented Dec 4, 2020

Concept ACK

1 similar comment
@practicalswift
Copy link

Concept ACK

@jakesylvestre jakesylvestre self-requested a review December 6, 2020 16:51
@jakesylvestre
Copy link
Collaborator

jakesylvestre commented Dec 6, 2020

Concept ACK.

Would definitely prefer to see some test cases around this. Taking a look at the error handling now.

Copy link
Collaborator

@jakesylvestre jakesylvestre left a 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

@vasild
Copy link
Author

vasild commented Dec 7, 2020

@jakesyl, thanks for the test! I added it to this PR.

(I think it upset the CI)

@jakesylvestre
Copy link
Collaborator

Looks like we need to run go fmt ./... and we should be good to go.

If you could do that and push that’d be awesome otherwise I’ll get to it tomorrow (it’s 4:30 am here 💤)

@vasild vasild force-pushed the ignore_unknown_messages branch from 7141bda to ac83f0d Compare December 7, 2020 09:44
Copy link
Collaborator

@jakesylvestre jakesylvestre left a 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

@jakesylvestre jakesylvestre added this to the 0.22.0 milestone Dec 7, 2020
@Roasbeef
Copy link
Member

Roasbeef commented Dec 8, 2020

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.
Copy link
Member

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

Copy link
Collaborator

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

@vasild
Copy link
Author

vasild commented Dec 8, 2020

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.

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.

@onyb
Copy link
Contributor

onyb commented Apr 13, 2021

Do we still need this PR, considering #1661 is already resolved by #1670?

@Roasbeef
Copy link
Member

I think it's still relevant since it sets us up to be able to gracefully handle any other new messages introduced.

Copy link
Member

@Roasbeef Roasbeef left a 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)
Copy link
Member

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.

Copy link
Author

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") {
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

According to:

btcd/wire/doc.go

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?

@cubancorona
Copy link

Doc for wire pkg suggests no position

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.

Btcd disconnects upon receiving sendaddrv2
9 participants