Throw decoding exception if there's an invalid node distance #157
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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]
.I see that this is enforced in the
KBuckets
class, but I think we should throw a decoding error if we receive aFindNodeMessage
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 🤷