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

Throw decoding exception if there's an invalid node distance #157

Merged
merged 3 commits into from
Oct 26, 2022

Conversation

jtraglia
Copy link
Contributor

PR Description

According to the spec, there are 256 buckets and 0 is reserved for our node, so a distance value can be in [0, 256].

For each 0 ≤ i < 256, every node keeps a k-bucket for nodes of logdistance(self, n) == I. The Node Discovery Protocol uses k = 16, i.e. every k-bucket contains up to 16 node entries.

I see that this is enforced in the KBuckets class, but I think we should throw a decoding error if we receive a FindNodeMessage with an invalid distance. We could just ignore that distance, but I think we should ignore the message:

https://github.com/ConsenSys/discovery/blob/d780ba4642db8acd1a6a8253d9e86018eafb8b89/src/main/java/org/ethereum/beacon/discovery/storage/KBuckets.java#L22-L29

Also, in my opinion, the spec is pretty vague about this detail. My first impression told me that a distance of 256 is invalid, but after I thought more about it, it seems valid. I'm still kind of confused though 🤷

@jtraglia jtraglia changed the title Check node distance Throw decoding exception if there's an invalid node distance Oct 20, 2022
…ode-distance

# Conflicts:
#	src/main/java/org/ethereum/beacon/discovery/message/FindNodeMessage.java
Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

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

LGTM. I think you're right that 256 is a valid distance (and also agree that the spec is unclear...)

@ajsutton ajsutton merged commit 46358e0 into Consensys:master Oct 26, 2022
@jtraglia jtraglia deleted the check-node-distance branch October 26, 2022 21:03
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