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:
divma 2020-11-30 10:33:00 +00:00
parent 3f036fd193
commit 8fcd22992c
22 changed files with 160 additions and 158 deletions

View File

@ -198,7 +198,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
current_slot, current_slot,
)?; )?;
trace!(behaviour_log, "Using peer score params"; "params" => format!("{:?}", params)); trace!(behaviour_log, "Using peer score params"; "params" => ?params);
let update_gossipsub_scores = tokio::time::interval(params.decay_interval); let update_gossipsub_scores = tokio::time::interval(params.decay_interval);
@ -241,9 +241,9 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
debug!(self.log, "Updating gossipsub score parameters"; debug!(self.log, "Updating gossipsub score parameters";
"active_validators" => active_validators); "active_validators" => active_validators);
trace!(self.log, "Updated gossipsub score parameters"; trace!(self.log, "Updated gossipsub score parameters";
"beacon_block_params" => format!("{:?}", beacon_block_params), "beacon_block_params" => ?beacon_block_params,
"beacon_aggregate_proof_params" => format!("{:?}", beacon_aggregate_proof_params), "beacon_aggregate_proof_params" => ?beacon_aggregate_proof_params,
"beacon_attestation_subnet_params" => format!("{:?}", beacon_attestation_subnet_params), "beacon_attestation_subnet_params" => ?beacon_attestation_subnet_params,
); );
self.gossipsub self.gossipsub
@ -341,11 +341,11 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
match self.gossipsub.subscribe(&topic) { match self.gossipsub.subscribe(&topic) {
Err(_) => { Err(_) => {
warn!(self.log, "Failed to subscribe to topic"; "topic" => topic.to_string()); warn!(self.log, "Failed to subscribe to topic"; "topic" => %topic);
false false
} }
Ok(v) => { Ok(v) => {
debug!(self.log, "Subscribed to topic"; "topic" => topic.to_string()); debug!(self.log, "Subscribed to topic"; "topic" => %topic);
v v
} }
} }
@ -364,11 +364,11 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
match self.gossipsub.unsubscribe(&topic) { match self.gossipsub.unsubscribe(&topic) {
Err(_) => { Err(_) => {
warn!(self.log, "Failed to unsubscribe from topic"; "topic" => topic.to_string()); warn!(self.log, "Failed to unsubscribe from topic"; "topic" => %topic);
false false
} }
Ok(v) => { Ok(v) => {
debug!(self.log, "Unsubscribed to topic"; "topic" => topic.to_string()); debug!(self.log, "Unsubscribed to topic"; "topic" => %topic);
v v
} }
} }
@ -382,7 +382,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
Ok(message_data) => { Ok(message_data) => {
if let Err(e) = self.gossipsub.publish(topic.clone().into(), message_data) { if let Err(e) = self.gossipsub.publish(topic.clone().into(), message_data) {
slog::warn!(self.log, "Could not publish message"; slog::warn!(self.log, "Could not publish message";
"error" => format!("{:?}", e)); "error" => ?e);
// add to metrics // add to metrics
match topic.kind() { match topic.kind() {
@ -424,7 +424,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
propagation_source, propagation_source,
validation_result, validation_result,
) { ) {
warn!(self.log, "Failed to report message validation"; "message_id" => message_id.to_string(), "peer_id" => propagation_source.to_string(), "error" => format!("{:?}", e)); warn!(self.log, "Failed to report message validation"; "message_id" => %message_id, "peer_id" => %propagation_source, "error" => ?e);
} }
} }
@ -565,7 +565,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
let ping = crate::rpc::Ping { let ping = crate::rpc::Ping {
data: self.network_globals.local_metadata.read().seq_number, data: self.network_globals.local_metadata.read().seq_number,
}; };
trace!(self.log, "Sending Ping"; "request_id" => id, "peer_id" => peer_id.to_string()); trace!(self.log, "Sending Ping"; "request_id" => id, "peer_id" => %peer_id);
self.eth2_rpc self.eth2_rpc
.send_request(peer_id, id, RPCRequest::Ping(ping)); .send_request(peer_id, id, RPCRequest::Ping(ping));
@ -576,7 +576,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
let ping = crate::rpc::Ping { let ping = crate::rpc::Ping {
data: self.network_globals.local_metadata.read().seq_number, data: self.network_globals.local_metadata.read().seq_number,
}; };
trace!(self.log, "Sending Pong"; "request_id" => id.1, "peer_id" => peer_id.to_string()); trace!(self.log, "Sending Pong"; "request_id" => id.1, "peer_id" => %peer_id);
let event = RPCCodedResponse::Success(RPCResponse::Pong(ping)); let event = RPCCodedResponse::Success(RPCResponse::Pong(ping));
self.eth2_rpc.send_response(peer_id, id, event); self.eth2_rpc.send_response(peer_id, id, event);
} }
@ -620,7 +620,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
&propagation_source, &propagation_source,
MessageAcceptance::Reject, MessageAcceptance::Reject,
) { ) {
warn!(self.log, "Failed to report message validation"; "message_id" => id.to_string(), "peer_id" => propagation_source.to_string(), "error" => format!("{:?}", e)); warn!(self.log, "Failed to report message validation"; "message_id" => %id, "peer_id" => %propagation_source, "error" => ?e);
} }
} }
Ok(msg) => { Ok(msg) => {
@ -669,7 +669,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
debug!( debug!(
self.log, self.log,
"Ignoring rpc message of disconnected peer"; "Ignoring rpc message of disconnected peer";
"peer" => peer_id.to_string() "peer" => %peer_id
); );
return; return;
} }
@ -730,9 +730,9 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
// queue for disconnection without a goodbye message // queue for disconnection without a goodbye message
debug!( debug!(
self.log, "Peer sent Goodbye"; self.log, "Peer sent Goodbye";
"peer_id" => peer_id.to_string(), "peer_id" => %peer_id,
"reason" => reason.to_string(), "reason" => %reason,
"client" => self.network_globals.client(&peer_id).to_string(), "client" => %self.network_globals.client(&peer_id),
); );
self.peers_to_dc.push_back((peer_id, None)); self.peers_to_dc.push_back((peer_id, None));
// NOTE: We currently do not inform the application that we are // NOTE: We currently do not inform the application that we are
@ -835,7 +835,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
} }
PeerManagerEvent::DisconnectPeer(peer_id, reason) => { PeerManagerEvent::DisconnectPeer(peer_id, reason) => {
debug!(self.log, "PeerManager disconnecting peer"; debug!(self.log, "PeerManager disconnecting peer";
"peer_id" => peer_id.to_string(), "reason" => reason.to_string()); "peer_id" => %peer_id, "reason" => %reason);
// send one goodbye // send one goodbye
return Poll::Ready(NBAction::NotifyHandler { return Poll::Ready(NBAction::NotifyHandler {
peer_id, peer_id,
@ -881,12 +881,12 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
// send peer info to the peer manager. // send peer info to the peer manager.
self.peer_manager.identify(&peer_id, &info); self.peer_manager.identify(&peer_id, &info);
debug!(self.log, "Identified Peer"; "peer" => format!("{}", peer_id), debug!(self.log, "Identified Peer"; "peer" => %peer_id,
"protocol_version" => info.protocol_version, "protocol_version" => info.protocol_version,
"agent_version" => info.agent_version, "agent_version" => info.agent_version,
"listening_ addresses" => format!("{:?}", info.listen_addrs), "listening_ addresses" => ?info.listen_addrs,
"observed_address" => format!("{:?}", observed_addr), "observed_address" => ?observed_addr,
"protocols" => format!("{:?}", info.protocols) "protocols" => ?info.protocols
); );
} }
IdentifyEvent::Sent { .. } => {} IdentifyEvent::Sent { .. } => {}
@ -985,10 +985,10 @@ impl<TSpec: EthSpec> NetworkBehaviour for Behaviour<TSpec> {
if let Some(goodbye_reason) = goodbye_reason { if let Some(goodbye_reason) = goodbye_reason {
match goodbye_reason { match goodbye_reason {
GoodbyeReason::Banned => { GoodbyeReason::Banned => {
debug!(self.log, "Disconnecting newly connected peer"; "peer_id" => peer_id.to_string(), "reason" => goodbye_reason.to_string()) debug!(self.log, "Disconnecting newly connected peer"; "peer_id" => %peer_id, "reason" => %goodbye_reason)
} }
_ => { _ => {
trace!(self.log, "Disconnecting newly connected peer"; "peer_id" => peer_id.to_string(), "reason" => goodbye_reason.to_string()) trace!(self.log, "Disconnecting newly connected peer"; "peer_id" => %peer_id, "reason" => %goodbye_reason)
} }
} }
self.peers_to_dc self.peers_to_dc
@ -1005,13 +1005,13 @@ impl<TSpec: EthSpec> NetworkBehaviour for Behaviour<TSpec> {
self.peer_manager self.peer_manager
.connect_ingoing(&peer_id, send_back_addr.clone()); .connect_ingoing(&peer_id, send_back_addr.clone());
self.add_event(BehaviourEvent::PeerConnected(peer_id.clone())); self.add_event(BehaviourEvent::PeerConnected(peer_id.clone()));
debug!(self.log, "Connection established"; "peer_id" => peer_id.to_string(), "connection" => "Incoming"); debug!(self.log, "Connection established"; "peer_id" => %peer_id, "connection" => "Incoming");
} }
ConnectedPoint::Dialer { address } => { ConnectedPoint::Dialer { address } => {
self.peer_manager self.peer_manager
.connect_outgoing(&peer_id, address.clone()); .connect_outgoing(&peer_id, address.clone());
self.add_event(BehaviourEvent::PeerDialed(peer_id.clone())); self.add_event(BehaviourEvent::PeerDialed(peer_id.clone()));
debug!(self.log, "Connection established"; "peer_id" => peer_id.to_string(), "connection" => "Dialed"); debug!(self.log, "Connection established"; "peer_id" => %peer_id, "connection" => "Dialed");
} }
} }
// report the event to the behaviour // report the event to the behaviour
@ -1310,8 +1310,8 @@ pub fn save_metadata_to_disk<E: EthSpec>(dir: &PathBuf, metadata: MetaData<E>, l
warn!( warn!(
log, log,
"Could not write metadata to disk"; "Could not write metadata to disk";
"file" => format!("{:?}{:?}",dir, METADATA_FILENAME), "file" => format!("{:?}{:?}", dir, METADATA_FILENAME),
"error" => format!("{}", e) "error" => %e
); );
} }
} }

View File

@ -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 the same node id, then we may need to update our sequence number
if local_enr.node_id() == disk_enr.node_id() { if local_enr.node_id() == disk_enr.node_id() {
if compare_enr(&local_enr, &disk_enr) { 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 // the stored ENR has the same configuration, use it
*local_enr = disk_enr; *local_enr = disk_enr;
return Ok(()); return Ok(());
@ -87,7 +87,7 @@ pub fn use_or_load_enr(
} }
} }
Err(e) => { 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) => { Err(e) => {
warn!( warn!(
log, 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
); );
} }
} }

View File

@ -178,7 +178,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
let local_enr = network_globals.local_enr.read().clone(); 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); let listen_socket = SocketAddr::new(config.listen_address, config.discovery_port);
@ -193,11 +193,11 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
debug!( debug!(
log, log,
"Adding node to routing table"; "Adding node to routing table";
"node_id" => bootnode_enr.node_id().to_string(), "node_id" => %bootnode_enr.node_id(),
"peer_id" => bootnode_enr.peer_id().to_string(), "peer_id" => %bootnode_enr.peer_id(),
"ip" => format!("{:?}", bootnode_enr.ip()), "ip" => ?bootnode_enr.ip(),
"udp" => format!("{:?}", bootnode_enr.udp()), "udp" => ?bootnode_enr.udp(),
"tcp" => format!("{:?}", bootnode_enr.tcp()) "tcp" => ?bootnode_enr.tcp()
); );
let repr = bootnode_enr.to_string(); let repr = bootnode_enr.to_string();
let _ = discv5.add_enr(bootnode_enr).map_err(|e| { let _ = discv5.add_enr(bootnode_enr).map_err(|e| {
@ -247,11 +247,11 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
debug!( debug!(
log, log,
"Adding node to routing table"; "Adding node to routing table";
"node_id" => enr.node_id().to_string(), "node_id" => %enr.node_id(),
"peer_id" => enr.peer_id().to_string(), "peer_id" => %enr.peer_id(),
"ip" => format!("{:?}", enr.ip()), "ip" => ?enr.ip(),
"udp" => format!("{:?}", enr.udp()), "udp" => ?enr.udp(),
"tcp" => format!("{:?}", enr.tcp()) "tcp" => ?enr.tcp()
); );
let _ = discv5.add_enr(enr).map_err(|e| { let _ = discv5.add_enr(enr).map_err(|e| {
error!( error!(
@ -318,7 +318,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
debug!( debug!(
self.log, self.log,
"Making discovery query for subnets"; "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 { for subnet in subnets_to_discover {
self.add_subnet_query(subnet.subnet_id, subnet.min_ttl, 0); self.add_subnet_query(subnet.subnet_id, subnet.min_ttl, 0);
@ -334,7 +334,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
debug!( debug!(
self.log, self.log,
"Could not add peer to the local routing table"; "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"; info!(self.log, "Updating the ENR fork version";
"fork_digest" => format!("{:?}", enr_fork_id.fork_digest), "fork_digest" => ?enr_fork_id.fork_digest,
"next_fork_version" => format!("{:?}", enr_fork_id.next_fork_version), "next_fork_version" => ?enr_fork_id.next_fork_version,
"next_fork_epoch" => next_fork_epoch_log, "next_fork_epoch" => next_fork_epoch_log,
); );
@ -473,7 +473,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
warn!( warn!(
self.log, self.log,
"Could not update eth2 ENR field"; "Could not update eth2 ENR field";
"error" => format!("{:?}", e) "error" => ?e
) )
}); });
@ -607,7 +607,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
debug!( debug!(
self.log, self.log,
"Starting grouped subnet query"; "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); self.start_subnet_query(grouped_queries);
processed = true; processed = true;
@ -659,7 +659,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
"target_subnet_peers" => TARGET_SUBNET_PEERS, "target_subnet_peers" => TARGET_SUBNET_PEERS,
"peers_to_find" => target_peers, "peers_to_find" => target_peers,
"attempt" => subnet_query.retries, "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); filtered_subnet_ids.push(subnet_query.subnet_id);
@ -757,7 +757,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
return Some(results); return Some(results);
} }
Err(e) => { 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(); queries.iter().map(|query| query.subnet_id).collect();
match query_result.1 { match query_result.1 {
Ok(r) if r.is_empty() => { 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) => { 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(); let mut mapped_results = HashMap::new();
@ -836,7 +836,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
} }
} }
Err(e) => { 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); self.event_stream = EventStream::Present(stream);
} }
Err(e) => { 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; self.event_stream = EventStream::InActive;
} }
} }
@ -907,7 +907,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
*/ */
} }
Discv5Event::SocketUpdated(socket) => { 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); metrics::inc_counter(&metrics::ADDRESS_UPDATE_COUNT);
// Discv5 will have updated our local ENR. We save the updated version // Discv5 will have updated our local ENR. We save the updated version
// to disk. // to disk.

View File

@ -34,15 +34,15 @@ where
trace!( trace!(
log_clone, log_clone,
"Peer found but not on any of the desired subnets"; "Peer found but not on any of the desired subnets";
"peer_id" => format!("{}", enr.peer_id()) "peer_id" => %enr.peer_id()
); );
return false; return false;
} else { } else {
trace!( trace!(
log_clone, log_clone,
"Peer found on desired subnet(s)"; "Peer found on desired subnet(s)";
"peer_id" => format!("{}", enr.peer_id()), "peer_id" => %enr.peer_id(),
"subnets" => format!("{:?}", matches.as_slice()) "subnets" => ?matches.as_slice()
); );
return true; return true;
} }

View File

@ -193,7 +193,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
&self.log, &self.log,
); );
if previous_state == info.score_state() { if previous_state == info.score_state() {
debug!(self.log, "Peer score adjusted"; "peer_id" => peer_id.to_string(), "score" => info.score().to_string()); debug!(self.log, "Peer score adjusted"; "peer_id" => %peer_id, "score" => %info.score());
} }
} }
} // end write lock } // end write lock
@ -241,7 +241,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
trace!( trace!(
self.log, self.log,
"Discovery query ignored"; "Discovery query ignored";
"subnet_id" => format!("{:?}",s.subnet_id), "subnet_id" => ?s.subnet_id,
"reason" => "Already connected to desired peers", "reason" => "Already connected to desired peers",
"connected_peers_on_subnet" => peers_on_subnet, "connected_peers_on_subnet" => peers_on_subnet,
"target_subnet_peers" => TARGET_SUBNET_PEERS, "target_subnet_peers" => TARGET_SUBNET_PEERS,
@ -441,7 +441,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
if let Some(peer_info) = self.network_globals.peers.read().peer_info(peer_id) { if let Some(peer_info) = self.network_globals.peers.read().peer_info(peer_id) {
// received a ping // received a ping
// reset the to-ping timer for this peer // reset the to-ping timer for this peer
debug!(self.log, "Received a ping request"; "peer_id" => peer_id.to_string(), "seq_no" => seq); debug!(self.log, "Received a ping request"; "peer_id" => %peer_id, "seq_no" => seq);
match peer_info.connection_direction { match peer_info.connection_direction {
Some(ConnectionDirection::Incoming) => { Some(ConnectionDirection::Incoming) => {
self.inbound_ping_peers.insert(peer_id.clone()); self.inbound_ping_peers.insert(peer_id.clone());
@ -458,20 +458,20 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
if let Some(meta_data) = &peer_info.meta_data { if let Some(meta_data) = &peer_info.meta_data {
if meta_data.seq_number < seq { if meta_data.seq_number < seq {
debug!(self.log, "Requesting new metadata from peer"; debug!(self.log, "Requesting new metadata from peer";
"peer_id" => peer_id.to_string(), "known_seq_no" => meta_data.seq_number, "ping_seq_no" => seq); "peer_id" => %peer_id, "known_seq_no" => meta_data.seq_number, "ping_seq_no" => seq);
self.events self.events
.push(PeerManagerEvent::MetaData(peer_id.clone())); .push(PeerManagerEvent::MetaData(peer_id.clone()));
} }
} else { } else {
// if we don't know the meta-data, request it // if we don't know the meta-data, request it
debug!(self.log, "Requesting first metadata from peer"; debug!(self.log, "Requesting first metadata from peer";
"peer_id" => peer_id.to_string()); "peer_id" => %peer_id);
self.events self.events
.push(PeerManagerEvent::MetaData(peer_id.clone())); .push(PeerManagerEvent::MetaData(peer_id.clone()));
} }
} else { } else {
crit!(self.log, "Received a PING from an unknown peer"; crit!(self.log, "Received a PING from an unknown peer";
"peer_id" => peer_id.to_string()); "peer_id" => %peer_id);
} }
} }
@ -484,19 +484,19 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
if let Some(meta_data) = &peer_info.meta_data { if let Some(meta_data) = &peer_info.meta_data {
if meta_data.seq_number < seq { if meta_data.seq_number < seq {
debug!(self.log, "Requesting new metadata from peer"; debug!(self.log, "Requesting new metadata from peer";
"peer_id" => peer_id.to_string(), "known_seq_no" => meta_data.seq_number, "pong_seq_no" => seq); "peer_id" => %peer_id, "known_seq_no" => meta_data.seq_number, "pong_seq_no" => seq);
self.events self.events
.push(PeerManagerEvent::MetaData(peer_id.clone())); .push(PeerManagerEvent::MetaData(peer_id.clone()));
} }
} else { } else {
// if we don't know the meta-data, request it // if we don't know the meta-data, request it
debug!(self.log, "Requesting first metadata from peer"; debug!(self.log, "Requesting first metadata from peer";
"peer_id" => peer_id.to_string()); "peer_id" => %peer_id);
self.events self.events
.push(PeerManagerEvent::MetaData(peer_id.clone())); .push(PeerManagerEvent::MetaData(peer_id.clone()));
} }
} else { } else {
crit!(self.log, "Received a PONG from an unknown peer"; "peer_id" => peer_id.to_string()); crit!(self.log, "Received a PONG from an unknown peer"; "peer_id" => %peer_id);
} }
} }
@ -506,21 +506,21 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
if let Some(known_meta_data) = &peer_info.meta_data { if let Some(known_meta_data) = &peer_info.meta_data {
if known_meta_data.seq_number < meta_data.seq_number { if known_meta_data.seq_number < meta_data.seq_number {
debug!(self.log, "Updating peer's metadata"; debug!(self.log, "Updating peer's metadata";
"peer_id" => peer_id.to_string(), "known_seq_no" => known_meta_data.seq_number, "new_seq_no" => meta_data.seq_number); "peer_id" => %peer_id, "known_seq_no" => known_meta_data.seq_number, "new_seq_no" => meta_data.seq_number);
peer_info.meta_data = Some(meta_data); peer_info.meta_data = Some(meta_data);
} else { } else {
debug!(self.log, "Received old metadata"; debug!(self.log, "Received old metadata";
"peer_id" => peer_id.to_string(), "known_seq_no" => known_meta_data.seq_number, "new_seq_no" => meta_data.seq_number); "peer_id" => %peer_id, "known_seq_no" => known_meta_data.seq_number, "new_seq_no" => meta_data.seq_number);
} }
} else { } else {
// we have no meta-data for this peer, update // we have no meta-data for this peer, update
debug!(self.log, "Obtained peer's metadata"; debug!(self.log, "Obtained peer's metadata";
"peer_id" => peer_id.to_string(), "new_seq_no" => meta_data.seq_number); "peer_id" => %peer_id, "new_seq_no" => meta_data.seq_number);
peer_info.meta_data = Some(meta_data); peer_info.meta_data = Some(meta_data);
} }
} else { } else {
crit!(self.log, "Received METADATA from an unknown peer"; crit!(self.log, "Received METADATA from an unknown peer";
"peer_id" => peer_id.to_string()); "peer_id" => %peer_id);
} }
} }
@ -672,7 +672,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
} }
} }
for peer_id in to_dial_peers { for peer_id in to_dial_peers {
debug!(self.log, "Dialing discovered peer"; "peer_id"=> peer_id.to_string()); debug!(self.log, "Dialing discovered peer"; "peer_id" => %peer_id);
self.dial_peer(&peer_id); self.dial_peer(&peer_id);
} }
} }
@ -688,7 +688,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
let mut peerdb = self.network_globals.peers.write(); let mut peerdb = self.network_globals.peers.write();
if peerdb.is_banned(&peer_id) { if peerdb.is_banned(&peer_id) {
// don't connect if the peer is banned // don't connect if the peer is banned
slog::crit!(self.log, "Connection has been allowed to a banned peer"; "peer_id" => peer_id.to_string()); slog::crit!(self.log, "Connection has been allowed to a banned peer"; "peer_id" => %peer_id);
} }
let enr = self.discovery.enr_of_peer(peer_id); let enr = self.discovery.enr_of_peer(peer_id);
@ -751,11 +751,11 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
if previous_state != info.score_state() { if previous_state != info.score_state() {
match info.score_state() { match info.score_state() {
ScoreState::Banned => { ScoreState::Banned => {
debug!(log, "Peer has been banned"; "peer_id" => peer_id.to_string(), "score" => info.score().to_string()); debug!(log, "Peer has been banned"; "peer_id" => %peer_id, "score" => %info.score());
to_ban_peers.push(peer_id.clone()); to_ban_peers.push(peer_id.clone());
} }
ScoreState::Disconnected => { ScoreState::Disconnected => {
debug!(log, "Peer transitioned to disconnect state"; "peer_id" => peer_id.to_string(), "score" => info.score().to_string(), "past_state" => previous_state.to_string()); debug!(log, "Peer transitioned to disconnect state"; "peer_id" => %peer_id, "score" => %info.score(), "past_state" => %previous_state);
// disconnect the peer if it's currently connected or dialing // disconnect the peer if it's currently connected or dialing
if info.is_connected_or_dialing() { if info.is_connected_or_dialing() {
// Change the state to inform that we are disconnecting the peer. // Change the state to inform that we are disconnecting the peer.
@ -769,7 +769,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
} }
} }
ScoreState::Healthy => { ScoreState::Healthy => {
debug!(log, "Peer transitioned to healthy state"; "peer_id" => peer_id.to_string(), "score" => info.score().to_string(), "past_state" => previous_state.to_string()); debug!(log, "Peer transitioned to healthy state"; "peer_id" => %peer_id, "score" => %info.score(), "past_state" => %previous_state);
// unban the peer if it was previously banned. // unban the peer if it was previously banned.
if info.is_banned() { if info.is_banned() {
to_unban_peers.push(peer_id.clone()); to_unban_peers.push(peer_id.clone());

View File

@ -347,7 +347,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
.checked_duration_since(Instant::now()) .checked_duration_since(Instant::now())
.map(|duration| duration.as_secs()) .map(|duration| duration.as_secs())
.unwrap_or_else(|| 0); .unwrap_or_else(|| 0);
debug!(self.log, "Updating the time a peer is required for"; "peer_id" => peer_id.to_string(), "future_min_ttl_secs" => min_ttl_secs); debug!(self.log, "Updating the time a peer is required for"; "peer_id" => %peer_id, "future_min_ttl_secs" => min_ttl_secs);
} }
} }
@ -457,7 +457,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
let log_ref = &self.log; let log_ref = &self.log;
let info = self.peers.entry(peer_id.clone()).or_insert_with(|| { let info = self.peers.entry(peer_id.clone()).or_insert_with(|| {
warn!(log_ref, "Banning unknown peer"; warn!(log_ref, "Banning unknown peer";
"peer_id" => peer_id.to_string()); "peer_id" => %peer_id);
PeerInfo::default() PeerInfo::default()
}); });
@ -514,7 +514,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
let log_ref = &self.log; let log_ref = &self.log;
let info = self.peers.entry(peer_id.clone()).or_insert_with(|| { let info = self.peers.entry(peer_id.clone()).or_insert_with(|| {
warn!(log_ref, "UnBanning unknown peer"; warn!(log_ref, "UnBanning unknown peer";
"peer_id" => peer_id.to_string()); "peer_id" => %peer_id);
PeerInfo::default() PeerInfo::default()
}); });
@ -563,7 +563,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
self.banned_peers_count = BannedPeersCount::new(); self.banned_peers_count = BannedPeersCount::new();
None None
} { } {
debug!(self.log, "Removing old banned peer"; "peer_id" => to_drop.to_string()); debug!(self.log, "Removing old banned peer"; "peer_id" => %to_drop);
self.peers.remove(&to_drop); self.peers.remove(&to_drop);
} }
} }
@ -581,7 +581,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
.min_by_key(|(_, since)| *since) .min_by_key(|(_, since)| *since)
.map(|(id, _)| id.clone()) .map(|(id, _)| id.clone())
{ {
debug!(self.log, "Removing old disconnected peer"; "peer_id" => to_drop.to_string()); debug!(self.log, "Removing old disconnected peer"; "peer_id" => %to_drop);
self.peers.remove(&to_drop); self.peers.remove(&to_drop);
} }
// If there is no minimum, this is a coding error. For safety we decrease // If there is no minimum, this is a coding error. For safety we decrease
@ -595,7 +595,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
if let Some(peer_info) = self.peers.get_mut(peer_id) { if let Some(peer_info) = self.peers.get_mut(peer_id) {
peer_info.meta_data = Some(meta_data); peer_info.meta_data = Some(meta_data);
} else { } else {
warn!(self.log, "Tried to add meta data for a non-existant peer"; "peer_id" => peer_id.to_string()); warn!(self.log, "Tried to add meta data for a non-existent peer"; "peer_id" => %peer_id);
} }
} }
} }

View File

@ -307,7 +307,7 @@ where
if matches!(self.state, HandlerState::Deactivated) { if matches!(self.state, HandlerState::Deactivated) {
// we no longer send responses after the handler is deactivated // we no longer send responses after the handler is deactivated
debug!(self.log, "Response not sent. Deactivated handler"; debug!(self.log, "Response not sent. Deactivated handler";
"response" => response.to_string(), "id" => inbound_id); "response" => %response, "id" => inbound_id);
return; return;
} }
inbound_info.pending_items.push(response); inbound_info.pending_items.push(response);
@ -419,7 +419,7 @@ where
) )
.is_some() .is_some()
{ {
crit!(self.log, "Duplicate outbound substream id"; "id" => format!("{:?}", self.current_outbound_substream_id)); crit!(self.log, "Duplicate outbound substream id"; "id" => self.current_outbound_substream_id);
} }
self.current_outbound_substream_id.0 += 1; self.current_outbound_substream_id.0 += 1;
} }
@ -563,7 +563,7 @@ where
} }
} }
Poll::Ready(Some(Err(e))) => { Poll::Ready(Some(Err(e))) => {
warn!(self.log, "Inbound substream poll failed"; "error" => format!("{:?}", e)); warn!(self.log, "Inbound substream poll failed"; "error" => ?e);
// drops the peer if we cannot read the delay queue // drops the peer if we cannot read the delay queue
return Poll::Ready(ProtocolsHandlerEvent::Close(RPCError::InternalError( return Poll::Ready(ProtocolsHandlerEvent::Close(RPCError::InternalError(
"Could not poll inbound stream timer", "Could not poll inbound stream timer",
@ -592,7 +592,7 @@ where
} }
} }
Poll::Ready(Some(Err(e))) => { Poll::Ready(Some(Err(e))) => {
warn!(self.log, "Outbound substream poll failed"; "error" => format!("{:?}", e)); warn!(self.log, "Outbound substream poll failed"; "error" => ?e);
return Poll::Ready(ProtocolsHandlerEvent::Close(RPCError::InternalError( return Poll::Ready(ProtocolsHandlerEvent::Close(RPCError::InternalError(
"Could not poll outbound stream timer", "Could not poll outbound stream timer",
))); )));

View File

@ -399,11 +399,11 @@ impl slog::KV for StatusMessage {
serializer: &mut dyn slog::Serializer, serializer: &mut dyn slog::Serializer,
) -> slog::Result { ) -> slog::Result {
use slog::Value; use slog::Value;
serializer.emit_str("fork_digest", &format!("{:?}", self.fork_digest))?; serializer.emit_arguments("fork_digest", &format_args!("{:?}", self.fork_digest))?;
Value::serialize(&self.finalized_epoch, record, "finalized_epoch", serializer)?; Value::serialize(&self.finalized_epoch, record, "finalized_epoch", serializer)?;
serializer.emit_str("finalized_root", &self.finalized_root.to_string())?; serializer.emit_arguments("finalized_root", &format_args!("{}", self.finalized_root))?;
Value::serialize(&self.head_slot, record, "head_slot", serializer)?; Value::serialize(&self.head_slot, record, "head_slot", serializer)?;
serializer.emit_str("head_root", &self.head_root.to_string())?; serializer.emit_arguments("head_root", &format_args!("{}", self.head_root))?;
slog::Result::Ok(()) slog::Result::Ok(())
} }
} }

View File

@ -187,7 +187,7 @@ where
// Use connection established/closed instead of these currently // Use connection established/closed instead of these currently
fn inject_connected(&mut self, peer_id: &PeerId) { fn inject_connected(&mut self, peer_id: &PeerId) {
// find the peer's meta-data // find the peer's meta-data
debug!(self.log, "Requesting new peer's metadata"; "peer_id" => format!("{}",peer_id)); debug!(self.log, "Requesting new peer's metadata"; "peer_id" => %peer_id);
let rpc_event = RPCSend::Request(RequestId::Behaviour, RPCRequest::MetaData(PhantomData)); let rpc_event = RPCSend::Request(RequestId::Behaviour, RPCRequest::MetaData(PhantomData));
self.events.push(NetworkBehaviourAction::NotifyHandler { self.events.push(NetworkBehaviourAction::NotifyHandler {
peer_id: peer_id.clone(), peer_id: peer_id.clone(),
@ -253,7 +253,7 @@ where
} }
Err(RateLimitedErr::TooSoon(wait_time)) => { Err(RateLimitedErr::TooSoon(wait_time)) => {
debug!(self.log, "Request exceeds the rate limit"; debug!(self.log, "Request exceeds the rate limit";
"request" => req.to_string(), "peer_id" => peer_id.to_string(), "wait_time_ms" => wait_time.as_millis()); "request" => %req, "peer_id" => %peer_id, "wait_time_ms" => wait_time.as_millis());
// send an error code to the peer. // send an error code to the peer.
// the handler upon receiving the error code will send it back to the behaviour // the handler upon receiving the error code will send it back to the behaviour
self.send_response( self.send_response(

View File

@ -93,13 +93,13 @@ impl<TSpec: EthSpec> Service<TSpec> {
&log, &log,
)); ));
info!(log, "Libp2p Service"; "peer_id" => enr.peer_id().to_string()); info!(log, "Libp2p Service"; "peer_id" => %enr.peer_id());
let discovery_string = if config.disable_discovery { let discovery_string = if config.disable_discovery {
"None".into() "None".into()
} else { } else {
config.discovery_port.to_string() config.discovery_port.to_string()
}; };
debug!(log, "Attempting to open listening ports"; "address" => format!("{}", config.listen_address), "tcp_port" => config.libp2p_port, "udp_port" => discovery_string); debug!(log, "Attempting to open listening ports"; "address" => ?config.listen_address, "tcp_port" => config.libp2p_port, "udp_port" => discovery_string);
let (mut swarm, bandwidth) = { let (mut swarm, bandwidth) = {
// Set up the transport - tcp/ws with noise and mplex // Set up the transport - tcp/ws with noise and mplex
@ -147,14 +147,14 @@ impl<TSpec: EthSpec> Service<TSpec> {
Ok(_) => { Ok(_) => {
let mut log_address = listen_multiaddr; let mut log_address = listen_multiaddr;
log_address.push(Protocol::P2p(local_peer_id.clone().into())); log_address.push(Protocol::P2p(local_peer_id.clone().into()));
info!(log, "Listening established"; "address" => format!("{}", log_address)); info!(log, "Listening established"; "address" => %log_address);
} }
Err(err) => { Err(err) => {
crit!( crit!(
log, log,
"Unable to listen on libp2p address"; "Unable to listen on libp2p address";
"error" => format!("{:?}", err), "error" => ?err,
"listen_multiaddr" => format!("{}", listen_multiaddr), "listen_multiaddr" => %listen_multiaddr,
); );
return Err("Libp2p was unable to listen on the given listen address.".into()); return Err("Libp2p was unable to listen on the given listen address.".into());
} }
@ -165,10 +165,10 @@ impl<TSpec: EthSpec> Service<TSpec> {
// strip the p2p protocol if it exists // strip the p2p protocol if it exists
strip_peer_id(&mut multiaddr); strip_peer_id(&mut multiaddr);
match Swarm::dial_addr(&mut swarm, multiaddr.clone()) { match Swarm::dial_addr(&mut swarm, multiaddr.clone()) {
Ok(()) => debug!(log, "Dialing libp2p peer"; "address" => format!("{}", multiaddr)), Ok(()) => debug!(log, "Dialing libp2p peer"; "address" => %multiaddr),
Err(err) => debug!( Err(err) => debug!(
log, log,
"Could not connect to peer"; "address" => format!("{}", multiaddr), "error" => format!("{:?}", err) "Could not connect to peer"; "address" => %multiaddr, "error" => ?err
), ),
}; };
}; };
@ -216,12 +216,12 @@ impl<TSpec: EthSpec> Service<TSpec> {
if swarm.subscribe_kind(topic_kind.clone()) { if swarm.subscribe_kind(topic_kind.clone()) {
subscribed_topics.push(topic_kind.clone()); subscribed_topics.push(topic_kind.clone());
} else { } else {
warn!(log, "Could not subscribe to topic"; "topic" => format!("{}",topic_kind)); warn!(log, "Could not subscribe to topic"; "topic" => %topic_kind);
} }
} }
if !subscribed_topics.is_empty() { if !subscribed_topics.is_empty() {
info!(log, "Subscribed to topics"; "topics" => format!("{:?}", subscribed_topics)); info!(log, "Subscribed to topics"; "topics" => ?subscribed_topics);
} }
let service = Service { let service = Service {
@ -279,7 +279,7 @@ impl<TSpec: EthSpec> Service<TSpec> {
endpoint: _, endpoint: _,
num_established, num_established,
} => { } => {
trace!(self.log, "Connection closed"; "peer_id"=> peer_id.to_string(), "cause" => format!("{:?}", cause), "connections" => num_established); trace!(self.log, "Connection closed"; "peer_id" => %peer_id, "cause" => ?cause, "connections" => num_established);
} }
SwarmEvent::NewListenAddr(multiaddr) => { SwarmEvent::NewListenAddr(multiaddr) => {
return Libp2pEvent::NewListenAddr(multiaddr) return Libp2pEvent::NewListenAddr(multiaddr)
@ -288,14 +288,14 @@ impl<TSpec: EthSpec> Service<TSpec> {
local_addr, local_addr,
send_back_addr, send_back_addr,
} => { } => {
trace!(self.log, "Incoming connection"; "our_addr" => local_addr.to_string(), "from" => send_back_addr.to_string()) trace!(self.log, "Incoming connection"; "our_addr" => %local_addr, "from" => %send_back_addr)
} }
SwarmEvent::IncomingConnectionError { SwarmEvent::IncomingConnectionError {
local_addr, local_addr,
send_back_addr, send_back_addr,
error, error,
} => { } => {
debug!(self.log, "Failed incoming connection"; "our_addr" => local_addr.to_string(), "from" => send_back_addr.to_string(), "error" => error.to_string()) debug!(self.log, "Failed incoming connection"; "our_addr" => %local_addr, "from" => %send_back_addr, "error" => %error)
} }
SwarmEvent::BannedPeer { .. } => { SwarmEvent::BannedPeer { .. } => {
// We do not ban peers at the swarm layer, so this should never occur. // We do not ban peers at the swarm layer, so this should never occur.
@ -306,29 +306,29 @@ impl<TSpec: EthSpec> Service<TSpec> {
error, error,
attempts_remaining, attempts_remaining,
} => { } => {
debug!(self.log, "Failed to dial address"; "peer_id" => peer_id.to_string(), "address" => address.to_string(), "error" => error.to_string(), "attempts_remaining" => attempts_remaining); debug!(self.log, "Failed to dial address"; "peer_id" => %peer_id, "address" => %address, "error" => %error, "attempts_remaining" => attempts_remaining);
} }
SwarmEvent::UnknownPeerUnreachableAddr { address, error } => { SwarmEvent::UnknownPeerUnreachableAddr { address, error } => {
debug!(self.log, "Peer not known at dialed address"; "address" => address.to_string(), "error" => error.to_string()); debug!(self.log, "Peer not known at dialed address"; "address" => %address, "error" => %error);
} }
SwarmEvent::ExpiredListenAddr(multiaddr) => { SwarmEvent::ExpiredListenAddr(multiaddr) => {
debug!(self.log, "Listen address expired"; "multiaddr" => multiaddr.to_string()) debug!(self.log, "Listen address expired"; "multiaddr" => %multiaddr)
} }
SwarmEvent::ListenerClosed { addresses, reason } => { SwarmEvent::ListenerClosed { addresses, reason } => {
crit!(self.log, "Listener closed"; "addresses" => format!("{:?}", addresses), "reason" => format!("{:?}", reason)); crit!(self.log, "Listener closed"; "addresses" => ?addresses, "reason" => ?reason);
if Swarm::listeners(&self.swarm).count() == 0 { if Swarm::listeners(&self.swarm).count() == 0 {
return Libp2pEvent::ZeroListeners; return Libp2pEvent::ZeroListeners;
} }
} }
SwarmEvent::ListenerError { error } => { SwarmEvent::ListenerError { error } => {
// this is non fatal, but we still check // this is non fatal, but we still check
warn!(self.log, "Listener error"; "error" => format!("{:?}", error.to_string())); warn!(self.log, "Listener error"; "error" => ?error);
if Swarm::listeners(&self.swarm).count() == 0 { if Swarm::listeners(&self.swarm).count() == 0 {
return Libp2pEvent::ZeroListeners; return Libp2pEvent::ZeroListeners;
} }
} }
SwarmEvent::Dialing(peer_id) => { SwarmEvent::Dialing(peer_id) => {
debug!(self.log, "Dialing peer"; "peer_id" => peer_id.to_string()); debug!(self.log, "Dialing peer"; "peer_id" => %peer_id);
} }
} }
} }
@ -492,7 +492,7 @@ fn load_or_build_metadata<E: EthSpec>(
debug!( debug!(
log, log,
"Metadata from file could not be decoded"; "Metadata from file could not be decoded";
"error" => format!("{:?}", e), "error" => ?e,
); );
} }
} }

View File

@ -206,7 +206,7 @@ impl<T: BeaconChainTypes> AttestationService<T> {
// This will subscribe to long-lived random subnets if required. // This will subscribe to long-lived random subnets if required.
trace!(self.log, trace!(self.log,
"Validator subscription"; "Validator subscription";
"subscription" => format!("{:?}", subscription), "subscription" => ?subscription,
); );
self.add_known_validator(subscription.validator_index); self.add_known_validator(subscription.validator_index);
@ -220,7 +220,7 @@ impl<T: BeaconChainTypes> AttestationService<T> {
Err(e) => { Err(e) => {
warn!(self.log, warn!(self.log,
"Failed to compute subnet id for validator subscription"; "Failed to compute subnet id for validator subscription";
"error" => format!("{:?}", e), "error" => ?e,
"validator_index" => subscription.validator_index "validator_index" => subscription.validator_index
); );
continue; continue;
@ -257,7 +257,7 @@ impl<T: BeaconChainTypes> AttestationService<T> {
} else { } else {
trace!(self.log, trace!(self.log,
"Subscribed to subnet for aggregator duties"; "Subscribed to subnet for aggregator duties";
"exact_subnet" => format!("{:?}", exact_subnet), "exact_subnet" => ?exact_subnet,
"validator_index" => subscription.validator_index "validator_index" => subscription.validator_index
); );
} }
@ -339,7 +339,7 @@ impl<T: BeaconChainTypes> AttestationService<T> {
// peer before they can be removed. // peer before they can be removed.
warn!(self.log, warn!(self.log,
"Not enough time for a discovery search"; "Not enough time for a discovery search";
"subnet_id" => format!("{:?}", exact_subnet) "subnet_id" => ?exact_subnet
); );
None None
} }

View File

@ -961,7 +961,7 @@ impl Drop for SendOnDrop {
self.log, self.log,
"Unable to free worker"; "Unable to free worker";
"msg" => "did not free worker, shutdown may be underway", "msg" => "did not free worker, shutdown may be underway",
"error" => e.to_string() "error" => %e
) )
} }
} }

View File

@ -212,7 +212,7 @@ impl<T: BeaconChainTypes> Worker<T> {
self.log, self.log,
"New block received"; "New block received";
"slot" => verified_block.block.slot(), "slot" => verified_block.block.slot(),
"hash" => verified_block.block_root.to_string() "hash" => %verified_block.block_root
); );
self.propagate_validation_result( self.propagate_validation_result(
message_id, message_id,
@ -232,7 +232,7 @@ impl<T: BeaconChainTypes> Worker<T> {
| Err(e @ BlockError::NotFinalizedDescendant { .. }) | Err(e @ BlockError::NotFinalizedDescendant { .. })
| Err(e @ BlockError::BeaconChainError(_)) => { | Err(e @ BlockError::BeaconChainError(_)) => {
debug!(self.log, "Could not verify block for gossip, ignoring the block"; debug!(self.log, "Could not verify block for gossip, ignoring the block";
"error" => e.to_string()); "error" => %e);
// Prevent recurring behaviour by penalizing the peer slightly. // Prevent recurring behaviour by penalizing the peer slightly.
self.penalize_peer(peer_id.clone(), PeerAction::HighToleranceError); self.penalize_peer(peer_id.clone(), PeerAction::HighToleranceError);
self.propagate_validation_result(message_id, peer_id, MessageAcceptance::Ignore); self.propagate_validation_result(message_id, peer_id, MessageAcceptance::Ignore);
@ -252,7 +252,7 @@ impl<T: BeaconChainTypes> Worker<T> {
| Err(e @ BlockError::WeakSubjectivityConflict) | Err(e @ BlockError::WeakSubjectivityConflict)
| Err(e @ BlockError::GenesisBlock) => { | Err(e @ BlockError::GenesisBlock) => {
warn!(self.log, "Could not verify block for gossip, rejecting the block"; warn!(self.log, "Could not verify block for gossip, rejecting the block";
"error" => e.to_string()); "error" => %e);
self.propagate_validation_result( self.propagate_validation_result(
message_id, message_id,
peer_id.clone(), peer_id.clone(),
@ -307,15 +307,15 @@ impl<T: BeaconChainTypes> Worker<T> {
debug!( debug!(
self.log, self.log,
"Invalid gossip beacon block"; "Invalid gossip beacon block";
"outcome" => format!("{:?}", other), "outcome" => ?other,
"block root" => format!("{}", block.canonical_root()), "block root" => %block.canonical_root(),
"block slot" => block.slot() "block slot" => block.slot()
); );
self.penalize_peer(peer_id, PeerAction::MidToleranceError); self.penalize_peer(peer_id, PeerAction::MidToleranceError);
trace!( trace!(
self.log, self.log,
"Invalid gossip beacon block ssz"; "Invalid gossip beacon block ssz";
"ssz" => format!("0x{}", hex::encode(block.as_ssz_bytes())), "ssz" => format_args!("0x{}", hex::encode(block.as_ssz_bytes())),
); );
} }
}; };
@ -787,8 +787,8 @@ impl<T: BeaconChainTypes> Worker<T> {
debug!( debug!(
self.log, self.log,
"Received attestation on incorrect subnet"; "Received attestation on incorrect subnet";
"expected" => format!("{:?}", expected), "expected" => ?expected,
"received" => format!("{:?}", received), "received" => ?received,
); );
self.propagate_validation_result( self.propagate_validation_result(
message_id, message_id,

View File

@ -225,14 +225,14 @@ impl<T: BeaconChainTypes> Router<T> {
self.processor.on_block_gossip(id, peer_id, block); self.processor.on_block_gossip(id, peer_id, block);
} }
PubsubMessage::VoluntaryExit(exit) => { PubsubMessage::VoluntaryExit(exit) => {
debug!(self.log, "Received a voluntary exit"; "peer_id" => format!("{}", peer_id)); debug!(self.log, "Received a voluntary exit"; "peer_id" => %peer_id);
self.processor.on_voluntary_exit_gossip(id, peer_id, exit); self.processor.on_voluntary_exit_gossip(id, peer_id, exit);
} }
PubsubMessage::ProposerSlashing(proposer_slashing) => { PubsubMessage::ProposerSlashing(proposer_slashing) => {
debug!( debug!(
self.log, self.log,
"Received a proposer slashing"; "Received a proposer slashing";
"peer_id" => format!("{}", peer_id) "peer_id" => %peer_id
); );
self.processor self.processor
.on_proposer_slashing_gossip(id, peer_id, proposer_slashing); .on_proposer_slashing_gossip(id, peer_id, proposer_slashing);
@ -241,7 +241,7 @@ impl<T: BeaconChainTypes> Router<T> {
debug!( debug!(
self.log, self.log,
"Received a attester slashing"; "Received a attester slashing";
"peer_id" => format!("{}", peer_id) "peer_id" => %peer_id
); );
self.processor self.processor
.on_attester_slashing_gossip(id, peer_id, attester_slashing); .on_attester_slashing_gossip(id, peer_id, attester_slashing);

View File

@ -179,7 +179,7 @@ impl<T: BeaconChainTypes> Processor<T> {
trace!( trace!(
self.log, self.log,
"Received BlocksByRange Response"; "Received BlocksByRange Response";
"peer" => peer_id.to_string(), "peer" => %peer_id,
); );
if let RequestId::Sync(id) = request_id { if let RequestId::Sync(id) = request_id {
@ -206,7 +206,7 @@ impl<T: BeaconChainTypes> Processor<T> {
trace!( trace!(
self.log, self.log,
"Received BlocksByRoot Response"; "Received BlocksByRoot Response";
"peer" => peer_id.to_string(), "peer" => %peer_id,
); );
if let RequestId::Sync(id) = request_id { if let RequestId::Sync(id) = request_id {
@ -356,10 +356,9 @@ impl<T: EthSpec> HandlerNetworkContext<T> {
/// Sends a message to the network task. /// Sends a message to the network task.
fn inform_network(&mut self, msg: NetworkMessage<T>) { fn inform_network(&mut self, msg: NetworkMessage<T>) {
let msg_r = &format!("{:?}", msg); self.network_send.send(msg).unwrap_or_else(
self.network_send |e| warn!(self.log, "Could not send message to the network service"; "error" => %e),
.send(msg) )
.unwrap_or_else(|e| warn!(self.log, "Could not send message to the network service"; "error" => %e, "message" => msg_r))
} }
/// Disconnects and ban's a peer, sending a Goodbye request with the associated reason. /// Disconnects and ban's a peer, sending a Goodbye request with the associated reason.

View File

@ -241,13 +241,13 @@ fn spawn_service<T: BeaconChainTypes>(
debug!( debug!(
service.log, service.log,
"Persisting DHT to store"; "Persisting DHT to store";
"Number of peers" => format!("{}", enrs.len()), "Number of peers" => enrs.len(),
); );
match persist_dht::<T::EthSpec, T::HotStore, T::ColdStore>(service.store.clone(), enrs) { match persist_dht::<T::EthSpec, T::HotStore, T::ColdStore>(service.store.clone(), enrs) {
Err(e) => error!( Err(e) => error!(
service.log, service.log,
"Failed to persist DHT on drop"; "Failed to persist DHT on drop";
"error" => format!("{:?}", e) "error" => ?e
), ),
Ok(_) => info!( Ok(_) => info!(
service.log, service.log,
@ -354,9 +354,9 @@ fn spawn_service<T: BeaconChainTypes>(
validation_result, validation_result,
} => { } => {
trace!(service.log, "Propagating gossipsub message"; trace!(service.log, "Propagating gossipsub message";
"propagation_peer" => format!("{:?}", propagation_source), "propagation_peer" => ?propagation_source,
"message_id" => message_id.to_string(), "message_id" => %message_id,
"validation_result" => format!("{:?}", validation_result) "validation_result" => ?validation_result
); );
service service
.libp2p .libp2p
@ -376,7 +376,7 @@ fn spawn_service<T: BeaconChainTypes>(
service.log, service.log,
"Sending pubsub messages"; "Sending pubsub messages";
"count" => messages.len(), "count" => messages.len(),
"topics" => format!("{:?}", topic_kinds) "topics" => ?topic_kinds
); );
metrics::expose_publish_metrics(&messages); metrics::expose_publish_metrics(&messages);
service.libp2p.swarm.publish(messages); service.libp2p.swarm.publish(messages);
@ -398,7 +398,7 @@ fn spawn_service<T: BeaconChainTypes>(
if service.libp2p.swarm.subscribe_kind(topic_kind.clone()) { if service.libp2p.swarm.subscribe_kind(topic_kind.clone()) {
subscribed_topics.push(topic_kind.clone()); subscribed_topics.push(topic_kind.clone());
} else { } else {
warn!(service.log, "Could not subscribe to topic"; "topic" => format!("{}",topic_kind)); warn!(service.log, "Could not subscribe to topic"; "topic" => %topic_kind);
} }
} }
@ -412,13 +412,13 @@ fn spawn_service<T: BeaconChainTypes>(
service.libp2p.swarm.update_enr_subnet(subnet_id, true); service.libp2p.swarm.update_enr_subnet(subnet_id, true);
subscribed_topics.push(topic_kind.clone()); subscribed_topics.push(topic_kind.clone());
} else { } else {
warn!(service.log, "Could not subscribe to topic"; "topic" => format!("{}",topic_kind)); warn!(service.log, "Could not subscribe to topic"; "topic" => %topic_kind);
} }
} }
} }
if !subscribed_topics.is_empty() { if !subscribed_topics.is_empty() {
info!(service.log, "Subscribed to topics"; "topics" => format!("{:?}", subscribed_topics)); info!(service.log, "Subscribed to topics"; "topics" => ?subscribed_topics);
} }
} }
} }
@ -545,7 +545,7 @@ fn spawn_service<T: BeaconChainTypes>(
} }
Libp2pEvent::ZeroListeners => { Libp2pEvent::ZeroListeners => {
let _ = shutdown_sender.send("All listeners are closed. Unable to listen").await.map_err(|e| { let _ = shutdown_sender.send("All listeners are closed. Unable to listen").await.map_err(|e| {
warn!(service.log, "failed to send a shutdown signal"; "error" => e.to_string() warn!(service.log, "failed to send a shutdown signal"; "error" => %e
) )
}); });
} }

View File

@ -611,7 +611,7 @@ impl<T: BeaconChainTypes> SyncManager<T> {
if let Some(peer_info) = self.network_globals.peers.write().peer_info_mut(peer_id) { if let Some(peer_info) = self.network_globals.peers.write().peer_info_mut(peer_id) {
let new_state = sync_type.as_sync_status(remote_sync_info); let new_state = sync_type.as_sync_status(remote_sync_info);
let rpr = new_state.to_string(); let rpr = new_state.as_str();
let was_updated = peer_info.sync_status.update(new_state); let was_updated = peer_info.sync_status.update(new_state);
if was_updated { if was_updated {
debug!(self.log, "Peer transitioned sync state"; "peer_id" => %peer_id, "new_state" => rpr, debug!(self.log, "Peer transitioned sync state"; "peer_id" => %peer_id, "new_state" => rpr,

View File

@ -125,7 +125,7 @@ impl<T: EthSpec> SyncNetworkContext<T> {
"Sending BlocksByRoot Request"; "Sending BlocksByRoot Request";
"method" => "BlocksByRoot", "method" => "BlocksByRoot",
"count" => request.block_roots.len(), "count" => request.block_roots.len(),
"peer" => format!("{:?}", peer_id) "peer" => %peer_id
); );
self.send_rpc_request(peer_id, Request::BlocksByRoot(request)) self.send_rpc_request(peer_id, Request::BlocksByRoot(request))
} }
@ -139,11 +139,11 @@ impl<T: EthSpec> SyncNetworkContext<T> {
} }
pub fn report_peer(&mut self, peer_id: PeerId, action: PeerAction) { pub fn report_peer(&mut self, peer_id: PeerId, action: PeerAction) {
debug!(self.log, "Sync reporting peer"; "peer_id" => peer_id.to_string(), "action" => action.to_string()); debug!(self.log, "Sync reporting peer"; "peer_id" => %peer_id, "action" => %action);
self.network_send self.network_send
.send(NetworkMessage::ReportPeer { peer_id, action }) .send(NetworkMessage::ReportPeer { peer_id, action })
.unwrap_or_else(|e| { .unwrap_or_else(|e| {
warn!(self.log, "Could not report peer, channel failed"; "error"=> e.to_string()); warn!(self.log, "Could not report peer, channel failed"; "error"=> %e);
}); });
} }
@ -166,7 +166,7 @@ impl<T: EthSpec> SyncNetworkContext<T> {
self.network_send self.network_send
.send(NetworkMessage::SubscribeCoreTopics) .send(NetworkMessage::SubscribeCoreTopics)
.unwrap_or_else(|e| { .unwrap_or_else(|e| {
warn!(self.log, "Could not subscribe to core topics."; "error" => e.to_string()); warn!(self.log, "Could not subscribe to core topics."; "error" => %e);
}); });
} }

View File

@ -391,7 +391,7 @@ impl<T: EthSpec> slog::KV for BatchInfo<T> {
)?; )?;
serializer.emit_usize("downloaded", self.failed_download_attempts.len())?; serializer.emit_usize("downloaded", self.failed_download_attempts.len())?;
serializer.emit_usize("processed", self.failed_processing_attempts.len())?; serializer.emit_usize("processed", self.failed_processing_attempts.len())?;
serializer.emit_str("state", &format!("{:?}", self.state))?; serializer.emit_arguments("state", &format_args!("{:?}", self.state))?;
slog::Result::Ok(()) slog::Result::Ok(())
} }
} }

View File

@ -513,7 +513,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
// This should be unlikely, so we tolerate these errors, but not often. // This should be unlikely, so we tolerate these errors, but not often.
let action = PeerAction::LowToleranceError; let action = PeerAction::LowToleranceError;
warn!(self.log, "Batch failed to download. Dropping chain scoring peers"; warn!(self.log, "Batch failed to download. Dropping chain scoring peers";
"score_adjustment" => action.to_string(), "score_adjustment" => %action,
"batch_epoch"=> batch_id); "batch_epoch"=> batch_id);
for (peer, _) in self.peers.drain() { for (peer, _) in self.peers.drain() {
network.report_peer(peer, action); network.report_peer(peer, action);
@ -1028,7 +1028,7 @@ impl<T: BeaconChainTypes> slog::KV for SyncingChain<T> {
"to", "to",
serializer, serializer,
)?; )?;
serializer.emit_str("end_root", &self.target_head_root.to_string())?; serializer.emit_arguments("end_root", &format_args!("{}", self.target_head_root))?;
Value::serialize( Value::serialize(
&self.processing_target, &self.processing_target,
record, record,

View File

@ -215,13 +215,15 @@ impl<T: BeaconChainTypes> ChainCollection<T> {
} }
} }
pub fn state(&self) -> Result<Option<(RangeSyncType, Slot /* from */, Slot /* to */)>, String> { pub fn state(
&self,
) -> Result<Option<(RangeSyncType, Slot /* from */, Slot /* to */)>, &'static str> {
match self.state { match self.state {
RangeSyncState::Finalized(ref syncing_id) => { RangeSyncState::Finalized(ref syncing_id) => {
let chain = self let chain = self
.finalized_chains .finalized_chains
.get(syncing_id) .get(syncing_id)
.ok_or(format!("Finalized syncing chain not found: {}", syncing_id))?; .ok_or("Finalized syncing chain not found")?;
Ok(Some(( Ok(Some((
RangeSyncType::Finalized, RangeSyncType::Finalized,
chain.start_epoch.start_slot(T::EthSpec::slots_per_epoch()), chain.start_epoch.start_slot(T::EthSpec::slots_per_epoch()),
@ -234,7 +236,7 @@ impl<T: BeaconChainTypes> ChainCollection<T> {
let chain = self let chain = self
.head_chains .head_chains
.get(id) .get(id)
.ok_or(format!("Head syncing chain not found: {}", id))?; .ok_or("Head syncing chain not found")?;
let start = chain.start_epoch.start_slot(T::EthSpec::slots_per_epoch()); let start = chain.start_epoch.start_slot(T::EthSpec::slots_per_epoch());
let target = chain.target_head_slot; let target = chain.target_head_slot;
@ -242,8 +244,7 @@ impl<T: BeaconChainTypes> ChainCollection<T> {
.map(|(min_start, max_slot)| (min_start.min(start), max_slot.max(target))) .map(|(min_start, max_slot)| (min_start.min(start), max_slot.max(target)))
.or(Some((start, target))); .or(Some((start, target)));
} }
let (start_slot, target_slot) = let (start_slot, target_slot) = range.ok_or("Syncing head with empty head ids")?;
range.ok_or_else(|| "Syncing head with empty head ids".to_string())?;
Ok(Some((RangeSyncType::Head, start_slot, target_slot))) Ok(Some((RangeSyncType::Head, start_slot, target_slot)))
} }
RangeSyncState::Idle => Ok(None), RangeSyncState::Idle => Ok(None),

View File

@ -88,7 +88,9 @@ impl<T: BeaconChainTypes> RangeSync<T> {
} }
} }
pub fn state(&self) -> Result<Option<(RangeSyncType, Slot /* from */, Slot /* to */)>, String> { pub fn state(
&self,
) -> Result<Option<(RangeSyncType, Slot /* from */, Slot /* to */)>, &'static str> {
self.chains.state() self.chains.state()
} }