Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions beacon_node/lighthouse_network/src/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ pub struct Discovery<TSpec: EthSpec> {
/// always false.
pub started: bool,

/// This keeps track of whether an external UDP port change should also indicate an internal
/// TCP port change. As we cannot detect our external TCP port, we assume that the external UDP
/// port is also our external TCP port. This assumption only holds if the user has not
/// explicitly set their ENR TCP port via the CLI config.
update_tcp_port: bool,

/// Logger for the discovery behaviour.
log: slog::Logger,
}
Expand Down Expand Up @@ -290,6 +296,8 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
}
}

let update_tcp_port = config.enr_tcp_port.is_none();

Ok(Self {
cached_enrs: LruCache::new(50),
network_globals,
Expand All @@ -299,6 +307,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
discv5,
event_stream,
started: !config.disable_discovery,
update_tcp_port,
log,
enr_dir,
})
Expand Down Expand Up @@ -1009,6 +1018,10 @@ impl<TSpec: EthSpec> NetworkBehaviour for Discovery<TSpec> {
metrics::check_nat();
// Discv5 will have updated our local ENR. We save the updated version
// to disk.
if self.update_tcp_port {
// Update the TCP port in the ENR
self.discv5.update_local_enr_socket(socket_addr, true);
}
let enr = self.discv5.local_enr();
enr::save_enr_to_disk(Path::new(&self.enr_dir), &enr, &self.log);
// update network globals
Expand Down