Skip to content

Add Discovery V5 alongside V4 #3489

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

Merged
merged 9 commits into from
Jul 21, 2025
Merged

Add Discovery V5 alongside V4 #3489

merged 9 commits into from
Jul 21, 2025

Conversation

jangko
Copy link
Contributor

@jangko jangko commented Jul 19, 2025

Also cleanup peer pool and EthereumNode async start and termination. Async raises in Discovery V4 also refactored.
There is no algorithm changes, only modify error handling of both receiver proc. So when discovery V4 cannot handle incoming message, there is discovery V5 waiting to handle it.
If both of them error, the error will be logged with two error message.

And this is test result from hive, some test cases are failing. But other clients also have no perfect score:

jangko@Jangko-MSI:~/hive$ ./hive --sim devp2p --sim.limit discv5 --client nimbus-el
Jul 19 22:16:03.463 INF building image image=hive/hiveproxy nocache=false pull=false
Jul 19 22:16:03.491 INF building 1 clients...
Jul 19 22:16:03.491 INF building image image=hive/clients/nimbus-el:latest dir=clients/nimbus-el nocache=false pull=false
Jul 19 22:16:04.062 INF building 1 simulators...
Jul 19 22:16:04.062 INF building image image=hive/simulators/devp2p:latest dir=simulators/devp2p nocache=false pull=false
Jul 19 22:16:04.123 INF running simulation: devp2p
Jul 19 22:16:04.332 INF hiveproxy started container=2b7ab4068cb6 addr=172.17.0.4:8081
Jul 19 22:16:04.552 INF API: suite started suite=0 name=discv5
Jul 19 22:16:04.554 INF API: test started suite=0 test=1 name=nimbus-el
Jul 19 22:16:04.854 INF API: client nimbus-el started suite=0 test=1 container=5fe0323c
Jul 19 22:16:04.884 INF API: network created name=network1
Jul 19 22:16:04.979 INF API: container connected to network network=network1 container=simulation
Jul 19 22:16:04.981 INF API: container IP requested network=bridge container=simulation ip=172.17.0.5
Jul 19 22:16:04.983 INF API: container IP requested network=network1 container=simulation ip=172.20.0.2
Jul 19 22:16:05.078 INF API: container connected to network network=network1 container=5fe0323c
Jul 19 22:16:05.135 INF API: container IP requested network=bridge container=5fe0323c ip=172.17.0.6
Jul 19 22:16:05.451 INF API: test started suite=0 test=2 name="Ping (nimbus-el)"
Jul 19 22:16:05.452 INF API: test ended suite=0 test=2 pass=true
Jul 19 22:16:05.756 INF API: test started suite=0 test=3 name="PingLargeRequestID (nimbus-el)"
Jul 19 22:16:05.758 INF API: test ended suite=0 test=3 pass=true
Jul 19 22:16:06.061 INF API: test started suite=0 test=4 name="PingMultiIP (nimbus-el)"
Jul 19 22:16:06.062 INF API: test ended suite=0 test=4 pass=false
Jul 19 22:16:06.068 INF API: test started suite=0 test=5 name="PingHandshakeInterrupted (nimbus-el)"
Jul 19 22:16:06.069 INF API: test ended suite=0 test=5 pass=false
Jul 19 22:16:06.072 INF API: test started suite=0 test=6 name="TalkRequest (nimbus-el)"
Jul 19 22:16:06.073 INF API: test ended suite=0 test=6 pass=true
Jul 19 22:17:06.078 INF API: test started suite=0 test=7 name="FindnodeZeroDistance (nimbus-el)"
Jul 19 22:17:06.079 INF API: test ended suite=0 test=7 pass=true
Jul 19 22:17:06.082 INF API: test started suite=0 test=8 name="FindnodeResults (nimbus-el)"
Jul 19 22:17:06.084 INF API: test ended suite=0 test=8 pass=false
Jul 19 22:17:06.405 INF API: test ended suite=0 test=1 pass=false
Jul 19 22:17:06.408 INF removing docker network name=network1
Jul 19 22:17:06.599 INF API: suite ended suite=0
Jul 19 22:17:06.964 INF simulation devp2p finished suites=1 tests=8 failed=4
4 tests failed

fix #2799

jangko added 9 commits July 19, 2025 22:01
Also cleanup peer pool and EthereumNode async start and termination.
Async raises in Discovery V4 also refactored.
There is no algorithm changes, only modify error handling of both
receiver proc. So when discovery V4 cannot handle incoming message,
there is discovery V5 waiting to handle it.
If both of them error, the error will be logged with two error message.
@jangko jangko enabled auto-merge (squash) July 21, 2025 06:00
@jangko jangko merged commit e29e529 into master Jul 21, 2025
5 checks passed
@jangko jangko deleted the discv5 branch July 21, 2025 06:04
Comment on lines +126 to +160
proc open*(
proto: Eth1Discovery, enableDiscV4: bool, enableDiscV5: bool
) {.raises: [TransportOsError].} =
# TODO: allow binding to both IPv4 and IPv6

if not (enableDiscV4 or enableDiscV5):
return

privateAccess(DiscV4)
privateAccess(DiscV5)

info "Starting discovery node",
node = proto.discv4.localNode,
bindAddress = proto.discv4.address,
discV4 = enableDiscV4,
discV5 = enableDiscV5

if enableDiscV4 and not enableDiscV5:
proto.discv4.open()
proto.discv5 = nil
return

if enableDiscV5 and not enableDiscV4:
proto.discv5.open()
proto.discv4 = nil
proto.discv5.seedTable()
return

# Both DiscV4 and DiscV5 share the same transport
# Unhandled data from DiscV4 will be handled by DiscV5
let ta = initTAddress(proto.discv4.bindIp, proto.discv4.bindPort)
proto.discv4.transp = newDatagramTransport(processClient, udata = proto, local = ta)
proto.discv5.transp = proto.discv4.transp
proto.discv5.seedTable()

Copy link
Contributor

@kdeme kdeme Jul 21, 2025

Choose a reason for hiding this comment

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

This isn't exactly the cleanest solution as it rather hacks around the existing APIs and requires some duplication also.

But I assume it works and allows for quick way of using both. However if both are required in the "long" term future still, we should revise this definitely.

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.

Add support for discv5 discovery
2 participants