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

whisper: new protocol-level message codes #15802

Merged
merged 6 commits into from
Jan 12, 2018
Merged

Conversation

gluk256
Copy link
Contributor

@gluk256 gluk256 commented Jan 3, 2018

This PR contains complete functionality of PoW and Bloom Filter exchange protocol.
This is the main feature of v.6.

Copy link
Member

@gballet gballet left a comment

Choose a reason for hiding this comment

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

That was a first pass. For instance, I have not yet checked if the test coverage was good. I suggest that:

  • You use a bloom filters with all 1s for full nodes
  • You add more comments to make it easier for others (i.e. status, parity and me) to comprehend what this does
  • You break the filter test into separate tests, so that the immediate cause of the problem can be found.

if err != nil {
return false, err
}
return true, nil
Copy link
Member

Choose a reason for hiding this comment

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

can be rewritten: return (err != nil), err. Does this need to be part of this changelist, though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my style is easier to read, it's more explicit.

if err != nil {
return false, err
}
return true, nil
Copy link
Member

Choose a reason for hiding this comment

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

Same thing as above

@@ -57,6 +56,7 @@ const (
aesKeyLength = 32
AESNonceLength = 12
keyIdSize = 32
bloomFilterSize = 64
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: I would like to see a unit for that "size" Bytes? Bits? String length? A comment like the one when you define DefaultSyncAllowance below.

return e.bloom
}

func TopicToBloom(topic TopicType) []byte {
Copy link
Member

Choose a reason for hiding this comment

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

Public functions need a comment

var index [3]int
for j := 0; j < 3; j++ {
index[j] = int(topic[j])
if (topic[3] & powers[j]) != 0 {
Copy link
Member

Choose a reason for hiding this comment

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

imho, it would be more readable to write it: topic[3] & (1 << j). Creating powers on the stack for just this purpose is wasteful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanx, it was good one!

return val.(float64)
}

func (w *Whisper) BloomFilter() []byte {
Copy link
Member

Choose a reason for hiding this comment

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

Public functions need a comment

return val.([]byte)
}

func (w *Whisper) BloomFilterTolerance() []byte {
Copy link
Member

Choose a reason for hiding this comment

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

Public functions need a comment

for _, p := range arr {
err := p.notifyAboutBloomFilterChange(bloom)
if err != nil {
// allow one retry
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious: why only one?

Also, since this is a network-related function, shouldn't you wait a little before retrying?

Finally, since there's a network call in that loop, why not start a goroutine for each iteration and be done with that function? You're not waiting for the result anyway, beyond reporting that something went wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is only used in one api function, and it should wait till all the peers are notified, IMHO.
or maybe not, in which case the entire function should be called as a go routine.
but you are right, we should refactor this function later, i just don't want to do it in haste.

Copy link
Member

Choose a reason for hiding this comment

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

having the entire function as a goroutine would have the same issue. fine, let's do that later

for i := 0; i < bloomFilterSize; i++ {
f := filter[i]
s := sample[i]
if ((f | s) ^ f) != 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure what you're trying to do, but wouldn't this be more understandable as f & s == f ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanx!


if cnt == 0 {
t.Fatalf("no matching peers found.")
func isBloomFilterEqual(a, b []byte) bool {
Copy link
Member

Choose a reason for hiding this comment

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

This function should be available in the general api, not just in a test file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed

TopicLength = 4 // in bytes
signatureLength = 65 // in bytes
aesKeyLength = 32 // in bytes
AESNonceLength = 12 // in bytes
Copy link
Member

Choose a reason for hiding this comment

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

I really just meant for the Size constants. Length are usually in bytes.

@@ -51,6 +51,7 @@ type Envelope struct {

// size returns the size of envelope as it is sent (i.e. public fields only)
func (e *Envelope) size() int {
const EnvelopeHeaderLength = 20
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't this constant declared in doc.go ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because it is used only once in this function, and never again. we don't need a global constant if it can be local.

Copy link
Member

@gballet gballet Jan 8, 2018

Choose a reason for hiding this comment

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

I disagree: in spite of momentarily only being used in this specific function, this constant is a characteristic of the envelope format, and therefore its scope is the whole envelope code. So it should definitely be a top-level constant, if not documented in doc.go.

Copy link
Member

Choose a reason for hiding this comment

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

To press the point further, there are two reasons this should be defined globally:

  • Anybody who would need it will not be scanning the code to find if it's already defined. They will look at doc.go and the first lines of envelope.go.
  • documentation purposes: once again, not having to scan the entire code to get some info about the format.

if err != nil {
return false, err
}
return true, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

If the error is non-nil, the caller will not see the return value. You can use return true, err.

node.shh.SetMinimumPowTest(0.00000001)
node.shh.SetMinimumPoW(masterPow)
node.shh.SetBloomFilter(b)
if !isBloomFilterEqual(node.shh.BloomFilter(), masterBloomFilter) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use bytes.Equal and delete isBloomFilterEqual

@fjl fjl merged commit fd869dc into ethereum:master Jan 12, 2018
mariameda pushed a commit to NiluPlatform/go-nilu that referenced this pull request Aug 23, 2018
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.

3 participants