mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 20:22:02 +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:
@@ -12,12 +12,12 @@ use interface::{Environment, OpenDatabases, RwTransaction};
|
||||
use lru::LruCache;
|
||||
use parking_lot::Mutex;
|
||||
use serde::de::DeserializeOwned;
|
||||
use slog::{info, Logger};
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::borrow::{Borrow, Cow};
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
use tracing::info;
|
||||
use tree_hash::TreeHash;
|
||||
use types::{
|
||||
AggregateSignature, AttestationData, ChainSpec, Epoch, EthSpec, Hash256, IndexedAttestation,
|
||||
@@ -287,8 +287,8 @@ fn ssz_decode<T: Decode>(bytes: Cow<[u8]>) -> Result<T, Error> {
|
||||
}
|
||||
|
||||
impl<E: EthSpec> SlasherDB<E> {
|
||||
pub fn open(config: Arc<Config>, spec: Arc<ChainSpec>, log: Logger) -> Result<Self, Error> {
|
||||
info!(log, "Opening slasher database"; "backend" => %config.backend);
|
||||
pub fn open(config: Arc<Config>, spec: Arc<ChainSpec>) -> Result<Self, Error> {
|
||||
info!(backend = %config.backend, "Opening slasher database");
|
||||
|
||||
std::fs::create_dir_all(&config.database_path)?;
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ use crate::{
|
||||
IndexedAttestationId, ProposerSlashingStatus, RwTransaction, SimpleBatch, SlasherDB,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use slog::{debug, error, info, Logger};
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
use tracing::{debug, error, info};
|
||||
use types::{
|
||||
AttesterSlashing, ChainSpec, Epoch, EthSpec, IndexedAttestation, ProposerSlashing,
|
||||
SignedBeaconBlockHeader,
|
||||
@@ -25,26 +25,21 @@ pub struct Slasher<E: EthSpec> {
|
||||
attester_slashings: Mutex<HashSet<AttesterSlashing<E>>>,
|
||||
proposer_slashings: Mutex<HashSet<ProposerSlashing>>,
|
||||
config: Arc<Config>,
|
||||
log: Logger,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Slasher<E> {
|
||||
pub fn open(config: Config, spec: Arc<ChainSpec>, log: Logger) -> Result<Self, Error> {
|
||||
pub fn open(config: Config, spec: Arc<ChainSpec>) -> Result<Self, Error> {
|
||||
config.validate()?;
|
||||
let config = Arc::new(config);
|
||||
let db = SlasherDB::open(config.clone(), spec, log.clone())?;
|
||||
Self::from_config_and_db(config, db, log)
|
||||
let db = SlasherDB::open(config.clone(), spec)?;
|
||||
Self::from_config_and_db(config, db)
|
||||
}
|
||||
|
||||
/// TESTING ONLY.
|
||||
///
|
||||
/// Initialise a slasher database from an existing `db`. The caller must ensure that the
|
||||
/// database's config matches the one provided.
|
||||
pub fn from_config_and_db(
|
||||
config: Arc<Config>,
|
||||
db: SlasherDB<E>,
|
||||
log: Logger,
|
||||
) -> Result<Self, Error> {
|
||||
pub fn from_config_and_db(config: Arc<Config>, db: SlasherDB<E>) -> Result<Self, Error> {
|
||||
config.validate()?;
|
||||
let attester_slashings = Mutex::new(HashSet::new());
|
||||
let proposer_slashings = Mutex::new(HashSet::new());
|
||||
@@ -57,7 +52,6 @@ impl<E: EthSpec> Slasher<E> {
|
||||
attester_slashings,
|
||||
proposer_slashings,
|
||||
config,
|
||||
log,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -80,10 +74,6 @@ impl<E: EthSpec> Slasher<E> {
|
||||
&self.config
|
||||
}
|
||||
|
||||
pub fn log(&self) -> &Logger {
|
||||
&self.log
|
||||
}
|
||||
|
||||
/// Accept an attestation from the network and queue it for processing.
|
||||
pub fn accept_attestation(&self, attestation: IndexedAttestation<E>) {
|
||||
self.attestation_queue.queue(attestation);
|
||||
@@ -126,11 +116,7 @@ impl<E: EthSpec> Slasher<E> {
|
||||
|
||||
let num_slashings = slashings.len();
|
||||
if !slashings.is_empty() {
|
||||
info!(
|
||||
self.log,
|
||||
"Found {} new proposer slashings!",
|
||||
slashings.len(),
|
||||
);
|
||||
info!("Found {} new proposer slashings!", slashings.len());
|
||||
self.proposer_slashings.lock().extend(slashings);
|
||||
}
|
||||
|
||||
@@ -156,11 +142,10 @@ impl<E: EthSpec> Slasher<E> {
|
||||
self.attestation_queue.requeue(deferred);
|
||||
|
||||
debug!(
|
||||
self.log,
|
||||
"Pre-processing attestations for slasher";
|
||||
"num_valid" => num_valid,
|
||||
"num_deferred" => num_deferred,
|
||||
"num_dropped" => num_dropped,
|
||||
%num_valid,
|
||||
num_deferred,
|
||||
num_dropped,
|
||||
"Pre-processing attestations for slasher"
|
||||
);
|
||||
metrics::set_gauge(&SLASHER_NUM_ATTESTATIONS_VALID, num_valid as i64);
|
||||
metrics::set_gauge(&SLASHER_NUM_ATTESTATIONS_DEFERRED, num_deferred as i64);
|
||||
@@ -194,12 +179,7 @@ impl<E: EthSpec> Slasher<E> {
|
||||
}
|
||||
}
|
||||
|
||||
debug!(
|
||||
self.log,
|
||||
"Stored attestations in slasher DB";
|
||||
"num_stored" => num_stored,
|
||||
"num_valid" => num_valid,
|
||||
);
|
||||
debug!(num_stored, ?num_valid, "Stored attestations in slasher DB");
|
||||
metrics::set_gauge(
|
||||
&SLASHER_NUM_ATTESTATIONS_STORED_PER_BATCH,
|
||||
num_stored as i64,
|
||||
@@ -239,19 +219,14 @@ impl<E: EthSpec> Slasher<E> {
|
||||
) {
|
||||
Ok(slashings) => {
|
||||
if !slashings.is_empty() {
|
||||
info!(
|
||||
self.log,
|
||||
"Found {} new double-vote slashings!",
|
||||
slashings.len()
|
||||
);
|
||||
info!("Found {} new double-vote slashings!", slashings.len());
|
||||
}
|
||||
self.attester_slashings.lock().extend(slashings);
|
||||
}
|
||||
Err(e) => {
|
||||
error!(
|
||||
self.log,
|
||||
"Error checking for double votes";
|
||||
"error" => format!("{:?}", e)
|
||||
error = ?e,
|
||||
"Error checking for double votes"
|
||||
);
|
||||
return Err(e);
|
||||
}
|
||||
@@ -269,20 +244,12 @@ impl<E: EthSpec> Slasher<E> {
|
||||
) {
|
||||
Ok(slashings) => {
|
||||
if !slashings.is_empty() {
|
||||
info!(
|
||||
self.log,
|
||||
"Found {} new surround slashings!",
|
||||
slashings.len()
|
||||
);
|
||||
info!("Found {} new surround slashings!", slashings.len());
|
||||
}
|
||||
self.attester_slashings.lock().extend(slashings);
|
||||
}
|
||||
Err(e) => {
|
||||
error!(
|
||||
self.log,
|
||||
"Error processing array update";
|
||||
"error" => format!("{:?}", e),
|
||||
);
|
||||
error!(error = ?e, "Error processing array update");
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
@@ -315,10 +282,9 @@ impl<E: EthSpec> Slasher<E> {
|
||||
|
||||
if let Some(slashing) = slashing_status.into_slashing(attestation) {
|
||||
debug!(
|
||||
self.log,
|
||||
"Found double-vote slashing";
|
||||
"validator_index" => validator_index,
|
||||
"epoch" => slashing.attestation_1().data().target.epoch,
|
||||
validator_index,
|
||||
epoch = %slashing.attestation_1().data().target.epoch,
|
||||
"Found double-vote slashing"
|
||||
);
|
||||
slashings.insert(slashing);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user