You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
At the time of creation, this code only exists in the branch gsalgado:p2p under @gsalgado 's fork.
What is wrong?
The current implementation of evm.p2p.kademlia.RoutingTable.get_bucket_for_node is implemented such that it operates in linear runtime.
How can it be fixed
This can be fixed by doing two things:
Implementing ordering for the Bucket class.
Using the bisect module to lookup the appropriate bucket using a binary search.
In order to make the Bucket class orderable, you should use the functools.total_ordering class decorator. Buckets should be sorted by Bucket.end
Once the Bucket class can be ordered, you should use the bisect module to perform a binary search on the bucket list to find the appropriate bucket for the given node.
The criteria for a bucket/node match are: Bucket.start <= node.id <= Bucket.end
How to test it
This functionality should be written as a standalone function which takes a list of buckets and the node and returns the bucket. If no bucket is found for the given node then a ValueError should be raised.