Skip to content

Conversation

divagant-martian
Copy link
Contributor

@divagant-martian divagant-martian commented Feb 13, 2023

Issue Addressed

Add support for ipv6 and dual stack in lighthouse.

Proposed Changes

From an user perspective, now setting an ipv6 address, optionally configuring the ports should feel exactly the same as using an ipv4 address. If listening over both ipv4 and ipv6 then the user needs to:

  • use the --listen-address two times (ipv4 and ipv6 addresses)
  • --port6 becomes then required
  • --discovery-port6 can now be used to additionally configure the ipv6 udp port

Rough list of code changes

  • Discovery:
    • Ipv6 address, tcp port and udp port set in the ENR builder
    • Reported addresses now check which tcp port to give to libp2p
  • LH Network Service:
    • Can listen over Ipv6, Ipv4, or both. This uses two sockets. Using mapped addresses is disabled from libp2p and it's the most compatible option.
  • NetworkGlobals:
    • No longer stores udp port since was not used at all. Instead, stores the Ipv4 and Ipv6 TCP ports.
  • NetworkConfig:
    • Update names to make it clear that previous udp and tcp ports in ENR were Ipv4
    • Add fields to configure Ipv6 udp and tcp ports in the ENR
    • Include advertised enr Ipv6 address.
    • Add type to model Listening address that's either Ipv4, Ipv6 or both. A listening address includes the ip, udp port and tcp port.
  • UPnP:
    • Kept only for ipv4
  • Cli flags:
    • --listen-addresses now can take up to two values
    • --port will apply to ipv4 or ipv6 if only one listening address is given. If two listening addresses are given it will apply only to Ipv4.
    • --port6 New flag required when listening over ipv4 and ipv6 that applies exclusively to Ipv6.
    • --discovery-port will now apply to ipv4 and ipv6 if only one listening address is given.
    • --discovery-port6 New flag to configure the individual udp port of ipv6 if listening over both ipv4 and ipv6.
    • --enr-udp-port Updated docs to specify that it only applies to ipv4. This is an old behaviour.
    • --enr-udp6-port Added to configure the enr udp6 field.
    • --enr-tcp-port Updated docs to specify that it only applies to ipv4. This is an old behaviour.
    • --enr-tcp6-port Added to configure the enr tcp6 field.
    • --enr-addresses now can take two values.
  • Common:
    • rename unused_port functions to specify that they are over ipv4.
    • add functions to get unused ports over ipv6.
  • Testing binaries
    • Updated code to reflect network config changes and unused_port changes.

Additional Info

TODOs:

  • set the ip filters with respect to the listening sockets.
  • use two sockets in discovery.
  • lcli allow listening over two sockets in generate_bootnodes_enr
  • add cli flag tests
  • add at least one smoke flag for ipv6

Copy link
Member

@AgeManning AgeManning left a comment

Choose a reason for hiding this comment

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

Had a preliminary review, looks good.

There is a lot more conditional handling of CLI args. It might be worth adding some tests here to try and check some of these: https://github.com/sigp/lighthouse/blob/stable/lighthouse/tests/beacon_node.rs

(I can help out with these tests when this PR is ready for final review)

.or_else(|| config.listen_addresses.v4().map(|v4_addr| v4_addr.tcp_port));
if let Some(tcp_port) = tcp4_port {
builder.tcp4(tcp_port);
}
Copy link
Member

Choose a reason for hiding this comment

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

🤔 - Is there a case where this can be None? Should we error in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when it's an only ipv6 node, which wouldn't be an error

udp_port: config.discovery_port,
impl UPnPConfig {
pub fn from_config(config: &NetworkConfig) -> Option<Self> {
// TODO: need to read more on UPnP over ipv6
Copy link
Member

Choose a reason for hiding this comment

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

Yeah me too. I think the UPnP library is pretty opaque and we just send it IPs and the router tries to open them for us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for completeness I add it here: the lib we use accepts exclusively ipv4 addresses so this is basically left as work for the future

@@ -25,10 +25,21 @@ pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
));
}

// TODO: allow using dual stack.
Copy link
Member

Choose a reason for hiding this comment

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

Libp2p supports this right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the generate_bootnode_enr so I think this is not relevant here. I'm disallowing dual stack in this cases for now, but to answer the question yes of course

@divagant-martian
Copy link
Contributor Author

closed in favor of #4046

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.

2 participants