mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-18 04:13:00 +00:00
No string in slog (#2017)
## Issue Addressed Following slog's documentation, this should help a bit with string allocations. I left it run for two days and mem usage is lower. This is of course anecdotal, but shouldn't harm anyway ## Proposed Changes remove `String` creation in logs when possible
This commit is contained in:
@@ -70,7 +70,7 @@ pub fn use_or_load_enr(
|
||||
// if the same node id, then we may need to update our sequence number
|
||||
if local_enr.node_id() == disk_enr.node_id() {
|
||||
if compare_enr(&local_enr, &disk_enr) {
|
||||
debug!(log, "ENR loaded from disk"; "file" => format!("{:?}", enr_f));
|
||||
debug!(log, "ENR loaded from disk"; "file" => ?enr_f);
|
||||
// the stored ENR has the same configuration, use it
|
||||
*local_enr = disk_enr;
|
||||
return Ok(());
|
||||
@@ -87,7 +87,7 @@ pub fn use_or_load_enr(
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(log, "ENR from file could not be decoded"; "error" => format!("{:?}", e));
|
||||
warn!(log, "ENR from file could not be decoded"; "error" => ?e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,7 @@ pub fn save_enr_to_disk(dir: &Path, enr: &Enr, log: &slog::Logger) {
|
||||
Err(e) => {
|
||||
warn!(
|
||||
log,
|
||||
"Could not write ENR to file"; "file" => format!("{:?}{:?}",dir, ENR_FILENAME), "error" => format!("{}", e)
|
||||
"Could not write ENR to file"; "file" => format!("{:?}{:?}",dir, ENR_FILENAME), "error" => %e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
|
||||
let local_enr = network_globals.local_enr.read().clone();
|
||||
|
||||
info!(log, "ENR Initialised"; "enr" => local_enr.to_base64(), "seq" => local_enr.seq(), "id"=> format!("{}",local_enr.node_id()), "ip" => format!("{:?}", local_enr.ip()), "udp"=> format!("{:?}", local_enr.udp()), "tcp" => format!("{:?}", local_enr.tcp()));
|
||||
info!(log, "ENR Initialised"; "enr" => local_enr.to_base64(), "seq" => local_enr.seq(), "id"=> %local_enr.node_id(), "ip" => ?local_enr.ip(), "udp"=> ?local_enr.udp(), "tcp" => ?local_enr.tcp());
|
||||
|
||||
let listen_socket = SocketAddr::new(config.listen_address, config.discovery_port);
|
||||
|
||||
@@ -193,11 +193,11 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
debug!(
|
||||
log,
|
||||
"Adding node to routing table";
|
||||
"node_id" => bootnode_enr.node_id().to_string(),
|
||||
"peer_id" => bootnode_enr.peer_id().to_string(),
|
||||
"ip" => format!("{:?}", bootnode_enr.ip()),
|
||||
"udp" => format!("{:?}", bootnode_enr.udp()),
|
||||
"tcp" => format!("{:?}", bootnode_enr.tcp())
|
||||
"node_id" => %bootnode_enr.node_id(),
|
||||
"peer_id" => %bootnode_enr.peer_id(),
|
||||
"ip" => ?bootnode_enr.ip(),
|
||||
"udp" => ?bootnode_enr.udp(),
|
||||
"tcp" => ?bootnode_enr.tcp()
|
||||
);
|
||||
let repr = bootnode_enr.to_string();
|
||||
let _ = discv5.add_enr(bootnode_enr).map_err(|e| {
|
||||
@@ -247,11 +247,11 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
debug!(
|
||||
log,
|
||||
"Adding node to routing table";
|
||||
"node_id" => enr.node_id().to_string(),
|
||||
"peer_id" => enr.peer_id().to_string(),
|
||||
"ip" => format!("{:?}", enr.ip()),
|
||||
"udp" => format!("{:?}", enr.udp()),
|
||||
"tcp" => format!("{:?}", enr.tcp())
|
||||
"node_id" => %enr.node_id(),
|
||||
"peer_id" => %enr.peer_id(),
|
||||
"ip" => ?enr.ip(),
|
||||
"udp" => ?enr.udp(),
|
||||
"tcp" => ?enr.tcp()
|
||||
);
|
||||
let _ = discv5.add_enr(enr).map_err(|e| {
|
||||
error!(
|
||||
@@ -318,7 +318,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
debug!(
|
||||
self.log,
|
||||
"Making discovery query for subnets";
|
||||
"subnets" => format!("{:?}", subnets_to_discover.iter().map(|s| s.subnet_id).collect::<Vec<_>>())
|
||||
"subnets" => ?subnets_to_discover.iter().map(|s| s.subnet_id).collect::<Vec<_>>()
|
||||
);
|
||||
for subnet in subnets_to_discover {
|
||||
self.add_subnet_query(subnet.subnet_id, subnet.min_ttl, 0);
|
||||
@@ -334,7 +334,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
debug!(
|
||||
self.log,
|
||||
"Could not add peer to the local routing table";
|
||||
"error" => e.to_string()
|
||||
"error" => %e
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -461,8 +461,8 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
};
|
||||
|
||||
info!(self.log, "Updating the ENR fork version";
|
||||
"fork_digest" => format!("{:?}", enr_fork_id.fork_digest),
|
||||
"next_fork_version" => format!("{:?}", enr_fork_id.next_fork_version),
|
||||
"fork_digest" => ?enr_fork_id.fork_digest,
|
||||
"next_fork_version" => ?enr_fork_id.next_fork_version,
|
||||
"next_fork_epoch" => next_fork_epoch_log,
|
||||
);
|
||||
|
||||
@@ -473,7 +473,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
warn!(
|
||||
self.log,
|
||||
"Could not update eth2 ENR field";
|
||||
"error" => format!("{:?}", e)
|
||||
"error" => ?e
|
||||
)
|
||||
});
|
||||
|
||||
@@ -607,7 +607,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
debug!(
|
||||
self.log,
|
||||
"Starting grouped subnet query";
|
||||
"subnets" => format!("{:?}", grouped_queries.iter().map(|q| q.subnet_id).collect::<Vec<_>>()),
|
||||
"subnets" => ?grouped_queries.iter().map(|q| q.subnet_id).collect::<Vec<_>>(),
|
||||
);
|
||||
self.start_subnet_query(grouped_queries);
|
||||
processed = true;
|
||||
@@ -659,7 +659,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
"target_subnet_peers" => TARGET_SUBNET_PEERS,
|
||||
"peers_to_find" => target_peers,
|
||||
"attempt" => subnet_query.retries,
|
||||
"min_ttl" => format!("{:?}", subnet_query.min_ttl),
|
||||
"min_ttl" => ?subnet_query.min_ttl,
|
||||
);
|
||||
|
||||
filtered_subnet_ids.push(subnet_query.subnet_id);
|
||||
@@ -757,7 +757,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
return Some(results);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(self.log, "Discovery query failed"; "error" => e.to_string());
|
||||
warn!(self.log, "Discovery query failed"; "error" => %e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -766,10 +766,10 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
queries.iter().map(|query| query.subnet_id).collect();
|
||||
match query_result.1 {
|
||||
Ok(r) if r.is_empty() => {
|
||||
debug!(self.log, "Grouped subnet discovery query yielded no results."; "subnets_searched_for" => format!("{:?}",subnets_searched_for));
|
||||
debug!(self.log, "Grouped subnet discovery query yielded no results."; "subnets_searched_for" => ?subnets_searched_for);
|
||||
}
|
||||
Ok(r) => {
|
||||
debug!(self.log, "Peer grouped subnet discovery request completed"; "peers_found" => r.len(), "subnets_searched_for" => format!("{:?}",subnets_searched_for));
|
||||
debug!(self.log, "Peer grouped subnet discovery request completed"; "peers_found" => r.len(), "subnets_searched_for" => ?subnets_searched_for);
|
||||
|
||||
let mut mapped_results = HashMap::new();
|
||||
|
||||
@@ -836,7 +836,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(self.log,"Grouped subnet discovery query failed"; "subnets_searched_for" => format!("{:?}",subnets_searched_for), "error" => e.to_string());
|
||||
warn!(self.log,"Grouped subnet discovery query failed"; "subnets_searched_for" => ?subnets_searched_for, "error" => %e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -881,7 +881,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
self.event_stream = EventStream::Present(stream);
|
||||
}
|
||||
Err(e) => {
|
||||
slog::crit!(self.log, "Discv5 event stream failed"; "error" => e.to_string());
|
||||
slog::crit!(self.log, "Discv5 event stream failed"; "error" => %e);
|
||||
self.event_stream = EventStream::InActive;
|
||||
}
|
||||
}
|
||||
@@ -907,7 +907,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
*/
|
||||
}
|
||||
Discv5Event::SocketUpdated(socket) => {
|
||||
info!(self.log, "Address updated"; "ip" => format!("{}",socket.ip()), "udp_port" => format!("{}", socket.port()));
|
||||
info!(self.log, "Address updated"; "ip" => %socket.ip(), "udp_port" => %socket.port());
|
||||
metrics::inc_counter(&metrics::ADDRESS_UPDATE_COUNT);
|
||||
// Discv5 will have updated our local ENR. We save the updated version
|
||||
// to disk.
|
||||
|
||||
@@ -34,15 +34,15 @@ where
|
||||
trace!(
|
||||
log_clone,
|
||||
"Peer found but not on any of the desired subnets";
|
||||
"peer_id" => format!("{}", enr.peer_id())
|
||||
"peer_id" => %enr.peer_id()
|
||||
);
|
||||
return false;
|
||||
} else {
|
||||
trace!(
|
||||
log_clone,
|
||||
"Peer found on desired subnet(s)";
|
||||
"peer_id" => format!("{}", enr.peer_id()),
|
||||
"subnets" => format!("{:?}", matches.as_slice())
|
||||
"peer_id" => %enr.peer_id(),
|
||||
"subnets" => ?matches.as_slice()
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user