mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 02:01:40 +00:00
Integrate tracing (#6339)
Tracing Integration
- [reference](5bbf1859e9/projects/project-ideas.md (L297))
- [x] replace slog & log with tracing throughout the codebase
- [x] implement custom crit log
- [x] make relevant changes in the formatter
- [x] replace sloggers
- [x] re-write SSE logging components
cc: @macladson @eserilev
This commit is contained in:
@@ -9,7 +9,6 @@ use libp2p::core::{multiaddr::Multiaddr, muxing::StreamMuxerBox, transport::Boxe
|
||||
use libp2p::identity::{secp256k1, Keypair};
|
||||
use libp2p::{core, noise, yamux, PeerId, Transport};
|
||||
use prometheus_client::registry::Registry;
|
||||
use slog::{debug, warn};
|
||||
use ssz::Decode;
|
||||
use std::collections::HashSet;
|
||||
use std::fs::File;
|
||||
@@ -17,6 +16,7 @@ use std::io::prelude::*;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tracing::{debug, warn};
|
||||
use types::{
|
||||
ChainSpec, DataColumnSubnetId, EnrForkId, EthSpec, ForkContext, SubnetId, SyncSubnetId,
|
||||
};
|
||||
@@ -107,21 +107,21 @@ fn keypair_from_bytes(mut bytes: Vec<u8>) -> Result<Keypair, String> {
|
||||
/// generated and is then saved to disk.
|
||||
///
|
||||
/// Currently only secp256k1 keys are allowed, as these are the only keys supported by discv5.
|
||||
pub fn load_private_key(config: &NetworkConfig, log: &slog::Logger) -> Keypair {
|
||||
pub fn load_private_key(config: &NetworkConfig) -> Keypair {
|
||||
// check for key from disk
|
||||
let network_key_f = config.network_dir.join(NETWORK_KEY_FILENAME);
|
||||
if let Ok(mut network_key_file) = File::open(network_key_f.clone()) {
|
||||
let mut key_bytes: Vec<u8> = Vec::with_capacity(36);
|
||||
match network_key_file.read_to_end(&mut key_bytes) {
|
||||
Err(_) => debug!(log, "Could not read network key file"),
|
||||
Err(_) => debug!("Could not read network key file"),
|
||||
Ok(_) => {
|
||||
// only accept secp256k1 keys for now
|
||||
if let Ok(secret_key) = secp256k1::SecretKey::try_from_bytes(&mut key_bytes) {
|
||||
let kp: secp256k1::Keypair = secret_key.into();
|
||||
debug!(log, "Loaded network key from disk.");
|
||||
debug!("Loaded network key from disk.");
|
||||
return kp.into();
|
||||
} else {
|
||||
debug!(log, "Network key file is not a valid secp256k1 key");
|
||||
debug!("Network key file is not a valid secp256k1 key");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,12 +134,12 @@ pub fn load_private_key(config: &NetworkConfig, log: &slog::Logger) -> Keypair {
|
||||
.and_then(|mut f| f.write_all(&local_private_key.secret().to_bytes()))
|
||||
{
|
||||
Ok(_) => {
|
||||
debug!(log, "New network key generated and written to disk");
|
||||
debug!("New network key generated and written to disk");
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(
|
||||
log,
|
||||
"Could not write node key to file: {:?}. error: {}", network_key_f, e
|
||||
"Could not write node key to file: {:?}. error: {}",
|
||||
network_key_f, e
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,6 @@ pub fn strip_peer_id(addr: &mut Multiaddr) {
|
||||
pub fn load_or_build_metadata<E: EthSpec>(
|
||||
network_dir: &Path,
|
||||
custody_group_count_opt: Option<u64>,
|
||||
log: &slog::Logger,
|
||||
) -> MetaData<E> {
|
||||
// We load a V2 metadata version by default (regardless of current fork)
|
||||
// since a V2 metadata can be converted to V1. The RPC encoder is responsible
|
||||
@@ -192,7 +191,7 @@ pub fn load_or_build_metadata<E: EthSpec>(
|
||||
{
|
||||
meta_data.seq_number += 1;
|
||||
}
|
||||
debug!(log, "Loaded metadata from disk");
|
||||
debug!("Loaded metadata from disk");
|
||||
}
|
||||
Err(_) => {
|
||||
match MetaDataV1::<E>::from_ssz_bytes(&metadata_ssz) {
|
||||
@@ -200,13 +199,12 @@ pub fn load_or_build_metadata<E: EthSpec>(
|
||||
let persisted_metadata = MetaData::V1(persisted_metadata);
|
||||
// Increment seq number as the persisted metadata version is updated
|
||||
meta_data.seq_number = *persisted_metadata.seq_number() + 1;
|
||||
debug!(log, "Loaded metadata from disk");
|
||||
debug!("Loaded metadata from disk");
|
||||
}
|
||||
Err(e) => {
|
||||
debug!(
|
||||
log,
|
||||
"Metadata from file could not be decoded";
|
||||
"error" => ?e,
|
||||
error = ?e,
|
||||
"Metadata from file could not be decoded"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -227,8 +225,8 @@ pub fn load_or_build_metadata<E: EthSpec>(
|
||||
MetaData::V2(meta_data)
|
||||
};
|
||||
|
||||
debug!(log, "Metadata sequence number"; "seq_num" => meta_data.seq_number());
|
||||
save_metadata_to_disk(network_dir, meta_data.clone(), log);
|
||||
debug!(seq_num = meta_data.seq_number(), "Metadata sequence number");
|
||||
save_metadata_to_disk(network_dir, meta_data.clone());
|
||||
meta_data
|
||||
}
|
||||
|
||||
@@ -275,11 +273,7 @@ pub(crate) fn create_whitelist_filter(
|
||||
}
|
||||
|
||||
/// Persist metadata to disk
|
||||
pub(crate) fn save_metadata_to_disk<E: EthSpec>(
|
||||
dir: &Path,
|
||||
metadata: MetaData<E>,
|
||||
log: &slog::Logger,
|
||||
) {
|
||||
pub(crate) fn save_metadata_to_disk<E: EthSpec>(dir: &Path, metadata: MetaData<E>) {
|
||||
let _ = std::fs::create_dir_all(dir);
|
||||
// We always store the metadata v2 to disk because
|
||||
// custody_group_count parameter doesn't need to be persisted across runs.
|
||||
@@ -288,14 +282,13 @@ pub(crate) fn save_metadata_to_disk<E: EthSpec>(
|
||||
let metadata_bytes = metadata.metadata_v2().as_ssz_bytes();
|
||||
match File::create(dir.join(METADATA_FILENAME)).and_then(|mut f| f.write_all(&metadata_bytes)) {
|
||||
Ok(_) => {
|
||||
debug!(log, "Metadata written to disk");
|
||||
debug!("Metadata written to disk");
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(
|
||||
log,
|
||||
"Could not write metadata to disk";
|
||||
"file" => format!("{:?}{:?}", dir, METADATA_FILENAME),
|
||||
"error" => %e
|
||||
file = format!("{:?}{:?}", dir, METADATA_FILENAME),
|
||||
error = %e,
|
||||
"Could not write metadata to disk"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user