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:
ThreeHrSleep
2025-03-13 04:01:05 +05:30
committed by GitHub
parent f23f984f85
commit d60c24ef1c
241 changed files with 9485 additions and 9328 deletions

View File

@@ -32,16 +32,14 @@ rand = { workspace = true }
redb = { version = "2.1.4", optional = true }
safe_arith = { workspace = true }
serde = { workspace = true }
slog = { workspace = true }
ssz_types = { workspace = true }
strum = { workspace = true }
tracing = { workspace = true }
tree_hash = { workspace = true }
tree_hash_derive = { workspace = true }
types = { workspace = true }
[dev-dependencies]
logging = { workspace = true }
maplit = { workspace = true }
rayon = { workspace = true }
tempfile = { workspace = true }

View File

@@ -10,9 +10,9 @@ directory = { workspace = true }
lighthouse_network = { workspace = true }
network = { workspace = true }
slasher = { workspace = true }
slog = { workspace = true }
slot_clock = { workspace = true }
state_processing = { workspace = true }
task_executor = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
types = { workspace = true }

View File

@@ -8,7 +8,6 @@ use slasher::{
metrics::{self, SLASHER_DATABASE_SIZE, SLASHER_RUN_TIME},
Slasher,
};
use slog::{debug, error, info, trace, warn, Logger};
use slot_clock::SlotClock;
use state_processing::{
per_block_processing::errors::{
@@ -21,6 +20,7 @@ use std::sync::Arc;
use task_executor::TaskExecutor;
use tokio::sync::mpsc::UnboundedSender;
use tokio::time::{interval_at, Duration, Instant};
use tracing::{debug, error, info, info_span, trace, warn, Instrument};
use types::{AttesterSlashing, Epoch, EthSpec, ProposerSlashing};
pub struct SlasherService<T: BeaconChainTypes> {
@@ -47,9 +47,8 @@ impl<T: BeaconChainTypes> SlasherService<T> {
.slasher
.clone()
.ok_or("No slasher is configured")?;
let log = slasher.log().clone();
info!(log, "Starting slasher"; "broadcast" => slasher.config().broadcast);
info!(broadcast = slasher.config().broadcast, "Starting slasher");
// Buffer just a single message in the channel. If the receiver is still processing, we
// don't need to burden them with more work (we can wait).
@@ -65,13 +64,17 @@ impl<T: BeaconChainTypes> SlasherService<T> {
update_period,
slot_offset,
notif_sender,
log,
),
)
.instrument(tracing::info_span!("slasher", service = "slasher")),
"slasher_server_notifier",
);
executor.spawn_blocking(
|| Self::run_processor(beacon_chain, slasher, notif_receiver, network_sender),
|| {
let span = info_span!("slasher", service = "slasher");
let _ = span.enter();
Self::run_processor(beacon_chain, slasher, notif_receiver, network_sender);
},
"slasher_server_processor",
);
@@ -84,14 +87,13 @@ impl<T: BeaconChainTypes> SlasherService<T> {
update_period: u64,
slot_offset: f64,
notif_sender: SyncSender<Epoch>,
log: Logger,
) {
let slot_offset = Duration::from_secs_f64(slot_offset);
let start_instant =
if let Some(duration_to_next_slot) = beacon_chain.slot_clock.duration_to_next_slot() {
Instant::now() + duration_to_next_slot + slot_offset
} else {
error!(log, "Error aligning slasher to slot clock");
error!("Error aligning slasher to slot clock");
Instant::now()
};
let mut interval = interval_at(start_instant, Duration::from_secs(update_period));
@@ -104,7 +106,7 @@ impl<T: BeaconChainTypes> SlasherService<T> {
break;
}
} else {
trace!(log, "Slasher has nothing to do: we are pre-genesis");
trace!("Slasher has nothing to do: we are pre-genesis");
}
}
}
@@ -116,7 +118,6 @@ impl<T: BeaconChainTypes> SlasherService<T> {
notif_receiver: Receiver<Epoch>,
network_sender: UnboundedSender<NetworkMessage<T::EthSpec>>,
) {
let log = slasher.log();
while let Ok(current_epoch) = notif_receiver.recv() {
let t = Instant::now();
@@ -125,10 +126,9 @@ impl<T: BeaconChainTypes> SlasherService<T> {
Ok(stats) => Some(stats),
Err(e) => {
error!(
log,
"Error during scheduled slasher processing";
"epoch" => current_epoch,
"error" => ?e,
epoch = %current_epoch,
error = ?e,
"Error during scheduled slasher processing"
);
None
}
@@ -139,10 +139,9 @@ impl<T: BeaconChainTypes> SlasherService<T> {
// If the database is full then pruning could help to free it up.
if let Err(e) = slasher.prune_database(current_epoch) {
error!(
log,
"Error during slasher database pruning";
"epoch" => current_epoch,
"error" => ?e,
epoch = %current_epoch,
error = ?e,
"Error during slasher database pruning"
);
continue;
};
@@ -155,12 +154,11 @@ impl<T: BeaconChainTypes> SlasherService<T> {
if let Some(stats) = stats {
debug!(
log,
"Completed slasher update";
"epoch" => current_epoch,
"time_taken" => format!("{}ms", t.elapsed().as_millis()),
"num_attestations" => stats.attestation_stats.num_processed,
"num_blocks" => stats.block_stats.num_processed,
epoch = %current_epoch,
time_taken = format!("{}ms", t.elapsed().as_millis()),
num_attestations = stats.attestation_stats.num_processed,
num_blocks = stats.block_stats.num_processed,
"Completed slasher update"
);
}
}
@@ -181,7 +179,6 @@ impl<T: BeaconChainTypes> SlasherService<T> {
slasher: &Slasher<T::EthSpec>,
network_sender: &UnboundedSender<NetworkMessage<T::EthSpec>>,
) {
let log = slasher.log();
let attester_slashings = slasher.get_attester_slashings();
for slashing in attester_slashings {
@@ -198,18 +195,16 @@ impl<T: BeaconChainTypes> SlasherService<T> {
BlockOperationError::Invalid(AttesterSlashingInvalid::NoSlashableIndices),
)) => {
debug!(
log,
"Skipping attester slashing for slashed validators";
"slashing" => ?slashing,
?slashing,
"Skipping attester slashing for slashed validators"
);
continue;
}
Err(e) => {
warn!(
log,
"Attester slashing produced is invalid";
"error" => ?e,
"slashing" => ?slashing,
error = ?e,
?slashing,
"Attester slashing produced is invalid"
);
continue;
}
@@ -224,9 +219,8 @@ impl<T: BeaconChainTypes> SlasherService<T> {
Self::publish_attester_slashing(beacon_chain, network_sender, slashing)
{
debug!(
log,
"Unable to publish attester slashing";
"error" => e,
error = ?e,
"Unable to publish attester slashing"
);
}
}
@@ -238,7 +232,6 @@ impl<T: BeaconChainTypes> SlasherService<T> {
slasher: &Slasher<T::EthSpec>,
network_sender: &UnboundedSender<NetworkMessage<T::EthSpec>>,
) {
let log = slasher.log();
let proposer_slashings = slasher.get_proposer_slashings();
for slashing in proposer_slashings {
@@ -254,18 +247,16 @@ impl<T: BeaconChainTypes> SlasherService<T> {
)),
)) => {
debug!(
log,
"Skipping proposer slashing for slashed validator";
"validator_index" => index,
validator_index = index,
"Skipping proposer slashing for slashed validator"
);
continue;
}
Err(e) => {
error!(
log,
"Proposer slashing produced is invalid";
"error" => ?e,
"slashing" => ?slashing,
error = ?e,
?slashing,
"Proposer slashing produced is invalid"
);
continue;
}
@@ -277,9 +268,8 @@ impl<T: BeaconChainTypes> SlasherService<T> {
Self::publish_proposer_slashing(beacon_chain, network_sender, slashing)
{
debug!(
log,
"Unable to publish proposer slashing";
"error" => e,
error = ?e,
"Unable to publish proposer slashing"
);
}
}

View File

@@ -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)?;

View File

@@ -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);
}

View File

@@ -1,6 +1,5 @@
#![cfg(any(feature = "mdbx", feature = "lmdb", feature = "redb"))]
use logging::test_logger;
use maplit::hashset;
use rayon::prelude::*;
use slasher::{
@@ -272,7 +271,7 @@ fn slasher_test(
let tempdir = tempdir().unwrap();
let config = Config::new(tempdir.path().into());
let spec = chain_spec();
let slasher = Slasher::open(config, spec, test_logger()).unwrap();
let slasher = Slasher::open(config, spec).unwrap();
let current_epoch = Epoch::new(current_epoch);
for (i, attestation) in attestations.iter().enumerate() {
@@ -302,7 +301,7 @@ fn parallel_slasher_test(
let tempdir = tempdir().unwrap();
let config = Config::new(tempdir.path().into());
let spec = chain_spec();
let slasher = Slasher::open(config, spec, test_logger()).unwrap();
let slasher = Slasher::open(config, spec).unwrap();
let current_epoch = Epoch::new(current_epoch);
attestations

View File

@@ -1,6 +1,5 @@
#![cfg(any(feature = "mdbx", feature = "lmdb", feature = "redb"))]
use logging::test_logger;
use slasher::{
test_utils::{block as test_block, chain_spec, E},
Config, Slasher,
@@ -13,7 +12,7 @@ fn empty_pruning() {
let tempdir = tempdir().unwrap();
let config = Config::new(tempdir.path().into());
let spec = chain_spec();
let slasher = Slasher::<E>::open(config, spec, test_logger()).unwrap();
let slasher = Slasher::<E>::open(config, spec).unwrap();
slasher.prune_database(Epoch::new(0)).unwrap();
}
@@ -27,7 +26,7 @@ fn block_pruning() {
config.history_length = 2;
let spec = chain_spec();
let slasher = Slasher::<E>::open(config.clone(), spec, test_logger()).unwrap();
let slasher = Slasher::<E>::open(config.clone(), spec).unwrap();
let current_epoch = Epoch::from(2 * config.history_length);
// Pruning the empty database should be safe.

View File

@@ -1,6 +1,5 @@
#![cfg(any(feature = "mdbx", feature = "lmdb", feature = "redb"))]
use logging::test_logger;
use rand::prelude::*;
use slasher::{
test_utils::{
@@ -36,9 +35,8 @@ impl Default for TestConfig {
fn make_db() -> (TempDir, SlasherDB<E>) {
let tempdir = tempdir().unwrap();
let initial_config = Arc::new(Config::new(tempdir.path().into()));
let logger = test_logger();
let spec = chain_spec();
let db = SlasherDB::open(initial_config.clone(), spec, logger).unwrap();
let db = SlasherDB::open(initial_config.clone(), spec).unwrap();
(tempdir, db)
}
@@ -60,7 +58,7 @@ fn random_test(seed: u64, mut db: SlasherDB<E>, test_config: TestConfig) -> Slas
let config = Arc::new(config);
db.update_config(config.clone());
let slasher = Slasher::<E>::from_config_and_db(config.clone(), db, test_logger()).unwrap();
let slasher = Slasher::<E>::from_config_and_db(config.clone(), db).unwrap();
let validators = (0..num_validators as u64).collect::<Vec<u64>>();

View File

@@ -1,6 +1,5 @@
#![cfg(any(feature = "mdbx", feature = "lmdb", feature = "redb"))]
use logging::test_logger;
use slasher::{
test_utils::{chain_spec, indexed_att},
Config, Slasher,
@@ -17,7 +16,7 @@ fn attestation_pruning_empty_wrap_around() {
config.chunk_size = 16;
config.history_length = 16;
let slasher = Slasher::open(config.clone(), spec, test_logger()).unwrap();
let slasher = Slasher::open(config.clone(), spec).unwrap();
let v = vec![0];
let history_length = config.history_length as u64;