diff --git a/Cargo.lock b/Cargo.lock index bc235ad2f..e38755cd7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -596,6 +596,8 @@ dependencies = [ "serde_json", "slasher", "slog", + "slog-async", + "slog-term", "sloggers", "slot_clock", "smallvec", diff --git a/beacon_node/beacon_chain/Cargo.toml b/beacon_node/beacon_chain/Cargo.toml index a4182b773..26fdc0f5a 100644 --- a/beacon_node/beacon_chain/Cargo.toml +++ b/beacon_node/beacon_chain/Cargo.toml @@ -68,6 +68,8 @@ hex = "0.4.2" exit-future = "0.2.0" unused_port = {path = "../../common/unused_port"} oneshot_broadcast = { path = "../../common/oneshot_broadcast" } +slog-term = "2.6.0" +slog-async = "2.5.0" [[test]] name = "beacon_chain_tests" diff --git a/beacon_node/beacon_chain/src/test_utils.rs b/beacon_node/beacon_chain/src/test_utils.rs index 6696e15ee..a2dcdeefe 100644 --- a/beacon_node/beacon_chain/src/test_utils.rs +++ b/beacon_node/beacon_chain/src/test_utils.rs @@ -34,7 +34,9 @@ use rand::Rng; use rand::SeedableRng; use rayon::prelude::*; use sensitive_url::SensitiveUrl; -use slog::Logger; +use slog::{o, Drain, Logger}; +use slog_async::Async; +use slog_term::{FullFormat, TermDecorator}; use slot_clock::{SlotClock, SystemTimeSlotClock, TestingSlotClock}; use state_processing::per_block_processing::compute_timestamp_at_slot; use state_processing::{ @@ -72,7 +74,6 @@ pub type DiskHarnessType = BaseHarnessType, LevelDB pub type EphemeralHarnessType = BaseHarnessType, MemoryStore, TSlotClock>; - pub type EphemeralTestingSlotClockHarnessType = BaseHarnessType, MemoryStore, TestingSlotClock>; pub type EphemeralSystemTimeSlotClockHarnessType = @@ -2129,3 +2130,15 @@ impl fmt::Debug for BeaconChainHarness { write!(f, "BeaconChainHarness") } } + +pub fn build_log(level: slog::Level, enabled: bool) -> Logger { + let decorator = TermDecorator::new().build(); + let drain = FullFormat::new(decorator).build().fuse(); + let drain = Async::new(drain).build().fuse(); + + if enabled { + Logger::root(drain.filter_level(level).fuse(), o!()) + } else { + Logger::root(drain.filter(|_| false).fuse(), o!()) + } +} diff --git a/beacon_node/network/src/sync/range_sync/range.rs b/beacon_node/network/src/sync/range_sync/range.rs index 8fde80cbc..afa42371b 100644 --- a/beacon_node/network/src/sync/range_sync/range.rs +++ b/beacon_node/network/src/sync/range_sync/range.rs @@ -377,25 +377,26 @@ mod tests { use crate::beacon_processor::WorkEvent as BeaconWorkEvent; use crate::service::RequestId; use crate::NetworkMessage; - use beacon_chain::{builder::BeaconChainBuilder, test_utils::test_spec}; use beacon_chain::{ - builder::Witness, eth1_chain::CachingEth1Backend, parking_lot::RwLock, EngineState, + builder::Witness, + eth1_chain::CachingEth1Backend, + parking_lot::RwLock, + test_utils::{ + build_log, BeaconChainHarness, EphemeralSystemTimeSlotClockHarnessType as HarnessType, + }, + EngineState, }; use lighthouse_network::{ rpc::{BlocksByRangeRequest, StatusMessage}, NetworkGlobals, Request, }; - use slog::{o, Drain}; - use sloggers::{null::NullLoggerBuilder, Build}; - use slot_clock::{SlotClock, SystemTimeSlotClock}; - use std::time::{Duration, SystemTime}; + use slog::o; + use slot_clock::SystemTimeSlotClock; use std::{collections::HashSet, sync::Arc}; use store::MemoryStore; use tokio::sync::mpsc; use types::{Hash256, MinimalEthSpec as E}; - const SLOT_DURATION_MILLIS: u64 = 400; - #[derive(Debug)] struct FakeStorage { known_blocks: RwLock>, @@ -443,18 +444,6 @@ mod tests { type TestBeaconChainType = Witness, E, MemoryStore, MemoryStore>; - fn build_log(level: slog::Level, enabled: bool) -> slog::Logger { - let decorator = slog_term::TermDecorator::new().build(); - let drain = slog_term::FullFormat::new(decorator).build().fuse(); - let drain = slog_async::Async::new(drain).build().fuse(); - - if enabled { - slog::Logger::root(drain.filter_level(level).fuse(), o!()) - } else { - slog::Logger::root(drain.filter(|_| false).fuse(), o!()) - } - } - #[allow(unused)] struct TestRig { log: slog::Logger, @@ -595,37 +584,16 @@ mod tests { } fn range(log_enabled: bool) -> (TestRig, RangeSync) { - let builder = NullLoggerBuilder; - let db_log = builder.build().expect("should build logger"); - let store = store::HotColdDB::open_ephemeral( - store::StoreConfig::default(), - E::default_spec(), - db_log, - ) - .unwrap(); - - // Initialise a new beacon chain - let chain = Arc::new( - BeaconChainBuilder::new(E) - .custom_spec(test_spec::()) - .store(Arc::new(store)) - .dummy_eth1_backend() - .expect("should build dummy backend") - .slot_clock(SystemTimeSlotClock::new( - types::Slot::new(0), - Duration::from_secs( - SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs(), - ), - Duration::from_millis(SLOT_DURATION_MILLIS), - )) - .build() - .expect("should build"), - ); - let log = build_log(slog::Level::Trace, log_enabled); + // Initialise a new beacon chain + let harness = BeaconChainHarness::>::builder(E::default()) + .default_spec() + .logger(log.clone()) + .deterministic_keypairs(1) + .fresh_ephemeral_store() + .build(); + let chain = harness.chain; + let fake_store = Arc::new(FakeStorage::default()); let (beacon_processor_tx, beacon_processor_rx) = mpsc::channel(10); let range_sync = RangeSync::::new(