feat(l1): dual-stack IPv6 support and ENR-based outbound connections#6376
feat(l1): dual-stack IPv6 support and ENR-based outbound connections#6376azteca1998 wants to merge 3 commits intofeat/p2p-discv4-vs-rlpx-addrfrom
Conversation
🤖 Kimi Code ReviewReview SummaryThis PR adds dual-stack IPv4/IPv6 support for P2P networking by allowing multiple bind addresses and properly handling IPv6 in ENRs. The changes are well-structured and follow Rust best practices. Issues Found1. Potential panic in let rlpx_bind_addrs: Vec<IpAddr> = if opts.p2p_addr.is_empty() {
// No explicit bind address — default to one entry.
let bind = if nat_extip.is_some() {
IpAddr::V4(Ipv4Addr::UNSPECIFIED)
} else {
local_ip().unwrap_or_else(|_| {
local_ipv6().expect("Neither ipv4 nor ipv6 local address found")
})
};The 2. Missing validation for address count in } else {
opts.p2p_addr
.iter()
.map(|a| a.parse().expect("Failed to parse --p2p.addr address"))
.collect()
};The code allows any number of addresses but the help text mentions "one or two comma-separated addresses". Add validation to enforce this limit. 3. Inconsistent default handling in 4. Missing IPv6 validation in Minor Suggestions1. Consider using 2. Add debug logging for address selection 3. Consider using Security ConsiderationsThe changes appear safe from a security perspective. The dual-stack support properly handles both IPv4 and IPv6 without introducing new attack vectors. The ENR construction correctly validates and sorts keys before signing. Performance ImpactThe changes are minimal performance-wise. The vector operations for multiple addresses are efficient, and the dual-stack support adds negligible overhead. Automated review by Kimi (Moonshot AI) · custom prompt |
Lines of code reportTotal lines added: Detailed view |
🤖 Claude Code ReviewHere is the review of PR #6376: Review:
|
🤖 Codex Code Review
Overall direction looks good (dual-stack listener support + ENR-based contact refresh is useful), but the input-shape validation should be tightened to avoid silent misconfiguration. I couldn’t run Automated review by OpenAI Codex · custom prompt |
430df2e to
858f935
Compare
6c0615f to
aade806
Compare
52993c0 to
a9bce4d
Compare
…#5354) - Add `NodeRecord::from_network_config()` that emits both `ip`/`tcp`/`udp` and `ip6`/`tcp6`/`udp6` ENR key-value pairs when `rlpx_external_addrs` contains addresses of both families, enabling dual-stack ENR advertisement. - Extend `NetworkConfig`: `rlpx_bind_addr`/`rlpx_external_addr` replaced by `rlpx_bind_addrs: Vec<IpAddr>` / `rlpx_external_addrs: Vec<IpAddr>`. `bind_tcp_addr()` replaced by `bind_tcp_addrs() -> Vec<SocketAddr>`. `primary_rlpx_external_addr()` helper added for single-stack code paths. - Add `NodeRecordPairs::connection_addr()` that returns the best TCP address from an ENR record (IPv4 preferred, IPv6 fallback). - Update `Contact::record_enr_response_received()` to refresh `node.ip` and `node.tcp_port` from the ENR when a valid connection address is present, enabling outbound connections to IPv6-only peers. - `network.rs`: `serve_p2p_requests()` now accepts an explicit `SocketAddr` and `start_network()` spawns one TCP listener per `bind_tcp_addrs()` entry, enabling dual-stack RLPx listening. - `--p2p.addr` CLI flag changed from `Option<String>` to `Vec<String>` with comma delimiter, accepting e.g. `--p2p.addr 0.0.0.0,::` for dual-stack. - `get_local_p2p_node()` derives per-address external IPs from the bind list and `--nat.extip`, populating `rlpx_bind_addrs` / `rlpx_external_addrs`. - `get_local_node_record()` updated to accept `&NetworkConfig` and call `NodeRecord::from_network_config()` for correct dual-stack ENR construction. Closes #5354
a9bce4d to
2ffe518
Compare
aade806 to
0b2a359
Compare
Closes #5354
Summary
--p2p.addrnow accepts a comma-separated list (e.g.--p2p.addr 0.0.0.0,::) andstart_network()spawns one TCP listener per entry.NodeRecord::from_network_config()emits bothip/tcp/udp(IPv4) andip6/tcp6/udp6(IPv6) ENR pairs when both families are configured.Contact::record_enr_response_received()now updatesnode.ipandnode.tcp_portfrom the received ENR, so the RLPx initiator can connect to IPv6-only peers.NodeRecordPairs::connection_addr(): helper that picks the best TCP address from an ENR (IPv4 preferred, IPv6 fallback).NetworkConfigrefactor:rlpx_bind_addr/rlpx_external_addr(scalar) replaced byrlpx_bind_addrs/rlpx_external_addrs(Vec<IpAddr>).Depends on
Test plan
cargo checkpasses (verified locally)--p2p.addr 0.0.0.0behaves identically to before--p2p.addr 0.0.0.0,::binds two listeners--p2p.addr 0.0.0.0 --nat.extip <pub_ip>still announces correct external addresscontact.node.ipso outbound connection uses IPv6