From 28f6155b328c142bc8a24ede9d1f95168c9ba711 Mon Sep 17 00:00:00 2001 From: postmeback Date: Tue, 1 Aug 2023 21:18:30 +0530 Subject: [PATCH] Changes Committed --- beacon_node/beacon_chain/src/eth1_chain.rs | 4 +-- .../beacon_chain/src/shuffling_cache.rs | 4 +-- beacon_node/eth1/tests/test.rs | 29 ++++++++----------- .../execution_layer/src/test_utils/mod.rs | 4 +-- beacon_node/genesis/tests/tests.rs | 6 ++-- beacon_node/http_api/tests/tests.rs | 6 ++-- beacon_node/http_metrics/tests/tests.rs | 4 +-- beacon_node/tests/test.rs | 4 +-- lcli/src/transition_blocks.rs | 6 ++-- lighthouse/environment/src/lib.rs | 6 ++-- .../environment/tests/environment_builder.rs | 3 +- testing/web3signer_tests/src/lib.rs | 2 +- validator_client/src/doppelganger_service.rs | 3 +- 13 files changed, 39 insertions(+), 42 deletions(-) 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..b6e46e744ef 100644 --- a/beacon_node/eth1/tests/test.rs +++ b/beacon_node/eth1/tests/test.rs @@ -1,13 +1,13 @@ #![cfg(test)] -use environment::{Environment, EnvironmentBuilder}; +use environment::{Environment, + EnvironmentBuilder, + test_logger}; 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 +15,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 +99,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 +181,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 +236,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 +288,7 @@ mod eth1_cache { #[tokio::test] async fn double_update() { async { - let log = null_logger(); + let log = test_logger(); let n = 16; @@ -346,7 +341,7 @@ mod deposit_tree { #[tokio::test] async fn updating() { async { - let log = null_logger(); + let log = test_logger(); let n = 4; @@ -427,7 +422,7 @@ mod deposit_tree { #[tokio::test] async fn double_update() { async { - let log = null_logger(); + let log = test_logger(); let n = 8; @@ -689,7 +684,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 +767,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 a8e7bab270a..de6a88cd3e3 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}; @@ -115,7 +115,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..bcc85442c39 100644 --- a/beacon_node/genesis/tests/tests.rs +++ b/beacon_node/genesis/tests/tests.rs @@ -3,20 +3,20 @@ //! 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::{Environment, EnvironmentBuilder, test_logger}; use eth1::{Eth1Endpoint, DEFAULT_CHAIN_ID}; use eth1_test_rig::{AnvilEth1Instance, DelayThenDeposit, Middleware}; -use genesis::{Eth1Config, Eth1GenesisService}; use sensitive_url::SensitiveUrl; use state_processing::is_valid_genesis_state; use std::time::Duration; +use genesis::{Eth1Config, Eth1GenesisService}; use types::{test_utils::generate_deterministic_keypair, Hash256, MinimalEthSpec}; 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 741ee1ffc06..ad441c19746 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -3,7 +3,7 @@ use beacon_chain::{ test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType}, BeaconChain, StateSkipConfig, WhenSlotSkipped, MAXIMUM_GOSSIP_CLOCK_DISPARITY, }; -use environment::null_logger; +use logging::test_logger; use eth2::{ mixin::{RequestAccept, ResponseForkName, ResponseOptional}, reqwest::RequestBuilder, @@ -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 34a45607610..9119a25035a 100644 --- a/lcli/src/transition_blocks.rs +++ b/lcli/src/transition_blocks.rs @@ -66,7 +66,8 @@ use beacon_chain::{ }; use clap::ArgMatches; use clap_utils::{parse_optional, parse_required}; -use environment::{null_logger, Environment}; +use environment::{Environment, test_logger}; +use logging::test_logger; use eth2::{ types::{BlockId, StateId}, BeaconNodeHttpClient, SensitiveUrl, Timeouts, @@ -189,9 +190,10 @@ pub fn run(env: Environment, matches: &ArgMatches) -> Result<(), let store = HotColdDB::open_ephemeral( <_>::default(), spec.clone(), - null_logger().map_err(|e| format!("Failed to create null_logger: {:?}", e))?, + 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..d1ad9f6c370 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..c2267a0854f 100644 --- a/lighthouse/environment/tests/environment_builder.rs +++ b/lighthouse/environment/tests/environment_builder.rs @@ -1,5 +1,6 @@ #![cfg(test)] +use logging::test_logger; use environment::EnvironmentBuilder; use eth2_network_config::{Eth2NetworkConfig, DEFAULT_HARDCODED_NETWORK}; use std::path::PathBuf; @@ -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 57c4a742c13..4aef9bad3a5 100644 --- a/validator_client/src/doppelganger_service.rs +++ b/validator_client/src/doppelganger_service.rs @@ -671,7 +671,6 @@ 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; @@ -718,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 = test_logger().unwrap(); + let log = test_logger(); TestScenario { validators: (0..self.validator_count)