mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-16 03:12:41 +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:
@@ -611,7 +611,7 @@ impl<T: BeaconChainTypes> SyncManager<T> {
|
||||
|
||||
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 rpr = new_state.to_string();
|
||||
let rpr = new_state.as_str();
|
||||
let was_updated = peer_info.sync_status.update(new_state);
|
||||
if was_updated {
|
||||
debug!(self.log, "Peer transitioned sync state"; "peer_id" => %peer_id, "new_state" => rpr,
|
||||
|
||||
@@ -125,7 +125,7 @@ impl<T: EthSpec> SyncNetworkContext<T> {
|
||||
"Sending BlocksByRoot Request";
|
||||
"method" => "BlocksByRoot",
|
||||
"count" => request.block_roots.len(),
|
||||
"peer" => format!("{:?}", peer_id)
|
||||
"peer" => %peer_id
|
||||
);
|
||||
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) {
|
||||
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
|
||||
.send(NetworkMessage::ReportPeer { peer_id, action })
|
||||
.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
|
||||
.send(NetworkMessage::SubscribeCoreTopics)
|
||||
.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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -391,7 +391,7 @@ impl<T: EthSpec> slog::KV for BatchInfo<T> {
|
||||
)?;
|
||||
serializer.emit_usize("downloaded", self.failed_download_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(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -513,7 +513,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
|
||||
// This should be unlikely, so we tolerate these errors, but not often.
|
||||
let action = PeerAction::LowToleranceError;
|
||||
warn!(self.log, "Batch failed to download. Dropping chain scoring peers";
|
||||
"score_adjustment" => action.to_string(),
|
||||
"score_adjustment" => %action,
|
||||
"batch_epoch"=> batch_id);
|
||||
for (peer, _) in self.peers.drain() {
|
||||
network.report_peer(peer, action);
|
||||
@@ -1028,7 +1028,7 @@ impl<T: BeaconChainTypes> slog::KV for SyncingChain<T> {
|
||||
"to",
|
||||
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(
|
||||
&self.processing_target,
|
||||
record,
|
||||
|
||||
@@ -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 {
|
||||
RangeSyncState::Finalized(ref syncing_id) => {
|
||||
let chain = self
|
||||
.finalized_chains
|
||||
.get(syncing_id)
|
||||
.ok_or(format!("Finalized syncing chain not found: {}", syncing_id))?;
|
||||
.ok_or("Finalized syncing chain not found")?;
|
||||
Ok(Some((
|
||||
RangeSyncType::Finalized,
|
||||
chain.start_epoch.start_slot(T::EthSpec::slots_per_epoch()),
|
||||
@@ -234,7 +236,7 @@ impl<T: BeaconChainTypes> ChainCollection<T> {
|
||||
let chain = self
|
||||
.head_chains
|
||||
.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 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)))
|
||||
.or(Some((start, target)));
|
||||
}
|
||||
let (start_slot, target_slot) =
|
||||
range.ok_or_else(|| "Syncing head with empty head ids".to_string())?;
|
||||
let (start_slot, target_slot) = range.ok_or("Syncing head with empty head ids")?;
|
||||
Ok(Some((RangeSyncType::Head, start_slot, target_slot)))
|
||||
}
|
||||
RangeSyncState::Idle => Ok(None),
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user