Skip to content

Bug: --p2p-udp-port is ignored for ENR/discovery_addresses advertised port #10915

Description

@MqllR

Summary

When --p2p-udp-port is set to a value different from --p2p-port, the advertised UDP port in the ENR and in the /eth/v1/node/identity discovery_addresses field still shows the TCP port instead of the configured UDP port.

Steps to Reproduce

Start Teku with:

--p2p-port=9000
--p2p-udp-port=9001
--p2p-advertised-ip=<public-ip>

Query the identity endpoint:

GET /eth/v1/node/identity

Expected Behavior

discovery_addresses should contain /ip4/<public-ip>/udp/9001/... and the ENR should encode UDP port 9001.

Actual Behavior

discovery_addresses contains /ip4/<public-ip>/udp/9000/... and the ENR encodes UDP port 9000. The --p2p-udp-port=9001 value is silently ignored for the advertised port.

Root Cause

In P2PConfig.build() (networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/P2PConfig.java:361):

discoveryConfig.advertisedUdpPortDefault(OptionalInt.of(networkConfig.getAdvertisedPort())); // TCP port = 9000

This runs after P2POptions.configure() has called discoveryConfig.listenUdpPort(9001), and it fills in advertisedUdpPort with the TCP port (9000) because advertisedUdpPort is still empty at that point.

DiscoveryConfig.getAdvertisedUdpPort() is:

return advertisedUdpPort.orElse(listenUdpPort);

The intent was: fall back to listenUdpPort (9001) when no explicit --p2p-advertised-udp-port is set. But because advertisedUdpPortDefault runs after and fills in the value with 9000, the fallback to listenUdpPort is never reached.

Workaround

Add --p2p-advertised-udp-port=9001 explicitly alongside --p2p-udp-port=9001. Since this sets advertisedUdpPort to a non-empty value before P2PConfig.build() runs, the advertisedUdpPortDefault(9000) call becomes a no-op.

Fix Direction

P2PConfig.build() should only propagate the TCP advertised port as the UDP advertised default when --p2p-udp-port was not explicitly set. When a UDP listen port has been explicitly configured, it should take precedence over the TCP port for the UDP advertised default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions