diff --git a/beacon_node/beacon_chain/src/eth1_chain.rs b/beacon_node/beacon_chain/src/eth1_chain.rs index 8b6c6b37409..3509af86851 100644 --- a/beacon_node/beacon_chain/src/eth1_chain.rs +++ b/beacon_node/beacon_chain/src/eth1_chain.rs @@ -678,7 +678,7 @@ fn is_candidate_block(block: &Eth1Block, period_start: u64, spec: &ChainSpec) -> #[cfg(test)] mod test { use super::*; - use environment::null_logger; + use logging::test_logger; use types::{DepositData, MinimalEthSpec, Signature}; type E = MinimalEthSpec; @@ -743,7 +743,7 @@ mod test { ..Eth1Config::default() }; - let log = null_logger().unwrap(); + let log = test_logger(); Eth1Chain::new( CachingEth1Backend::new(eth1_config, log, MainnetEthSpec::default_spec()).unwrap(), ) diff --git a/beacon_node/beacon_chain/src/shuffling_cache.rs b/beacon_node/beacon_chain/src/shuffling_cache.rs index 086e1c09498..17fbe094f95 100644 --- a/beacon_node/beacon_chain/src/shuffling_cache.rs +++ b/beacon_node/beacon_chain/src/shuffling_cache.rs @@ -294,7 +294,7 @@ impl BlockShufflingIds { #[cfg(not(debug_assertions))] #[cfg(test)] mod test { - use task_executor::test_utils::null_logger; + use logging::test_logger; use types::*; use crate::test_utils::EphemeralHarnessType; @@ -315,7 +315,7 @@ mod test { previous: Some(shuffling_id(current_epoch - 1)), block_root: Hash256::from_low_u64_le(0), }; - let logger = null_logger().unwrap(); + let logger = test_logger().unwrap(); ShufflingCache::new(TEST_CACHE_SIZE, head_shuffling_ids, logger) } diff --git a/beacon_node/eth1/tests/test.rs b/beacon_node/eth1/tests/test.rs index 505e4a47968..c2df5c260ea 100644 --- a/beacon_node/eth1/tests/test.rs +++ b/beacon_node/eth1/tests/test.rs @@ -1,13 +1,11 @@ #![cfg(test)] -use environment::{Environment, EnvironmentBuilder}; +use environment::{test_logger, Environment, EnvironmentBuilder}; use eth1::{Config, Eth1Endpoint, Service}; use eth1::{DepositCache, DEFAULT_CHAIN_ID}; use eth1_test_rig::{AnvilEth1Instance, Http, Middleware, Provider}; use execution_layer::http::{deposit_methods::*, HttpJsonRpc, Log}; use merkle_proof::verify_merkle_proof; use sensitive_url::SensitiveUrl; -use slog::Logger; -use sloggers::{null::NullLoggerBuilder, Build}; use std::ops::Range; use std::time::Duration; use tree_hash::TreeHash; @@ -15,16 +13,11 @@ use types::{DepositData, EthSpec, Hash256, Keypair, MainnetEthSpec, MinimalEthSp const DEPOSIT_CONTRACT_TREE_DEPTH: usize = 32; -pub fn null_logger() -> Logger { - let log_builder = NullLoggerBuilder; - log_builder.build().expect("should build logger") -} - pub fn new_env() -> Environment { EnvironmentBuilder::minimal() .multi_threaded_tokio_runtime() .expect("should start tokio runtime") - .null_logger() + .test_logger() .expect("should start null logger") .build() .expect("should build env") @@ -104,7 +97,7 @@ mod eth1_cache { #[tokio::test] async fn simple_scenario() { async { - let log = null_logger(); + let log = test_logger(); for follow_distance in 0..3 { let eth1 = new_anvil_instance() @@ -186,7 +179,7 @@ mod eth1_cache { #[tokio::test] async fn big_skip() { async { - let log = null_logger(); + let log = test_logger(); let eth1 = new_anvil_instance() .await @@ -241,7 +234,7 @@ mod eth1_cache { #[tokio::test] async fn pruning() { async { - let log = null_logger(); + let log = test_logger(); let eth1 = new_anvil_instance() .await @@ -293,7 +286,7 @@ mod eth1_cache { #[tokio::test] async fn double_update() { async { - let log = null_logger(); + let log = test_logger(); let n = 16; @@ -346,7 +339,7 @@ mod deposit_tree { #[tokio::test] async fn updating() { async { - let log = null_logger(); + let log = test_logger(); let n = 4; @@ -427,7 +420,7 @@ mod deposit_tree { #[tokio::test] async fn double_update() { async { - let log = null_logger(); + let log = test_logger(); let n = 8; @@ -689,7 +682,7 @@ mod fast { #[tokio::test] async fn deposit_cache_query() { async { - let log = null_logger(); + let log = test_logger(); let eth1 = new_anvil_instance() .await @@ -772,7 +765,7 @@ mod persist { #[tokio::test] async fn test_persist_caches() { async { - let log = null_logger(); + let log = test_logger(); let eth1 = new_anvil_instance() .await diff --git a/beacon_node/execution_layer/src/test_utils/mod.rs b/beacon_node/execution_layer/src/test_utils/mod.rs index 99d264aa7b8..c4d55914c2c 100644 --- a/beacon_node/execution_layer/src/test_utils/mod.rs +++ b/beacon_node/execution_layer/src/test_utils/mod.rs @@ -5,7 +5,7 @@ use crate::engine_api::{ auth::Auth, http::JSONRPC_VERSION, ExecutionBlock, PayloadStatusV1, PayloadStatusV1Status, }; use bytes::Bytes; -use environment::null_logger; +use environment::test_logger; use execution_block_generator::PoWBlock; use handle_rpc::handle_rpc; use parking_lot::{Mutex, RwLock, RwLockWriteGuard}; @@ -114,7 +114,7 @@ impl MockServer { let ctx: Arc> = Arc::new(Context { config: server_config, jwt_key, - log: null_logger().unwrap(), + log: test_logger(), last_echo_request: last_echo_request.clone(), execution_block_generator: RwLock::new(execution_block_generator), previous_request: <_>::default(), diff --git a/beacon_node/genesis/tests/tests.rs b/beacon_node/genesis/tests/tests.rs index f99fcb55bf1..5144dd9adf9 100644 --- a/beacon_node/genesis/tests/tests.rs +++ b/beacon_node/genesis/tests/tests.rs @@ -3,7 +3,7 @@ //! You can start a suitable instance using the `anvil_test_node.sh` script in the `scripts` //! dir in the root of the `lighthouse` repo. #![cfg(test)] -use environment::{Environment, EnvironmentBuilder}; +use environment::{test_logger, Environment, EnvironmentBuilder}; use eth1::{Eth1Endpoint, DEFAULT_CHAIN_ID}; use eth1_test_rig::{AnvilEth1Instance, DelayThenDeposit, Middleware}; use genesis::{Eth1Config, Eth1GenesisService}; @@ -16,7 +16,7 @@ pub fn new_env() -> Environment { EnvironmentBuilder::minimal() .multi_threaded_tokio_runtime() .expect("should start tokio runtime") - .null_logger() + .test_logger() .expect("should start null logger") .build() .expect("should build env") diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index 28eb106e8df..f9b4b03c5de 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -3,7 +3,6 @@ use beacon_chain::{ test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType}, BeaconChain, StateSkipConfig, WhenSlotSkipped, }; -use environment::null_logger; use eth2::{ mixin::{RequestAccept, ResponseForkName, ResponseOptional}, reqwest::RequestBuilder, @@ -22,6 +21,7 @@ use http_api::{ BlockId, StateId, }; use lighthouse_network::{Enr, EnrExt, PeerId}; +use logging::test_logger; use network::NetworkReceivers; use proto_array::ExecutionStatus; use sensitive_url::SensitiveUrl; @@ -229,7 +229,7 @@ impl ApiTester { "precondition: justification" ); - let log = null_logger().unwrap(); + let log = test_logger(); let ApiServer { server, @@ -315,7 +315,7 @@ impl ApiTester { let chain = harness.chain.clone(); - let log = null_logger().unwrap(); + let log = test_logger(); let ApiServer { server, diff --git a/beacon_node/http_metrics/tests/tests.rs b/beacon_node/http_metrics/tests/tests.rs index b88a790afd5..f0c04ffbaf2 100644 --- a/beacon_node/http_metrics/tests/tests.rs +++ b/beacon_node/http_metrics/tests/tests.rs @@ -1,5 +1,5 @@ use beacon_chain::test_utils::EphemeralHarnessType; -use environment::null_logger; +use environment::test_logger; use http_metrics::Config; use reqwest::header::HeaderValue; use reqwest::StatusCode; @@ -13,7 +13,7 @@ type Context = http_metrics::Context>; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn returns_200_ok() { async { - let log = null_logger().unwrap(); + let log = test_logger(); let context = Arc::new(Context { config: Config { diff --git a/beacon_node/tests/test.rs b/beacon_node/tests/test.rs index bbec70330b7..3aac277c2ab 100644 --- a/beacon_node/tests/test.rs +++ b/beacon_node/tests/test.rs @@ -1,6 +1,7 @@ #![cfg(test)] use beacon_chain::StateSkipConfig; +use logging::test_logger; use node_test_rig::{ environment::{Environment, EnvironmentBuilder}, eth2::types::StateId, @@ -25,8 +26,7 @@ fn build_node(env: &mut Environment) -> LocalBeaconNode { #[test] fn http_server_genesis_state() { let mut env = env_builder() - .null_logger() - //.async_logger("debug", None) + .test_logger() .expect("should build env logger") .multi_threaded_tokio_runtime() .expect("should start tokio runtime") diff --git a/lcli/src/transition_blocks.rs b/lcli/src/transition_blocks.rs index 23b0ae26206..1b1d1f41122 100644 --- a/lcli/src/transition_blocks.rs +++ b/lcli/src/transition_blocks.rs @@ -66,12 +66,13 @@ use beacon_chain::{ }; use clap::ArgMatches; use clap_utils::{parse_optional, parse_required}; -use environment::{null_logger, Environment}; +use environment::{test_logger, Environment}; use eth2::{ types::{BlockId, StateId}, BeaconNodeHttpClient, SensitiveUrl, Timeouts, }; use eth2_network_config::Eth2NetworkConfig; +use logging::test_logger; use ssz::Encode; use state_processing::state_advance::complete_state_advance; use state_processing::{ @@ -192,12 +193,9 @@ pub fn run( * Create a `BeaconStore` and `ValidatorPubkeyCache` for block signature verification. */ - let store = HotColdDB::open_ephemeral( - <_>::default(), - spec.clone(), - null_logger().map_err(|e| format!("Failed to create null_logger: {:?}", e))?, - ) - .map_err(|e| format!("Failed to create ephemeral store: {:?}", e))?; + let store = HotColdDB::open_ephemeral(<_>::default(), spec.clone(), test_logger()) + .map_err(|e| format!("Failed to create ephemeral store: {:?}", e))?; + let store = Arc::new(store); debug!("Building pubkey cache (might take some time)"); diff --git a/lighthouse/environment/src/lib.rs b/lighthouse/environment/src/lib.rs index 53915b52d96..de1a6ff36ae 100644 --- a/lighthouse/environment/src/lib.rs +++ b/lighthouse/environment/src/lib.rs @@ -34,7 +34,7 @@ use { #[cfg(not(target_family = "unix"))] use {futures::channel::oneshot, std::cell::RefCell}; -pub use task_executor::test_utils::null_logger; +pub use logging::test_logger; const LOG_CHANNEL_SIZE: usize = 2048; const SSE_LOG_CHANNEL_SIZE: usize = 2048; @@ -185,8 +185,8 @@ impl EnvironmentBuilder { } /// Specifies that all logs should be sent to `null` (i.e., ignored). - pub fn null_logger(mut self) -> Result { - self.log = Some(null_logger()?); + pub fn test_logger(mut self) -> Result { + self.log = Some(test_logger()); Ok(self) } diff --git a/lighthouse/environment/tests/environment_builder.rs b/lighthouse/environment/tests/environment_builder.rs index ad775c99f5e..1ece21a4a48 100644 --- a/lighthouse/environment/tests/environment_builder.rs +++ b/lighthouse/environment/tests/environment_builder.rs @@ -2,6 +2,7 @@ use environment::EnvironmentBuilder; use eth2_network_config::{Eth2NetworkConfig, DEFAULT_HARDCODED_NETWORK}; +use logging::test_logger; use std::path::PathBuf; use types::{Config, MainnetEthSpec}; @@ -9,7 +10,7 @@ fn builder() -> EnvironmentBuilder { EnvironmentBuilder::mainnet() .multi_threaded_tokio_runtime() .expect("should set runtime") - .null_logger() + .test_logger() .expect("should set logger") } diff --git a/testing/web3signer_tests/src/lib.rs b/testing/web3signer_tests/src/lib.rs index dd17ae23b15..da0acb04224 100644 --- a/testing/web3signer_tests/src/lib.rs +++ b/testing/web3signer_tests/src/lib.rs @@ -298,7 +298,7 @@ mod tests { impl ValidatorStoreRig { pub async fn new(validator_definitions: Vec, spec: ChainSpec) -> Self { - let log = environment::null_logger().unwrap(); + let log = logging::test_logger(); let validator_dir = TempDir::new().unwrap(); let validator_definitions = ValidatorDefinitions::from(validator_definitions); diff --git a/validator_client/src/doppelganger_service.rs b/validator_client/src/doppelganger_service.rs index 558b9e199f0..4aef9bad3a5 100644 --- a/validator_client/src/doppelganger_service.rs +++ b/validator_client/src/doppelganger_service.rs @@ -671,8 +671,8 @@ impl DoppelgangerService { #[cfg(test)] mod test { use super::*; - use environment::null_logger; use futures::executor::block_on; + use logging::test_logger; use slot_clock::TestingSlotClock; use std::collections::HashSet; use std::future; @@ -717,7 +717,7 @@ mod test { fn build(self) -> TestScenario { let mut rng = XorShiftRng::from_seed([42; 16]); let slot_clock = TestingSlotClock::new(Slot::new(0), GENESIS_TIME, SLOT_DURATION); - let log = null_logger().unwrap(); + let log = test_logger(); TestScenario { validators: (0..self.validator_count)