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.
Summary
When
--p2p-udp-portis set to a value different from--p2p-port, the advertised UDP port in the ENR and in the/eth/v1/node/identitydiscovery_addressesfield still shows the TCP port instead of the configured UDP port.Steps to Reproduce
Start Teku with:
Query the identity endpoint:
Expected Behavior
discovery_addressesshould contain/ip4/<public-ip>/udp/9001/...and the ENR should encode UDP port 9001.Actual Behavior
discovery_addressescontains/ip4/<public-ip>/udp/9000/...and the ENR encodes UDP port 9000. The--p2p-udp-port=9001value 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):This runs after
P2POptions.configure()has calleddiscoveryConfig.listenUdpPort(9001), and it fills inadvertisedUdpPortwith the TCP port (9000) becauseadvertisedUdpPortis still empty at that point.DiscoveryConfig.getAdvertisedUdpPort()is:The intent was: fall back to
listenUdpPort(9001) when no explicit--p2p-advertised-udp-portis set. But becauseadvertisedUdpPortDefaultruns after and fills in the value with 9000, the fallback tolistenUdpPortis never reached.Workaround
Add
--p2p-advertised-udp-port=9001explicitly alongside--p2p-udp-port=9001. Since this setsadvertisedUdpPortto a non-empty value beforeP2PConfig.build()runs, theadvertisedUdpPortDefault(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-portwas 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.