Skip to content

fix: support IPv6 enode URLs - #20

Open
iamomm-hack wants to merge 1 commit into
ethereum:mainfrom
iamomm-hack:fix/ipv6-enode-round-trip
Open

iamomm-hack wants to merge 1 commit into
ethereum:mainfrom
iamomm-hack:fix/ipv6-enode-round-trip

Conversation

@iamomm-hack

Copy link
Copy Markdown

Summary

  • parse canonical bracketed IPv6 enode:// endpoints returned by Ethereum clients
  • emit IPv6 endpoints with RFC 3986 brackets so serialized URLs remain unambiguous
  • preserve existing IPv4 behavior and add IPv4/IPv6 round-trip regression coverage
  • document the fix in the changelog

Problem

ClientEnode.from_string() split the endpoint on every colon:

ip, port = ip_port.split(":")

That works for IPv4, but a valid client response such as:

enode://<node-id>@[2001:db8::1]:30303

contains multiple colons and raises ValueError: too many values to unpack. This matters because Hive obtains the client P2P endpoint from enode.sh; IPv6-only or dual-stack test environments can therefore fail before a simulator can connect to the client.

The serializer had the inverse problem: it emitted ...@2001:db8::1:30303, where the address/port boundary is ambiguous. go-ethereum's canonical Node.URLv4() representation uses the standard bracketed host form for IPv6.

Implementation

The parser now splits the port from the right once, removes the brackets before passing the host to ip_address(), and limits the node-id split to one separator. ClientEnode.__str__() brackets IPv6Address values while leaving IPv4 output unchanged.

Keeping the parsed field as IPv4Address | IPv6Address retains the existing API and validation behavior; this is only a correction to endpoint parsing and serialization.

Validation

  • uv run pytest src/hive/tests/test_client.py src/hive/tests/test_session.py — 7 passed
  • uv run black --check src — passed
  • uv run isort --check-only src — passed
  • uv run mypy src — passed
  • complete uv run pytest reaches 9 tests; the 7 self-contained tests pass and the 2 existing Hive sanity tests require a live Hive API on 127.0.0.1:3000

Compatibility

No public types or method signatures change. Existing IPv4 enode strings serialize exactly as before; IPv6 strings now round-trip in the canonical form accepted and produced by Ethereum clients.

This branch has not been deployed

No deployments
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.

1 participant