Improve ENR updates (#5483)

* Improve ENR updates

* forever fmt

* Appease my old friend clippy

* Merge network unstable
This commit is contained in:
Age Manning
2024-05-01 18:40:19 +10:00
committed by GitHub
parent b9655b658e
commit 59753f5fed
2 changed files with 55 additions and 15 deletions

View File

@@ -1681,12 +1681,16 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
libp2p::upnp::Event::NewExternalAddr(addr) => {
info!(self.log, "UPnP route established"; "addr" => %addr);
let mut iter = addr.iter();
// Skip Ip address.
iter.next();
let is_ip6 = {
let addr = iter.next();
matches!(addr, Some(MProtocol::Ip6(_)))
};
match iter.next() {
Some(multiaddr::Protocol::Udp(udp_port)) => match iter.next() {
Some(multiaddr::Protocol::QuicV1) => {
if let Err(e) = self.discovery_mut().update_enr_quic_port(udp_port) {
if let Err(e) =
self.discovery_mut().update_enr_quic_port(udp_port, is_ip6)
{
warn!(self.log, "Failed to update ENR"; "error" => e);
}
}
@@ -1695,7 +1699,7 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
}
},
Some(multiaddr::Protocol::Tcp(tcp_port)) => {
if let Err(e) = self.discovery_mut().update_enr_tcp_port(tcp_port) {
if let Err(e) = self.discovery_mut().update_enr_tcp_port(tcp_port, is_ip6) {
warn!(self.log, "Failed to update ENR"; "error" => e);
}
}