diff --git a/Cargo.lock b/Cargo.lock index 818b6adc55..9afb3635f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -796,7 +796,6 @@ dependencies = [ "int_to_bytes", "itertools 0.10.5", "kzg", - "lazy_static", "lighthouse_metrics", "lighthouse_version", "logging", @@ -872,7 +871,6 @@ dependencies = [ "fnv", "futures", "itertools 0.10.5", - "lazy_static", "lighthouse_metrics", "lighthouse_network", "logging", @@ -1390,7 +1388,6 @@ dependencies = [ "genesis", "http_api", "http_metrics", - "lazy_static", "lighthouse_metrics", "lighthouse_network", "monitoring_api", @@ -2413,7 +2410,6 @@ dependencies = [ "ethereum_ssz_derive", "execution_layer", "futures", - "lazy_static", "lighthouse_metrics", "merkle_proof", "parking_lot 0.12.3", @@ -2492,7 +2488,6 @@ dependencies = [ "bls", "ethereum_hashing", "hex", - "lazy_static", "num-bigint", "serde", "serde_yaml", @@ -2913,7 +2908,6 @@ dependencies = [ "jsonwebtoken", "keccak-hash", "kzg", - "lazy_static", "lighthouse_metrics", "lighthouse_version", "lru", @@ -3783,7 +3777,6 @@ dependencies = [ "futures", "genesis", "hex", - "lazy_static", "lighthouse_metrics", "lighthouse_network", "lighthouse_version", @@ -4965,7 +4958,6 @@ dependencies = [ "eth2_network_config", "ethereum_hashing", "futures", - "lazy_static", "lighthouse_metrics", "lighthouse_network", "lighthouse_version", @@ -5013,7 +5005,6 @@ dependencies = [ "gossipsub", "hex", "itertools 0.10.5", - "lazy_static", "libp2p", "libp2p-mplex", "lighthouse_metrics", @@ -5126,7 +5117,6 @@ name = "logging" version = "0.2.0" dependencies = [ "chrono", - "lazy_static", "lighthouse_metrics", "parking_lot 0.12.3", "serde", @@ -5184,7 +5174,6 @@ version = "0.1.0" dependencies = [ "jemalloc-ctl", "jemallocator", - "lazy_static", "libc", "lighthouse_metrics", "parking_lot 0.12.3", @@ -5271,7 +5260,6 @@ version = "0.2.0" dependencies = [ "ethereum-types 0.14.1", "ethereum_hashing", - "lazy_static", "quickcheck", "quickcheck_macros", "safe_arith", @@ -5398,7 +5386,6 @@ name = "monitoring_api" version = "0.1.0" dependencies = [ "eth2", - "lazy_static", "lighthouse_metrics", "lighthouse_version", "regex", @@ -5576,7 +5563,6 @@ dependencies = [ "hex", "igd-next", "itertools 0.10.5", - "lazy_static", "lighthouse_metrics", "lighthouse_network", "logging", @@ -5881,7 +5867,6 @@ dependencies = [ "ethereum_ssz", "ethereum_ssz_derive", "itertools 0.10.5", - "lazy_static", "lighthouse_metrics", "maplit", "parking_lot 0.12.3", @@ -7698,7 +7683,6 @@ dependencies = [ "ethereum_ssz_derive", "filesystem", "flate2", - "lazy_static", "libmdbx", "lighthouse_metrics", "lmdb-rkv", @@ -7745,7 +7729,6 @@ dependencies = [ "arbitrary", "ethereum_serde_utils", "filesystem", - "lazy_static", "r2d2", "r2d2_sqlite", "rayon", @@ -7862,7 +7845,6 @@ dependencies = [ name = "slot_clock" version = "0.2.0" dependencies = [ - "lazy_static", "lighthouse_metrics", "parking_lot 0.12.3", "types", @@ -7991,7 +7973,6 @@ dependencies = [ "int_to_bytes", "integer-sqrt", "itertools 0.10.5", - "lazy_static", "lighthouse_metrics", "merkle_proof", "rand", @@ -8011,7 +7992,6 @@ version = "0.1.0" dependencies = [ "beacon_chain", "ethereum_ssz", - "lazy_static", "state_processing", "tokio", "types", @@ -8033,7 +8013,6 @@ dependencies = [ "ethereum_ssz", "ethereum_ssz_derive", "itertools 0.10.5", - "lazy_static", "leveldb", "lighthouse_metrics", "lru", @@ -8244,7 +8223,6 @@ version = "0.1.0" dependencies = [ "async-channel", "futures", - "lazy_static", "lighthouse_metrics", "logging", "slog", @@ -8856,7 +8834,6 @@ dependencies = [ "int_to_bytes", "itertools 0.10.5", "kzg", - "lazy_static", "log", "maplit", "merkle_proof", @@ -9022,7 +8999,6 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" name = "unused_port" version = "0.1.0" dependencies = [ - "lazy_static", "lru_cache", "parking_lot 0.12.3", ] @@ -9076,7 +9052,6 @@ dependencies = [ "hex", "hyper 1.4.1", "itertools 0.10.5", - "lazy_static", "libsecp256k1", "lighthouse_metrics", "lighthouse_version", @@ -9246,7 +9221,6 @@ dependencies = [ "bytes", "eth2", "headers", - "lazy_static", "lighthouse_metrics", "safe_arith", "serde", @@ -9428,7 +9402,6 @@ dependencies = [ "eth2_keystore", "eth2_network_config", "futures", - "lazy_static", "parking_lot 0.12.3", "reqwest", "serde", diff --git a/Cargo.toml b/Cargo.toml index b2957842d5..cf3fd0ab04 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -132,7 +132,6 @@ hex = "0.4" hashlink = "0.9.0" hyper = "1" itertools = "0.10" -lazy_static = "1" libsecp256k1 = "0.7" log = "0.4" lru = "0.12" diff --git a/Dockerfile b/Dockerfile index ff7f14d534..0f334e2ac8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.78.0-bullseye AS builder +FROM rust:1.80.0-bullseye AS builder RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev COPY . lighthouse ARG FEATURES diff --git a/beacon_node/beacon_chain/Cargo.toml b/beacon_node/beacon_chain/Cargo.toml index 32a1056c10..cf1c6be33f 100644 --- a/beacon_node/beacon_chain/Cargo.toml +++ b/beacon_node/beacon_chain/Cargo.toml @@ -37,7 +37,6 @@ hex = { workspace = true } int_to_bytes = { workspace = true } itertools = { workspace = true } kzg = { workspace = true } -lazy_static = { workspace = true } lighthouse_metrics = { workspace = true } lighthouse_version = { workspace = true } logging = { workspace = true } diff --git a/beacon_node/beacon_chain/src/beacon_block_streamer.rs b/beacon_node/beacon_chain/src/beacon_block_streamer.rs index f0a68b6be5..d63a3ee7ea 100644 --- a/beacon_node/beacon_chain/src/beacon_block_streamer.rs +++ b/beacon_node/beacon_chain/src/beacon_block_streamer.rs @@ -712,16 +712,16 @@ mod tests { use crate::test_utils::{test_spec, BeaconChainHarness, EphemeralHarnessType}; use execution_layer::test_utils::{Block, DEFAULT_ENGINE_CAPABILITIES}; use execution_layer::EngineCapabilities; - use lazy_static::lazy_static; + use std::sync::LazyLock; use std::time::Duration; use tokio::sync::mpsc; use types::{ChainSpec, Epoch, EthSpec, Hash256, Keypair, MinimalEthSpec, Slot}; const VALIDATOR_COUNT: usize = 48; - lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); - } + + /// A cached set of keys. + static KEYPAIRS: LazyLock> = + LazyLock::new(|| types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT)); fn get_harness( validator_count: usize, diff --git a/beacon_node/beacon_chain/src/graffiti_calculator.rs b/beacon_node/beacon_chain/src/graffiti_calculator.rs index 599c99dc2d..42a1aa1a0b 100644 --- a/beacon_node/beacon_chain/src/graffiti_calculator.rs +++ b/beacon_node/beacon_chain/src/graffiti_calculator.rs @@ -241,16 +241,15 @@ mod tests { use crate::ChainConfig; use execution_layer::test_utils::{DEFAULT_CLIENT_VERSION, DEFAULT_ENGINE_CAPABILITIES}; use execution_layer::EngineCapabilities; - use lazy_static::lazy_static; use slog::info; + use std::sync::LazyLock; use std::time::Duration; use types::{ChainSpec, Graffiti, Keypair, MinimalEthSpec, GRAFFITI_BYTES_LEN}; const VALIDATOR_COUNT: usize = 48; - lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); - } + /// A cached set of keys. + static KEYPAIRS: LazyLock> = + LazyLock::new(|| types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT)); fn get_harness( validator_count: usize, diff --git a/beacon_node/beacon_chain/src/metrics.rs b/beacon_node/beacon_chain/src/metrics.rs index 4ca511370d..b8969b31f1 100644 --- a/beacon_node/beacon_chain/src/metrics.rs +++ b/beacon_node/beacon_chain/src/metrics.rs @@ -1,9 +1,9 @@ use crate::observed_attesters::SlotSubcommitteeIndex; use crate::types::consts::altair::SYNC_COMMITTEE_SUBNET_COUNT; use crate::{BeaconChain, BeaconChainError, BeaconChainTypes}; -use lazy_static::lazy_static; pub use lighthouse_metrics::*; use slot_clock::SlotClock; +use std::sync::LazyLock; use types::{BeaconState, Epoch, EthSpec, Hash256, Slot}; // Attestation simulator metrics @@ -20,1182 +20,1839 @@ pub const VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_HIT_TOTAL: &st pub const VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_MISS_TOTAL: &str = "validator_monitor_attestation_simulator_source_attester_miss_total"; -lazy_static! { - /* - * Block Processing - */ - pub static ref BLOCK_PROCESSING_REQUESTS: Result = try_create_int_counter( +/* + * Block Processing + */ +pub static BLOCK_PROCESSING_REQUESTS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "beacon_block_processing_requests_total", - "Count of blocks submitted for processing" - ); - pub static ref BLOCK_PROCESSING_SUCCESSES: Result = try_create_int_counter( + "Count of blocks submitted for processing", + ) +}); +pub static BLOCK_PROCESSING_SUCCESSES: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "beacon_block_processing_successes_total", - "Count of blocks processed without error" - ); - // Keeping the existing "snapshot_cache" metric name as it would break existing dashboards - pub static ref BLOCK_PROCESSING_SNAPSHOT_CACHE_SIZE: Result = try_create_int_gauge( + "Count of blocks processed without error", + ) +}); +// Keeping the existing "snapshot_cache" metric name as it would break existing dashboards +pub static BLOCK_PROCESSING_SNAPSHOT_CACHE_SIZE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "beacon_block_processing_snapshot_cache_size", - "Count snapshots in the snapshot cache" - ); - pub static ref BLOCK_PROCESSING_TIMES: Result = - try_create_histogram("beacon_block_processing_seconds", "Full runtime of block processing"); - pub static ref BLOCK_PROCESSING_BLOCK_ROOT: Result = try_create_histogram( + "Count snapshots in the snapshot cache", + ) +}); +pub static BLOCK_PROCESSING_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( + "beacon_block_processing_seconds", + "Full runtime of block processing", + ) +}); +pub static BLOCK_PROCESSING_BLOCK_ROOT: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_processing_block_root_seconds", - "Time spent calculating the block root when processing a block." - ); - pub static ref BLOCK_HEADER_PROCESSING_BLOCK_ROOT: Result = try_create_histogram( + "Time spent calculating the block root when processing a block.", + ) +}); +pub static BLOCK_HEADER_PROCESSING_BLOCK_ROOT: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_header_processing_block_root_seconds", - "Time spent calculating the block root for a beacon block header." - ); - pub static ref BLOCK_PROCESSING_BLOB_ROOT: Result = try_create_histogram( + "Time spent calculating the block root for a beacon block header.", + ) +}); +pub static BLOCK_PROCESSING_BLOB_ROOT: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_processing_blob_root_seconds", - "Time spent calculating the blob root when processing a block." - ); - pub static ref BLOCK_PROCESSING_DB_READ: Result = try_create_histogram( + "Time spent calculating the blob root when processing a block.", + ) +}); +pub static BLOCK_PROCESSING_DB_READ: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_processing_db_read_seconds", - "Time spent loading block and state from DB for block processing" - ); - pub static ref BLOCK_PROCESSING_CATCHUP_STATE: Result = try_create_histogram( + "Time spent loading block and state from DB for block processing", + ) +}); +pub static BLOCK_PROCESSING_CATCHUP_STATE: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_processing_catch_up_state_seconds", - "Time spent skipping slots on a state before processing a block." - ); - pub static ref BLOCK_PROCESSING_COMMITTEE: Result = try_create_histogram( + "Time spent skipping slots on a state before processing a block.", + ) +}); +pub static BLOCK_PROCESSING_COMMITTEE: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_processing_committee_building_seconds", - "Time spent building/obtaining committees for block processing." - ); - pub static ref BLOCK_PROCESSING_SIGNATURE: Result = try_create_histogram( + "Time spent building/obtaining committees for block processing.", + ) +}); +pub static BLOCK_PROCESSING_SIGNATURE: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_processing_signature_seconds", - "Time spent doing signature verification for a block." - ); - pub static ref BLOCK_PROCESSING_CORE: Result = try_create_histogram( + "Time spent doing signature verification for a block.", + ) +}); +pub static BLOCK_PROCESSING_CORE: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_processing_core_seconds", - "Time spent doing the core per_block_processing state processing." - ); - pub static ref BLOCK_PROCESSING_STATE_ROOT: Result = try_create_histogram( + "Time spent doing the core per_block_processing state processing.", + ) +}); +pub static BLOCK_PROCESSING_STATE_ROOT: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_processing_state_root_seconds", - "Time spent calculating the state root when processing a block." - ); - pub static ref BLOCK_PROCESSING_POST_EXEC_PROCESSING: Result = try_create_histogram_with_buckets( - "beacon_block_processing_post_exec_pre_attestable_seconds", - "Time between finishing execution processing and the block becoming attestable", - linear_buckets(5e-3, 5e-3, 10) - ); - pub static ref BLOCK_PROCESSING_DB_WRITE: Result = try_create_histogram( + "Time spent calculating the state root when processing a block.", + ) +}); +pub static BLOCK_PROCESSING_POST_EXEC_PROCESSING: LazyLock> = + LazyLock::new(|| { + try_create_histogram_with_buckets( + "beacon_block_processing_post_exec_pre_attestable_seconds", + "Time between finishing execution processing and the block becoming attestable", + linear_buckets(5e-3, 5e-3, 10), + ) + }); +pub static BLOCK_PROCESSING_DB_WRITE: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_processing_db_write_seconds", - "Time spent writing a newly processed block and state to DB" - ); - pub static ref BLOCK_PROCESSING_ATTESTATION_OBSERVATION: Result = try_create_histogram( - "beacon_block_processing_attestation_observation_seconds", - "Time spent hashing and remembering all the attestations in the block" - ); - pub static ref BLOCK_PROCESSING_FORK_CHOICE: Result = try_create_histogram_with_buckets( + "Time spent writing a newly processed block and state to DB", + ) +}); +pub static BLOCK_PROCESSING_ATTESTATION_OBSERVATION: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_block_processing_attestation_observation_seconds", + "Time spent hashing and remembering all the attestations in the block", + ) + }); +pub static BLOCK_PROCESSING_FORK_CHOICE: LazyLock> = LazyLock::new(|| { + try_create_histogram_with_buckets( "beacon_block_processing_fork_choice_seconds", "Time spent running fork choice's `get_head` during block import", - exponential_buckets(1e-3, 2.0, 8) - ); - pub static ref BLOCK_PROCESSING_PUBKEY_CACHE_LOCK: Result = try_create_histogram( + exponential_buckets(1e-3, 2.0, 8), + ) +}); +pub static BLOCK_PROCESSING_PUBKEY_CACHE_LOCK: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_processing_pubkey_cache_lock_seconds", "Time spent waiting or holding the pubkey cache write lock", - ); - pub static ref BLOCK_SYNC_AGGREGATE_SET_BITS: Result = try_create_int_gauge( + ) +}); +pub static BLOCK_SYNC_AGGREGATE_SET_BITS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "block_sync_aggregate_set_bits", - "The number of true bits in the last sync aggregate in a block" - ); + "The number of true bits in the last sync aggregate in a block", + ) +}); - /* - * Block Production - */ - pub static ref BLOCK_PRODUCTION_REQUESTS: Result = try_create_int_counter( +/* + * Block Production + */ +pub static BLOCK_PRODUCTION_REQUESTS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "beacon_block_production_requests_total", - "Count of all block production requests" - ); - pub static ref BLOCK_PRODUCTION_SUCCESSES: Result = try_create_int_counter( + "Count of all block production requests", + ) +}); +pub static BLOCK_PRODUCTION_SUCCESSES: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "beacon_block_production_successes_total", - "Count of blocks successfully produced." - ); - pub static ref BLOCK_PRODUCTION_TIMES: Result = - try_create_histogram("beacon_block_production_seconds", "Full runtime of block production"); - pub static ref BLOCK_PRODUCTION_FORK_CHOICE_TIMES: Result = try_create_histogram( + "Count of blocks successfully produced.", + ) +}); +pub static BLOCK_PRODUCTION_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( + "beacon_block_production_seconds", + "Full runtime of block production", + ) +}); +pub static BLOCK_PRODUCTION_FORK_CHOICE_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_production_fork_choice_seconds", - "Time taken to run fork choice before block production" - ); - pub static ref BLOCK_PRODUCTION_GET_PROPOSER_HEAD_TIMES: Result = try_create_histogram_with_buckets( - "beacon_block_production_get_proposer_head_times", - "Time taken for fork choice to compute the proposer head before block production", - exponential_buckets(1e-3, 2.0, 8) - ); - pub static ref BLOCK_PRODUCTION_STATE_LOAD_TIMES: Result = try_create_histogram( + "Time taken to run fork choice before block production", + ) +}); +pub static BLOCK_PRODUCTION_GET_PROPOSER_HEAD_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram_with_buckets( + "beacon_block_production_get_proposer_head_times", + "Time taken for fork choice to compute the proposer head before block production", + exponential_buckets(1e-3, 2.0, 8), + ) + }); +pub static BLOCK_PRODUCTION_STATE_LOAD_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_production_state_load_seconds", - "Time taken to load the base state for block production" - ); - pub static ref BLOCK_PRODUCTION_SLOT_PROCESS_TIMES: Result = try_create_histogram( + "Time taken to load the base state for block production", + ) +}); +pub static BLOCK_PRODUCTION_SLOT_PROCESS_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_production_slot_process_seconds", - "Time taken to advance the state to the block production slot" - ); - pub static ref BLOCK_PRODUCTION_UNAGGREGATED_TIMES: Result = try_create_histogram( + "Time taken to advance the state to the block production slot", + ) +}); +pub static BLOCK_PRODUCTION_UNAGGREGATED_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_production_unaggregated_seconds", - "Time taken to import the naive aggregation pool for block production" - ); - pub static ref BLOCK_PRODUCTION_ATTESTATION_TIMES: Result = try_create_histogram( + "Time taken to import the naive aggregation pool for block production", + ) +}); +pub static BLOCK_PRODUCTION_ATTESTATION_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_production_attestation_seconds", - "Time taken to pack attestations into a block" - ); - pub static ref BLOCK_PRODUCTION_PROCESS_TIMES: Result = try_create_histogram( + "Time taken to pack attestations into a block", + ) +}); +pub static BLOCK_PRODUCTION_PROCESS_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_production_process_seconds", - "Time taken to process the block produced" - ); - pub static ref BLOCK_PRODUCTION_STATE_ROOT_TIMES: Result = try_create_histogram( + "Time taken to process the block produced", + ) +}); +pub static BLOCK_PRODUCTION_STATE_ROOT_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_block_production_state_root_seconds", - "Time taken to calculate the block's state root" - ); + "Time taken to calculate the block's state root", + ) +}); - /* - * Block Statistics - */ - pub static ref OPERATIONS_PER_BLOCK_ATTESTATION: Result = try_create_histogram_with_buckets( +/* + * Block Statistics + */ +pub static OPERATIONS_PER_BLOCK_ATTESTATION: LazyLock> = LazyLock::new(|| { + try_create_histogram_with_buckets( "beacon_operations_per_block_attestation_total", "Number of attestations in a block", // Full block is 128. - Ok(vec![0_f64, 1_f64, 3_f64, 15_f64, 31_f64, 63_f64, 127_f64, 255_f64]) - ); + Ok(vec![ + 0_f64, 1_f64, 3_f64, 15_f64, 31_f64, 63_f64, 127_f64, 255_f64, + ]), + ) +}); - pub static ref BLOCK_SIZE: Result = try_create_histogram_with_buckets( +pub static BLOCK_SIZE: LazyLock> = LazyLock::new(|| { + try_create_histogram_with_buckets( "beacon_block_total_size", "Size of a signed beacon block", - linear_buckets(5120_f64,5120_f64,10) - ); + linear_buckets(5120_f64, 5120_f64, 10), + ) +}); - /* - * Unaggregated Attestation Verification - */ - pub static ref UNAGGREGATED_ATTESTATION_PROCESSING_REQUESTS: Result = try_create_int_counter( - "beacon_unaggregated_attestation_processing_requests_total", - "Count of all unaggregated attestations submitted for processing" - ); - pub static ref UNAGGREGATED_ATTESTATION_PROCESSING_SUCCESSES: Result = try_create_int_counter( - "beacon_unaggregated_attestation_processing_successes_total", - "Number of unaggregated attestations verified for gossip" - ); - pub static ref UNAGGREGATED_ATTESTATION_GOSSIP_VERIFICATION_TIMES: Result = try_create_histogram( - "beacon_unaggregated_attestation_gossip_verification_seconds", - "Full runtime of aggregated attestation gossip verification" - ); +/* + * Unaggregated Attestation Verification + */ +pub static UNAGGREGATED_ATTESTATION_PROCESSING_REQUESTS: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_unaggregated_attestation_processing_requests_total", + "Count of all unaggregated attestations submitted for processing", + ) + }); +pub static UNAGGREGATED_ATTESTATION_PROCESSING_SUCCESSES: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_unaggregated_attestation_processing_successes_total", + "Number of unaggregated attestations verified for gossip", + ) + }); +pub static UNAGGREGATED_ATTESTATION_GOSSIP_VERIFICATION_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_unaggregated_attestation_gossip_verification_seconds", + "Full runtime of aggregated attestation gossip verification", + ) + }); - /* - * Aggregated Attestation Verification - */ - pub static ref AGGREGATED_ATTESTATION_PROCESSING_REQUESTS: Result = try_create_int_counter( - "beacon_aggregated_attestation_processing_requests_total", - "Count of all aggregated attestations submitted for processing" - ); - pub static ref AGGREGATED_ATTESTATION_PROCESSING_SUCCESSES: Result = try_create_int_counter( - "beacon_aggregated_attestation_processing_successes_total", - "Number of aggregated attestations verified for gossip" - ); - pub static ref AGGREGATED_ATTESTATION_GOSSIP_VERIFICATION_TIMES: Result = try_create_histogram( - "beacon_aggregated_attestation_gossip_verification_seconds", - "Full runtime of aggregated attestation gossip verification" - ); +/* + * Aggregated Attestation Verification + */ +pub static AGGREGATED_ATTESTATION_PROCESSING_REQUESTS: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_aggregated_attestation_processing_requests_total", + "Count of all aggregated attestations submitted for processing", + ) + }); +pub static AGGREGATED_ATTESTATION_PROCESSING_SUCCESSES: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_aggregated_attestation_processing_successes_total", + "Number of aggregated attestations verified for gossip", + ) + }); +pub static AGGREGATED_ATTESTATION_GOSSIP_VERIFICATION_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_aggregated_attestation_gossip_verification_seconds", + "Full runtime of aggregated attestation gossip verification", + ) + }); - /* - * General Attestation Processing - */ - pub static ref ATTESTATION_PROCESSING_APPLY_TO_AGG_POOL: Result = try_create_histogram( - "beacon_attestation_processing_apply_to_agg_pool", - "Time spent applying an attestation to the naive aggregation pool" - ); - pub static ref ATTESTATION_PROCESSING_AGG_POOL_PRUNE: Result = try_create_histogram( - "beacon_attestation_processing_agg_pool_prune", - "Time spent for the agg pool to prune" - ); - pub static ref ATTESTATION_PROCESSING_AGG_POOL_INSERT: Result = try_create_histogram( - "beacon_attestation_processing_agg_pool_insert", - "Time spent for the outer pool.insert() function of agg pool" - ); - pub static ref ATTESTATION_PROCESSING_AGG_POOL_CORE_INSERT: Result = try_create_histogram( - "beacon_attestation_processing_agg_pool_core_insert", - "Time spent for the core map.insert() function of agg pool" - ); - pub static ref ATTESTATION_PROCESSING_AGG_POOL_AGGREGATION: Result = try_create_histogram( - "beacon_attestation_processing_agg_pool_aggregation", - "Time spent doing signature aggregation when adding to the agg poll" - ); - pub static ref ATTESTATION_PROCESSING_AGG_POOL_CREATE_MAP: Result = try_create_histogram( - "beacon_attestation_processing_agg_pool_create_map", - "Time spent for creating a map for a new slot" - ); - pub static ref ATTESTATION_PROCESSING_APPLY_TO_OP_POOL: Result = try_create_histogram( - "beacon_attestation_processing_apply_to_op_pool", - "Time spent applying an attestation to the block inclusion pool" - ); +/* + * General Attestation Processing + */ +pub static ATTESTATION_PROCESSING_APPLY_TO_AGG_POOL: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_apply_to_agg_pool", + "Time spent applying an attestation to the naive aggregation pool", + ) + }); +pub static ATTESTATION_PROCESSING_AGG_POOL_PRUNE: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_agg_pool_prune", + "Time spent for the agg pool to prune", + ) + }); +pub static ATTESTATION_PROCESSING_AGG_POOL_INSERT: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_agg_pool_insert", + "Time spent for the outer pool.insert() function of agg pool", + ) + }); +pub static ATTESTATION_PROCESSING_AGG_POOL_CORE_INSERT: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_agg_pool_core_insert", + "Time spent for the core map.insert() function of agg pool", + ) + }); +pub static ATTESTATION_PROCESSING_AGG_POOL_AGGREGATION: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_agg_pool_aggregation", + "Time spent doing signature aggregation when adding to the agg poll", + ) + }); +pub static ATTESTATION_PROCESSING_AGG_POOL_CREATE_MAP: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_agg_pool_create_map", + "Time spent for creating a map for a new slot", + ) + }); +pub static ATTESTATION_PROCESSING_APPLY_TO_OP_POOL: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_apply_to_op_pool", + "Time spent applying an attestation to the block inclusion pool", + ) + }); - /* - * Attestation Processing - */ - pub static ref ATTESTATION_PROCESSING_SHUFFLING_CACHE_WAIT_TIMES: Result = try_create_histogram( - "beacon_attestation_processing_shuffling_cache_wait_seconds", - "Time spent on waiting for the shuffling cache lock during attestation processing" - ); - pub static ref ATTESTATION_PROCESSING_COMMITTEE_BUILDING_TIMES: Result = try_create_histogram( - "beacon_attestation_processing_committee_building_seconds", - "Time spent on building committees during attestation processing" - ); - pub static ref ATTESTATION_PROCESSING_STATE_READ_TIMES: Result = try_create_histogram( - "beacon_attestation_processing_state_read_seconds", - "Time spent on reading the state during attestation processing" - ); - pub static ref ATTESTATION_PROCESSING_STATE_SKIP_TIMES: Result = try_create_histogram( - "beacon_attestation_processing_state_skip_seconds", - "Time spent on reading the state during attestation processing" - ); - pub static ref ATTESTATION_PROCESSING_SIGNATURE_SETUP_TIMES: Result = try_create_histogram( - "beacon_attestation_processing_signature_setup_seconds", - "Time spent on setting up for the signature verification of attestation processing" - ); - pub static ref ATTESTATION_PROCESSING_SIGNATURE_TIMES: Result = try_create_histogram( - "beacon_attestation_processing_signature_seconds", - "Time spent on the signature verification of attestation processing" - ); +/* + * Attestation Processing + */ +pub static ATTESTATION_PROCESSING_SHUFFLING_CACHE_WAIT_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_shuffling_cache_wait_seconds", + "Time spent on waiting for the shuffling cache lock during attestation processing", + ) + }); +pub static ATTESTATION_PROCESSING_COMMITTEE_BUILDING_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_committee_building_seconds", + "Time spent on building committees during attestation processing", + ) + }); +pub static ATTESTATION_PROCESSING_STATE_READ_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_state_read_seconds", + "Time spent on reading the state during attestation processing", + ) + }); +pub static ATTESTATION_PROCESSING_STATE_SKIP_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_state_skip_seconds", + "Time spent on reading the state during attestation processing", + ) + }); +pub static ATTESTATION_PROCESSING_SIGNATURE_SETUP_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_signature_setup_seconds", + "Time spent on setting up for the signature verification of attestation processing", + ) + }); +pub static ATTESTATION_PROCESSING_SIGNATURE_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_signature_seconds", + "Time spent on the signature verification of attestation processing", + ) + }); - /* - * Batch Attestation Processing - */ - pub static ref ATTESTATION_PROCESSING_BATCH_AGG_SIGNATURE_SETUP_TIMES: Result = try_create_histogram( - "beacon_attestation_processing_batch_agg_signature_setup_times", - "Time spent on setting up for the signature verification of batch aggregate processing" - ); - pub static ref ATTESTATION_PROCESSING_BATCH_AGG_SIGNATURE_TIMES: Result = try_create_histogram( - "beacon_attestation_processing_batch_agg_signature_times", - "Time spent on the signature verification of batch aggregate attestation processing" - ); - pub static ref ATTESTATION_PROCESSING_BATCH_UNAGG_SIGNATURE_SETUP_TIMES: Result = try_create_histogram( +/* + * Batch Attestation Processing + */ +pub static ATTESTATION_PROCESSING_BATCH_AGG_SIGNATURE_SETUP_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_batch_agg_signature_setup_times", + "Time spent on setting up for the signature verification of batch aggregate processing", + ) + }); +pub static ATTESTATION_PROCESSING_BATCH_AGG_SIGNATURE_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_batch_agg_signature_times", + "Time spent on the signature verification of batch aggregate attestation processing", + ) + }); +pub static ATTESTATION_PROCESSING_BATCH_UNAGG_SIGNATURE_SETUP_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( "beacon_attestation_processing_batch_unagg_signature_setup_times", "Time spent on setting up for the signature verification of batch unaggregate processing" - ); - pub static ref ATTESTATION_PROCESSING_BATCH_UNAGG_SIGNATURE_TIMES: Result = try_create_histogram( - "beacon_attestation_processing_batch_unagg_signature_times", - "Time spent on the signature verification of batch unaggregate attestation processing" - ); + ) + }); +pub static ATTESTATION_PROCESSING_BATCH_UNAGG_SIGNATURE_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_attestation_processing_batch_unagg_signature_times", + "Time spent on the signature verification of batch unaggregate attestation processing", + ) + }); - /* - * Shuffling cache - */ - pub static ref SHUFFLING_CACHE_HITS: Result = - try_create_int_counter("beacon_shuffling_cache_hits_total", "Count of times shuffling cache fulfils request"); - pub static ref SHUFFLING_CACHE_MISSES: Result = - try_create_int_counter("beacon_shuffling_cache_misses_total", "Count of times shuffling cache fulfils request"); - pub static ref SHUFFLING_CACHE_PROMISE_HITS: Result = - try_create_int_counter("beacon_shuffling_cache_promise_hits_total", "Count of times shuffling cache returns a promise to future shuffling"); - pub static ref SHUFFLING_CACHE_PROMISE_FAILS: Result = - try_create_int_counter("beacon_shuffling_cache_promise_fails_total", "Count of times shuffling cache detects a failed promise"); +/* + * Shuffling cache + */ +pub static SHUFFLING_CACHE_HITS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( + "beacon_shuffling_cache_hits_total", + "Count of times shuffling cache fulfils request", + ) +}); +pub static SHUFFLING_CACHE_MISSES: LazyLock> = LazyLock::new(|| { + try_create_int_counter( + "beacon_shuffling_cache_misses_total", + "Count of times shuffling cache fulfils request", + ) +}); +pub static SHUFFLING_CACHE_PROMISE_HITS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( + "beacon_shuffling_cache_promise_hits_total", + "Count of times shuffling cache returns a promise to future shuffling", + ) +}); +pub static SHUFFLING_CACHE_PROMISE_FAILS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( + "beacon_shuffling_cache_promise_fails_total", + "Count of times shuffling cache detects a failed promise", + ) +}); - /* - * Early attester cache - */ - pub static ref BEACON_EARLY_ATTESTER_CACHE_HITS: Result = try_create_int_counter( +/* + * Early attester cache + */ +pub static BEACON_EARLY_ATTESTER_CACHE_HITS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "beacon_early_attester_cache_hits", - "Count of times the early attester cache returns an attestation" - ); + "Count of times the early attester cache returns an attestation", + ) +}); - pub static ref BEACON_REQRESP_PRE_IMPORT_CACHE_SIZE: Result = try_create_int_gauge( +pub static BEACON_REQRESP_PRE_IMPORT_CACHE_SIZE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "beacon_reqresp_pre_import_cache_size", - "Current count of items of the reqresp pre import cache" - ); - pub static ref BEACON_REQRESP_PRE_IMPORT_CACHE_HITS: Result = try_create_int_counter( - "beacon_reqresp_pre_import_cache_hits", - "Count of times the reqresp pre import cache returns an item" - ); -} + "Current count of items of the reqresp pre import cache", + ) +}); +pub static BEACON_REQRESP_PRE_IMPORT_CACHE_HITS: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_reqresp_pre_import_cache_hits", + "Count of times the reqresp pre import cache returns an item", + ) + }); -// Second lazy-static block is used to account for macro recursion limit. -lazy_static! { - - /* - * Attestation Production - */ - pub static ref ATTESTATION_PRODUCTION_SECONDS: Result = try_create_histogram( +/* + * Attestation Production + */ +pub static ATTESTATION_PRODUCTION_SECONDS: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_attestation_production_seconds", - "Full runtime of attestation production" - ); - pub static ref ATTESTATION_PRODUCTION_HEAD_SCRAPE_SECONDS: Result = try_create_histogram( - "attestation_production_head_scrape_seconds", - "Time taken to read the head state" - ); - pub static ref ATTESTATION_PRODUCTION_CACHE_INTERACTION_SECONDS: Result = try_create_histogram( - "attestation_production_cache_interaction_seconds", - "Time spent interacting with the attester cache" - ); - pub static ref ATTESTATION_PRODUCTION_CACHE_PRIME_SECONDS: Result = try_create_histogram( - "attestation_production_cache_prime_seconds", - "Time spent loading a new state from the disk due to a cache miss" - ); + "Full runtime of attestation production", + ) +}); +pub static ATTESTATION_PRODUCTION_HEAD_SCRAPE_SECONDS: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "attestation_production_head_scrape_seconds", + "Time taken to read the head state", + ) + }); +pub static ATTESTATION_PRODUCTION_CACHE_INTERACTION_SECONDS: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "attestation_production_cache_interaction_seconds", + "Time spent interacting with the attester cache", + ) + }); +pub static ATTESTATION_PRODUCTION_CACHE_PRIME_SECONDS: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "attestation_production_cache_prime_seconds", + "Time spent loading a new state from the disk due to a cache miss", + ) + }); - /* - * Fork Choice - */ - pub static ref FORK_CHOICE_REQUESTS: Result = try_create_int_counter( +/* + * Fork Choice + */ +pub static FORK_CHOICE_REQUESTS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "beacon_fork_choice_requests_total", - "Count of occasions where fork choice has tried to find a head" - ); - pub static ref FORK_CHOICE_ERRORS: Result = try_create_int_counter( + "Count of occasions where fork choice has tried to find a head", + ) +}); +pub static FORK_CHOICE_ERRORS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "beacon_fork_choice_errors_total", - "Count of occasions where fork choice has returned an error when trying to find a head" - ); - pub static ref FORK_CHOICE_CHANGED_HEAD: Result = try_create_int_counter( + "Count of occasions where fork choice has returned an error when trying to find a head", + ) +}); +pub static FORK_CHOICE_CHANGED_HEAD: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "beacon_fork_choice_changed_head_total", - "Count of occasions fork choice has found a new head" - ); - pub static ref FORK_CHOICE_REORG_COUNT: Result = try_create_int_counter( + "Count of occasions fork choice has found a new head", + ) +}); +pub static FORK_CHOICE_REORG_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "beacon_fork_choice_reorg_total", - "Count of occasions fork choice has switched to a different chain" - ); - pub static ref FORK_CHOICE_REORG_DISTANCE: Result = try_create_int_gauge( + "Count of occasions fork choice has switched to a different chain", + ) +}); +pub static FORK_CHOICE_REORG_DISTANCE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "beacon_fork_choice_reorg_distance", - "The distance of each re-org of the fork choice algorithm" - ); - pub static ref FORK_CHOICE_REORG_COUNT_INTEROP: Result = try_create_int_counter( + "The distance of each re-org of the fork choice algorithm", + ) +}); +pub static FORK_CHOICE_REORG_COUNT_INTEROP: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "beacon_reorgs_total", - "Count of occasions fork choice has switched to a different chain" - ); - pub static ref FORK_CHOICE_TIMES: Result = try_create_histogram_with_buckets( + "Count of occasions fork choice has switched to a different chain", + ) +}); +pub static FORK_CHOICE_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram_with_buckets( "beacon_fork_choice_seconds", "Full runtime of fork choice", - linear_buckets(10e-3, 20e-3, 10) - ); - pub static ref FORK_CHOICE_OVERRIDE_FCU_TIMES: Result = try_create_histogram_with_buckets( + linear_buckets(10e-3, 20e-3, 10), + ) +}); +pub static FORK_CHOICE_OVERRIDE_FCU_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram_with_buckets( "beacon_fork_choice_override_fcu_seconds", "Time taken to compute the optional forkchoiceUpdated override", - exponential_buckets(1e-3, 2.0, 8) - ); - pub static ref FORK_CHOICE_AFTER_NEW_HEAD_TIMES: Result = try_create_histogram_with_buckets( + exponential_buckets(1e-3, 2.0, 8), + ) +}); +pub static FORK_CHOICE_AFTER_NEW_HEAD_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram_with_buckets( "beacon_fork_choice_after_new_head_seconds", "Time taken to run `after_new_head`", - exponential_buckets(1e-3, 2.0, 10) - ); - pub static ref FORK_CHOICE_AFTER_FINALIZATION_TIMES: Result = try_create_histogram_with_buckets( - "beacon_fork_choice_after_finalization_seconds", - "Time taken to run `after_finalization`", - exponential_buckets(1e-3, 2.0, 10) - ); - pub static ref FORK_CHOICE_PROCESS_BLOCK_TIMES: Result = try_create_histogram( + exponential_buckets(1e-3, 2.0, 10), + ) +}); +pub static FORK_CHOICE_AFTER_FINALIZATION_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram_with_buckets( + "beacon_fork_choice_after_finalization_seconds", + "Time taken to run `after_finalization`", + exponential_buckets(1e-3, 2.0, 10), + ) + }); +pub static FORK_CHOICE_PROCESS_BLOCK_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_fork_choice_process_block_seconds", - "Time taken to add a block and all attestations to fork choice" - ); - pub static ref FORK_CHOICE_PROCESS_ATTESTATION_TIMES: Result = try_create_histogram( - "beacon_fork_choice_process_attestation_seconds", - "Time taken to add an attestation to fork choice" - ); - pub static ref FORK_CHOICE_SET_HEAD_LAG_TIMES: Result = try_create_histogram( + "Time taken to add a block and all attestations to fork choice", + ) +}); +pub static FORK_CHOICE_PROCESS_ATTESTATION_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_fork_choice_process_attestation_seconds", + "Time taken to add an attestation to fork choice", + ) + }); +pub static FORK_CHOICE_SET_HEAD_LAG_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_fork_choice_set_head_lag_times", - "Time taken between finding the head and setting the canonical head value" - ); - pub static ref BALANCES_CACHE_HITS: Result = - try_create_int_counter("beacon_balances_cache_hits_total", "Count of times balances cache fulfils request"); - pub static ref BALANCES_CACHE_MISSES: Result = - try_create_int_counter("beacon_balances_cache_misses_total", "Count of times balances cache misses request"); + "Time taken between finding the head and setting the canonical head value", + ) +}); +pub static BALANCES_CACHE_HITS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( + "beacon_balances_cache_hits_total", + "Count of times balances cache fulfils request", + ) +}); +pub static BALANCES_CACHE_MISSES: LazyLock> = LazyLock::new(|| { + try_create_int_counter( + "beacon_balances_cache_misses_total", + "Count of times balances cache misses request", + ) +}); - /* - * Persisting BeaconChain components to disk - */ - pub static ref PERSIST_HEAD: Result = - try_create_histogram("beacon_persist_head", "Time taken to persist the canonical head"); - pub static ref PERSIST_OP_POOL: Result = - try_create_histogram("beacon_persist_op_pool", "Time taken to persist the operations pool"); - pub static ref PERSIST_ETH1_CACHE: Result = - try_create_histogram("beacon_persist_eth1_cache", "Time taken to persist the eth1 caches"); - pub static ref PERSIST_FORK_CHOICE: Result = - try_create_histogram("beacon_persist_fork_choice", "Time taken to persist the fork choice struct"); +/* + * Persisting BeaconChain components to disk + */ +pub static PERSIST_HEAD: LazyLock> = LazyLock::new(|| { + try_create_histogram( + "beacon_persist_head", + "Time taken to persist the canonical head", + ) +}); +pub static PERSIST_OP_POOL: LazyLock> = LazyLock::new(|| { + try_create_histogram( + "beacon_persist_op_pool", + "Time taken to persist the operations pool", + ) +}); +pub static PERSIST_ETH1_CACHE: LazyLock> = LazyLock::new(|| { + try_create_histogram( + "beacon_persist_eth1_cache", + "Time taken to persist the eth1 caches", + ) +}); +pub static PERSIST_FORK_CHOICE: LazyLock> = LazyLock::new(|| { + try_create_histogram( + "beacon_persist_fork_choice", + "Time taken to persist the fork choice struct", + ) +}); - /* - * Eth1 - */ - pub static ref DEFAULT_ETH1_VOTES: Result = - try_create_int_counter("beacon_eth1_default_votes", "Count of times we have voted default value for eth1 data"); +/* + * Eth1 + */ +pub static DEFAULT_ETH1_VOTES: LazyLock> = LazyLock::new(|| { + try_create_int_counter( + "beacon_eth1_default_votes", + "Count of times we have voted default value for eth1 data", + ) +}); - /* - * Chain Head - */ - pub static ref UPDATE_HEAD_TIMES: Result = - try_create_histogram("beacon_update_head_seconds", "Time taken to update the canonical head"); - pub static ref HEAD_STATE_SLOT: Result = - try_create_int_gauge("beacon_head_state_slot", "Slot of the block at the head of the chain"); - pub static ref HEAD_STATE_SLOT_INTEROP: Result = - try_create_int_gauge("beacon_head_slot", "Slot of the block at the head of the chain"); - pub static ref HEAD_STATE_ROOT: Result = - try_create_int_gauge("beacon_head_state_root", "Root of the block at the head of the chain"); - pub static ref HEAD_STATE_LATEST_BLOCK_SLOT: Result = - try_create_int_gauge("beacon_head_state_latest_block_slot", "Latest block slot at the head of the chain"); - pub static ref HEAD_STATE_CURRENT_JUSTIFIED_ROOT: Result = - try_create_int_gauge("beacon_head_state_current_justified_root", "Current justified root at the head of the chain"); - pub static ref HEAD_STATE_CURRENT_JUSTIFIED_EPOCH: Result = - try_create_int_gauge("beacon_head_state_current_justified_epoch", "Current justified epoch at the head of the chain"); - pub static ref HEAD_STATE_CURRENT_JUSTIFIED_EPOCH_INTEROP: Result = - try_create_int_gauge("beacon_current_justified_epoch", "Current justified epoch at the head of the chain"); - pub static ref HEAD_STATE_PREVIOUS_JUSTIFIED_ROOT: Result = - try_create_int_gauge("beacon_head_state_previous_justified_root", "Previous justified root at the head of the chain"); - pub static ref HEAD_STATE_PREVIOUS_JUSTIFIED_EPOCH: Result = - try_create_int_gauge("beacon_head_state_previous_justified_epoch", "Previous justified epoch at the head of the chain"); - pub static ref HEAD_STATE_PREVIOUS_JUSTIFIED_EPOCH_INTEROP: Result = - try_create_int_gauge("beacon_previous_justified_epoch", "Previous justified epoch at the head of the chain"); - pub static ref HEAD_STATE_FINALIZED_ROOT: Result = - try_create_int_gauge("beacon_head_state_finalized_root", "Finalized root at the head of the chain"); - pub static ref HEAD_STATE_FINALIZED_EPOCH: Result = - try_create_int_gauge("beacon_head_state_finalized_epoch", "Finalized epoch at the head of the chain"); - pub static ref HEAD_STATE_FINALIZED_EPOCH_INTEROP: Result = - try_create_int_gauge("beacon_finalized_epoch", "Finalized epoch at the head of the chain"); - pub static ref HEAD_STATE_TOTAL_VALIDATORS: Result = - try_create_int_gauge("beacon_head_state_total_validators_total", "Count of validators at the head of the chain"); - pub static ref HEAD_STATE_ACTIVE_VALIDATORS: Result = - try_create_int_gauge("beacon_head_state_active_validators_total", "Count of active validators at the head of the chain"); - pub static ref HEAD_STATE_ACTIVE_VALIDATORS_INTEROP: Result = - try_create_int_gauge("beacon_current_active_validators", "Count of active validators at the head of the chain"); - pub static ref HEAD_STATE_VALIDATOR_BALANCES: Result = - try_create_int_gauge("beacon_head_state_validator_balances_total", "Sum of all validator balances at the head of the chain"); - pub static ref HEAD_STATE_SLASHED_VALIDATORS: Result = - try_create_int_gauge("beacon_head_state_slashed_validators_total", "Count of all slashed validators at the head of the chain"); - pub static ref HEAD_STATE_WITHDRAWN_VALIDATORS: Result = - try_create_int_gauge("beacon_head_state_withdrawn_validators_total", "Sum of all validator balances at the head of the chain"); - pub static ref HEAD_STATE_ETH1_DEPOSIT_INDEX: Result = - try_create_int_gauge("beacon_head_state_eth1_deposit_index", "Eth1 deposit index at the head of the chain"); - pub static ref HEAD_STATE_ETH1_DEPOSITS_INTEROP: Result = - try_create_int_gauge("beacon_processed_deposits_total", "Total Eth1 deposits at the head of the chain"); +/* + * Chain Head + */ +pub static UPDATE_HEAD_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( + "beacon_update_head_seconds", + "Time taken to update the canonical head", + ) +}); +pub static HEAD_STATE_SLOT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_slot", + "Slot of the block at the head of the chain", + ) +}); +pub static HEAD_STATE_SLOT_INTEROP: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_slot", + "Slot of the block at the head of the chain", + ) +}); +pub static HEAD_STATE_ROOT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_root", + "Root of the block at the head of the chain", + ) +}); +pub static HEAD_STATE_LATEST_BLOCK_SLOT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_latest_block_slot", + "Latest block slot at the head of the chain", + ) +}); +pub static HEAD_STATE_CURRENT_JUSTIFIED_ROOT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_current_justified_root", + "Current justified root at the head of the chain", + ) +}); +pub static HEAD_STATE_CURRENT_JUSTIFIED_EPOCH: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_current_justified_epoch", + "Current justified epoch at the head of the chain", + ) +}); +pub static HEAD_STATE_CURRENT_JUSTIFIED_EPOCH_INTEROP: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_current_justified_epoch", + "Current justified epoch at the head of the chain", + ) + }); +pub static HEAD_STATE_PREVIOUS_JUSTIFIED_ROOT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_previous_justified_root", + "Previous justified root at the head of the chain", + ) +}); +pub static HEAD_STATE_PREVIOUS_JUSTIFIED_EPOCH: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_previous_justified_epoch", + "Previous justified epoch at the head of the chain", + ) +}); +pub static HEAD_STATE_PREVIOUS_JUSTIFIED_EPOCH_INTEROP: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_previous_justified_epoch", + "Previous justified epoch at the head of the chain", + ) + }); +pub static HEAD_STATE_FINALIZED_ROOT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_finalized_root", + "Finalized root at the head of the chain", + ) +}); +pub static HEAD_STATE_FINALIZED_EPOCH: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_finalized_epoch", + "Finalized epoch at the head of the chain", + ) +}); +pub static HEAD_STATE_FINALIZED_EPOCH_INTEROP: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_finalized_epoch", + "Finalized epoch at the head of the chain", + ) +}); +pub static HEAD_STATE_TOTAL_VALIDATORS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_total_validators_total", + "Count of validators at the head of the chain", + ) +}); +pub static HEAD_STATE_ACTIVE_VALIDATORS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_active_validators_total", + "Count of active validators at the head of the chain", + ) +}); +pub static HEAD_STATE_ACTIVE_VALIDATORS_INTEROP: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_current_active_validators", + "Count of active validators at the head of the chain", + ) +}); +pub static HEAD_STATE_VALIDATOR_BALANCES: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_validator_balances_total", + "Sum of all validator balances at the head of the chain", + ) +}); +pub static HEAD_STATE_SLASHED_VALIDATORS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_slashed_validators_total", + "Count of all slashed validators at the head of the chain", + ) +}); +pub static HEAD_STATE_WITHDRAWN_VALIDATORS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_withdrawn_validators_total", + "Sum of all validator balances at the head of the chain", + ) +}); +pub static HEAD_STATE_ETH1_DEPOSIT_INDEX: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_head_state_eth1_deposit_index", + "Eth1 deposit index at the head of the chain", + ) +}); +pub static HEAD_STATE_ETH1_DEPOSITS_INTEROP: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_processed_deposits_total", + "Total Eth1 deposits at the head of the chain", + ) +}); - /* - * Operation Pool - */ - pub static ref OP_POOL_NUM_ATTESTATIONS: Result = - try_create_int_gauge("beacon_op_pool_attestations_total", "Count of attestations in the op pool"); - pub static ref OP_POOL_NUM_ATTESTATION_DATA: Result = - try_create_int_gauge("beacon_op_pool_attestation_data_total", "Count of attestation data in the op pool"); - pub static ref OP_POOL_MAX_AGGREGATES_PER_DATA: Result = - try_create_int_gauge("beacon_op_pool_max_aggregates_per_data", "Max aggregates per AttestationData"); - pub static ref OP_POOL_NUM_ATTESTER_SLASHINGS: Result = - try_create_int_gauge("beacon_op_pool_attester_slashings_total", "Count of attester slashings in the op pool"); - pub static ref OP_POOL_NUM_PROPOSER_SLASHINGS: Result = - try_create_int_gauge("beacon_op_pool_proposer_slashings_total", "Count of proposer slashings in the op pool"); - pub static ref OP_POOL_NUM_VOLUNTARY_EXITS: Result = - try_create_int_gauge("beacon_op_pool_voluntary_exits_total", "Count of voluntary exits in the op pool"); - pub static ref OP_POOL_NUM_SYNC_CONTRIBUTIONS: Result = - try_create_int_gauge("beacon_op_pool_sync_contributions_total", "Count of sync contributions in the op pool"); +/* + * Operation Pool + */ +pub static OP_POOL_NUM_ATTESTATIONS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_op_pool_attestations_total", + "Count of attestations in the op pool", + ) +}); +pub static OP_POOL_NUM_ATTESTATION_DATA: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_op_pool_attestation_data_total", + "Count of attestation data in the op pool", + ) +}); +pub static OP_POOL_MAX_AGGREGATES_PER_DATA: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_op_pool_max_aggregates_per_data", + "Max aggregates per AttestationData", + ) +}); +pub static OP_POOL_NUM_ATTESTER_SLASHINGS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_op_pool_attester_slashings_total", + "Count of attester slashings in the op pool", + ) +}); +pub static OP_POOL_NUM_PROPOSER_SLASHINGS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_op_pool_proposer_slashings_total", + "Count of proposer slashings in the op pool", + ) +}); +pub static OP_POOL_NUM_VOLUNTARY_EXITS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_op_pool_voluntary_exits_total", + "Count of voluntary exits in the op pool", + ) +}); +pub static OP_POOL_NUM_SYNC_CONTRIBUTIONS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_op_pool_sync_contributions_total", + "Count of sync contributions in the op pool", + ) +}); +/* + * Attestation Observation Metrics + */ +pub static ATTN_OBSERVATION_PREV_EPOCH_ATTESTERS: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_attn_observation_epoch_attesters", + "Count of attesters that have been seen by the beacon chain in the previous epoch", + ) + }); +pub static ATTN_OBSERVATION_PREV_EPOCH_AGGREGATORS: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_attn_observation_epoch_aggregators", + "Count of aggregators that have been seen by the beacon chain in the previous epoch", + ) + }); - /* - * Attestation Observation Metrics - */ - pub static ref ATTN_OBSERVATION_PREV_EPOCH_ATTESTERS: Result = try_create_int_gauge( - "beacon_attn_observation_epoch_attesters", - "Count of attesters that have been seen by the beacon chain in the previous epoch" - ); - pub static ref ATTN_OBSERVATION_PREV_EPOCH_AGGREGATORS: Result = try_create_int_gauge( - "beacon_attn_observation_epoch_aggregators", - "Count of aggregators that have been seen by the beacon chain in the previous epoch" - ); - - /* - * Sync Committee Observation Metrics - */ - pub static ref SYNC_COMM_OBSERVATION_PREV_SLOT_SIGNERS: Result = try_create_int_gauge( +/* + * Sync Committee Observation Metrics + */ +pub static SYNC_COMM_OBSERVATION_PREV_SLOT_SIGNERS: LazyLock> = LazyLock::new( + || { + try_create_int_gauge( "beacon_sync_comm_observation_slot_signers", "Count of sync committee contributors that have been seen by the beacon chain in the previous slot" - ); - pub static ref SYNC_COMM_OBSERVATION_PREV_SLOT_AGGREGATORS: Result = try_create_int_gauge( + ) + }, +); +pub static SYNC_COMM_OBSERVATION_PREV_SLOT_AGGREGATORS: LazyLock> = LazyLock::new( + || { + try_create_int_gauge( "beacon_sync_comm_observation_slot_aggregators", "Count of sync committee aggregators that have been seen by the beacon chain in the previous slot" - ); -} + ) + }, +); -// Third lazy-static block is used to account for macro recursion limit. -lazy_static! { - /* - * Validator Monitor Metrics (balances, etc) - */ - pub static ref VALIDATOR_MONITOR_BALANCE_GWEI: Result = - try_create_int_gauge_vec( - "validator_monitor_balance_gwei", - "The validator's balance in gwei.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_EFFECTIVE_BALANCE_GWEI: Result = +/* + * Validator Monitor Metrics (balances, etc) + */ +pub static VALIDATOR_MONITOR_BALANCE_GWEI: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( + "validator_monitor_balance_gwei", + "The validator's balance in gwei.", + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_EFFECTIVE_BALANCE_GWEI: LazyLock> = + LazyLock::new(|| { try_create_int_gauge_vec( "validator_monitor_effective_balance_gwei", "The validator's effective balance in gwei.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_SLASHED: Result = - try_create_int_gauge_vec( - "validator_monitor_slashed", - "Set to 1 if the validator is slashed.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_ACTIVE: Result = - try_create_int_gauge_vec( - "validator_monitor_active", - "Set to 1 if the validator is active.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_EXITED: Result = - try_create_int_gauge_vec( - "validator_monitor_exited", - "Set to 1 if the validator is exited.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_WITHDRAWABLE: Result = - try_create_int_gauge_vec( - "validator_monitor_withdrawable", - "Set to 1 if the validator is withdrawable.", - &["validator"] - ); - pub static ref VALIDATOR_ACTIVATION_ELIGIBILITY_EPOCH: Result = + &["validator"], + ) + }); +pub static VALIDATOR_MONITOR_SLASHED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( + "validator_monitor_slashed", + "Set to 1 if the validator is slashed.", + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_ACTIVE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( + "validator_monitor_active", + "Set to 1 if the validator is active.", + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_EXITED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( + "validator_monitor_exited", + "Set to 1 if the validator is exited.", + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_WITHDRAWABLE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( + "validator_monitor_withdrawable", + "Set to 1 if the validator is withdrawable.", + &["validator"], + ) +}); +pub static VALIDATOR_ACTIVATION_ELIGIBILITY_EPOCH: LazyLock> = + LazyLock::new(|| { try_create_int_gauge_vec( "validator_activation_eligibility_epoch", "Set to the epoch where the validator will be eligible for activation.", - &["validator"] - ); - pub static ref VALIDATOR_ACTIVATION_EPOCH: Result = - try_create_int_gauge_vec( - "validator_activation_epoch", - "Set to the epoch where the validator will activate.", - &["validator"] - ); - pub static ref VALIDATOR_EXIT_EPOCH: Result = - try_create_int_gauge_vec( - "validator_exit_epoch", - "Set to the epoch where the validator will exit.", - &["validator"] - ); - pub static ref VALIDATOR_WITHDRAWABLE_EPOCH: Result = - try_create_int_gauge_vec( - "validator_withdrawable_epoch", - "Set to the epoch where the validator will be withdrawable.", - &["validator"] - ); + &["validator"], + ) + }); +pub static VALIDATOR_ACTIVATION_EPOCH: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( + "validator_activation_epoch", + "Set to the epoch where the validator will activate.", + &["validator"], + ) +}); +pub static VALIDATOR_EXIT_EPOCH: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( + "validator_exit_epoch", + "Set to the epoch where the validator will exit.", + &["validator"], + ) +}); +pub static VALIDATOR_WITHDRAWABLE_EPOCH: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( + "validator_withdrawable_epoch", + "Set to the epoch where the validator will be withdrawable.", + &["validator"], + ) +}); - /* - * Validator Monitor Metrics (per-epoch summaries) - */ - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_ATTESTER_HIT: Result = +/* + * Validator Monitor Metrics (per-epoch summaries) + */ +pub static VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_ATTESTER_HIT: LazyLock> = + LazyLock::new(|| { try_create_int_counter_vec( "validator_monitor_prev_epoch_on_chain_attester_hit", "Incremented if the validator is flagged as a previous epoch attester \ during per epoch processing", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_ATTESTER_MISS: Result = + &["validator"], + ) + }); +pub static VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_ATTESTER_MISS: LazyLock> = + LazyLock::new(|| { try_create_int_counter_vec( "validator_monitor_prev_epoch_on_chain_attester_miss", "Incremented if the validator is not flagged as a previous epoch attester \ during per epoch processing", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_HEAD_ATTESTER_HIT: Result = - try_create_int_counter_vec( - "validator_monitor_prev_epoch_on_chain_head_attester_hit", - "Incremented if the validator is flagged as a previous epoch head attester \ + &["validator"], + ) + }); +pub static VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_HEAD_ATTESTER_HIT: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_counter_vec( + "validator_monitor_prev_epoch_on_chain_head_attester_hit", + "Incremented if the validator is flagged as a previous epoch head attester \ during per epoch processing", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_HEAD_ATTESTER_MISS: Result = - try_create_int_counter_vec( - "validator_monitor_prev_epoch_on_chain_head_attester_miss", - "Incremented if the validator is not flagged as a previous epoch head attester \ + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_HEAD_ATTESTER_MISS: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_counter_vec( + "validator_monitor_prev_epoch_on_chain_head_attester_miss", + "Incremented if the validator is not flagged as a previous epoch head attester \ during per epoch processing", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_TARGET_ATTESTER_HIT: Result = - try_create_int_counter_vec( - "validator_monitor_prev_epoch_on_chain_target_attester_hit", - "Incremented if the validator is flagged as a previous epoch target attester \ + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_TARGET_ATTESTER_HIT: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_counter_vec( + "validator_monitor_prev_epoch_on_chain_target_attester_hit", + "Incremented if the validator is flagged as a previous epoch target attester \ during per epoch processing", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_TARGET_ATTESTER_MISS: Result = - try_create_int_counter_vec( - "validator_monitor_prev_epoch_on_chain_target_attester_miss", - "Incremented if the validator is not flagged as a previous epoch target attester \ + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_TARGET_ATTESTER_MISS: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_counter_vec( + "validator_monitor_prev_epoch_on_chain_target_attester_miss", + "Incremented if the validator is not flagged as a previous epoch target attester \ during per epoch processing", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_INCLUSION_DISTANCE: Result = + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_INCLUSION_DISTANCE: LazyLock> = + LazyLock::new(|| { try_create_int_gauge_vec( "validator_monitor_prev_epoch_on_chain_inclusion_distance", "The attestation inclusion distance calculated during per epoch processing", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_ATTESTATIONS_TOTAL: Result = + &["validator"], + ) + }); +pub static VALIDATOR_MONITOR_PREV_EPOCH_ATTESTATIONS_TOTAL: LazyLock> = + LazyLock::new(|| { try_create_int_gauge_vec( "validator_monitor_prev_epoch_attestations_total", "The number of unagg. attestations seen in the previous epoch.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_ATTESTATIONS_MIN_DELAY_SECONDS: Result = - try_create_histogram_vec( + &["validator"], + ) + }); +pub static VALIDATOR_MONITOR_PREV_EPOCH_ATTESTATIONS_MIN_DELAY_SECONDS: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_histogram_vec( "validator_monitor_prev_epoch_attestations_min_delay_seconds", "The min delay between when the validator should send the attestation and when it was received.", &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_ATTESTATION_AGGREGATE_INCLUSIONS: Result = - try_create_int_gauge_vec( - "validator_monitor_prev_epoch_attestation_aggregate_inclusions", - "The count of times an attestation was seen inside an aggregate.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_ATTESTATION_BLOCK_INCLUSIONS: Result = - try_create_int_gauge_vec( - "validator_monitor_prev_epoch_attestation_block_inclusions", - "The count of times an attestation was seen inside a block.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_ATTESTATION_BLOCK_MIN_INCLUSION_DISTANCE: Result = - try_create_int_gauge_vec( - "validator_monitor_prev_epoch_attestation_block_min_inclusion_distance", - "The minimum inclusion distance observed for the inclusion of an attestation in a block.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_BEACON_BLOCKS_TOTAL: Result = + ) +}); +pub static VALIDATOR_MONITOR_PREV_EPOCH_ATTESTATION_AGGREGATE_INCLUSIONS: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_gauge_vec( + "validator_monitor_prev_epoch_attestation_aggregate_inclusions", + "The count of times an attestation was seen inside an aggregate.", + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_PREV_EPOCH_ATTESTATION_BLOCK_INCLUSIONS: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_gauge_vec( + "validator_monitor_prev_epoch_attestation_block_inclusions", + "The count of times an attestation was seen inside a block.", + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_PREV_EPOCH_ATTESTATION_BLOCK_MIN_INCLUSION_DISTANCE: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_gauge_vec( + "validator_monitor_prev_epoch_attestation_block_min_inclusion_distance", + "The minimum inclusion distance observed for the inclusion of an attestation in a block.", + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_PREV_EPOCH_BEACON_BLOCKS_TOTAL: LazyLock> = + LazyLock::new(|| { try_create_int_gauge_vec( "validator_monitor_prev_epoch_beacon_blocks_total", "The number of beacon_blocks seen in the previous epoch.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_BEACON_BLOCKS_MIN_DELAY_SECONDS: Result = - try_create_histogram_vec( - "validator_monitor_prev_epoch_beacon_blocks_min_delay_seconds", - "The min delay between when the validator should send the block and when it was received.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_AGGREGATES_TOTAL: Result = + &["validator"], + ) + }); +pub static VALIDATOR_MONITOR_PREV_EPOCH_BEACON_BLOCKS_MIN_DELAY_SECONDS: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_histogram_vec( + "validator_monitor_prev_epoch_beacon_blocks_min_delay_seconds", + "The min delay between when the validator should send the block and when it was received.", + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_PREV_EPOCH_AGGREGATES_TOTAL: LazyLock> = + LazyLock::new(|| { try_create_int_gauge_vec( "validator_monitor_prev_epoch_aggregates_total", "The number of aggregates seen in the previous epoch.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_AGGREGATES_MIN_DELAY_SECONDS: Result = - try_create_histogram_vec( + &["validator"], + ) + }); +pub static VALIDATOR_MONITOR_PREV_EPOCH_AGGREGATES_MIN_DELAY_SECONDS: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_histogram_vec( "validator_monitor_prev_epoch_aggregates_min_delay_seconds", "The min delay between when the validator should send the aggregate and when it was received.", &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_EXITS_TOTAL: Result = + ) +}); +pub static VALIDATOR_MONITOR_PREV_EPOCH_EXITS_TOTAL: LazyLock> = + LazyLock::new(|| { try_create_int_gauge_vec( "validator_monitor_prev_epoch_exits_total", "The number of exits seen in the previous epoch.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_PROPOSER_SLASHINGS_TOTAL: Result = + &["validator"], + ) + }); +pub static VALIDATOR_MONITOR_PREV_EPOCH_PROPOSER_SLASHINGS_TOTAL: LazyLock> = + LazyLock::new(|| { try_create_int_gauge_vec( "validator_monitor_prev_epoch_proposer_slashings_total", "The number of proposer slashings seen in the previous epoch.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_ATTESTER_SLASHINGS_TOTAL: Result = + &["validator"], + ) + }); +pub static VALIDATOR_MONITOR_PREV_EPOCH_ATTESTER_SLASHINGS_TOTAL: LazyLock> = + LazyLock::new(|| { try_create_int_gauge_vec( "validator_monitor_prev_epoch_attester_slashings_total", "The number of attester slashings seen in the previous epoch.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_SYNC_COMMITTEE_MESSAGES_TOTAL: Result = - try_create_int_gauge_vec( - "validator_monitor_prev_epoch_sync_committee_messages_total", - "The number of sync committee messages seen in the previous epoch.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_SYNC_COMMITTEE_MESSAGES_MIN_DELAY_SECONDS: Result = - try_create_histogram_vec( + &["validator"], + ) + }); +pub static VALIDATOR_MONITOR_PREV_EPOCH_SYNC_COMMITTEE_MESSAGES_TOTAL: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_gauge_vec( + "validator_monitor_prev_epoch_sync_committee_messages_total", + "The number of sync committee messages seen in the previous epoch.", + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_PREV_EPOCH_SYNC_COMMITTEE_MESSAGES_MIN_DELAY_SECONDS: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_histogram_vec( "validator_monitor_prev_epoch_sync_committee_messages_min_delay_seconds", "The min delay between when the validator should send the sync committee message and when it was received.", &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_SYNC_CONTRIBUTION_INCLUSIONS: Result = - try_create_int_gauge_vec( - "validator_monitor_prev_epoch_sync_contribution_inclusions", - "The count of times a sync signature was seen inside a sync contribution.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_SYNC_SIGNATURE_BLOCK_INCLUSIONS: Result = - try_create_int_gauge_vec( - "validator_monitor_prev_epoch_sync_signature_block_inclusions", - "The count of times a sync signature was seen inside a block.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_SYNC_CONTRIBUTIONS_TOTAL: Result = + ) +}); +pub static VALIDATOR_MONITOR_PREV_EPOCH_SYNC_CONTRIBUTION_INCLUSIONS: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_gauge_vec( + "validator_monitor_prev_epoch_sync_contribution_inclusions", + "The count of times a sync signature was seen inside a sync contribution.", + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_PREV_EPOCH_SYNC_SIGNATURE_BLOCK_INCLUSIONS: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_gauge_vec( + "validator_monitor_prev_epoch_sync_signature_block_inclusions", + "The count of times a sync signature was seen inside a block.", + &["validator"], + ) +}); +pub static VALIDATOR_MONITOR_PREV_EPOCH_SYNC_CONTRIBUTIONS_TOTAL: LazyLock> = + LazyLock::new(|| { try_create_int_gauge_vec( "validator_monitor_prev_epoch_sync_contributions_total", "The number of sync contributions seen in the previous epoch.", - &["validator"] - ); - pub static ref VALIDATOR_MONITOR_PREV_EPOCH_SYNC_CONTRIBUTION_MIN_DELAY_SECONDS: Result = - try_create_histogram_vec( + &["validator"], + ) + }); +pub static VALIDATOR_MONITOR_PREV_EPOCH_SYNC_CONTRIBUTION_MIN_DELAY_SECONDS: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_histogram_vec( "validator_monitor_prev_epoch_sync_contribution_min_delay_seconds", "The min delay between when the validator should send the sync contribution and when it was received.", &["validator"] - ); - pub static ref VALIDATOR_MONITOR_VALIDATOR_IN_CURRENT_SYNC_COMMITTEE: Result = + ) +}); +pub static VALIDATOR_MONITOR_VALIDATOR_IN_CURRENT_SYNC_COMMITTEE: LazyLock> = + LazyLock::new(|| { try_create_int_gauge_vec( "validator_monitor_validator_in_current_sync_committee", "Is the validator in the current sync committee (1 for true and 0 for false)", - &["validator"] - ); + &["validator"], + ) + }); - /* - * Validator Monitor Metrics (real-time) - */ - pub static ref VALIDATOR_MONITOR_VALIDATORS_TOTAL: Result = try_create_int_gauge( +/* + * Validator Monitor Metrics (real-time) + */ +pub static VALIDATOR_MONITOR_VALIDATORS_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "validator_monitor_validators_total", - "Count of validators that are specifically monitored by this beacon node" - ); - pub static ref VALIDATOR_MONITOR_UNAGGREGATED_ATTESTATION_TOTAL: Result = try_create_int_counter_vec( - "validator_monitor_unaggregated_attestation_total", - "Number of unaggregated attestations seen", - &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_UNAGGREGATED_ATTESTATION_DELAY_SECONDS: Result = try_create_histogram_vec( + "Count of validators that are specifically monitored by this beacon node", + ) +}); +pub static VALIDATOR_MONITOR_UNAGGREGATED_ATTESTATION_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "validator_monitor_unaggregated_attestation_total", + "Number of unaggregated attestations seen", + &["src", "validator"], + ) + }); +pub static VALIDATOR_MONITOR_UNAGGREGATED_ATTESTATION_DELAY_SECONDS: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_histogram_vec( "validator_monitor_unaggregated_attestation_delay_seconds", "The delay between when the validator should send the attestation and when it was received.", &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_SYNC_COMMITTEE_MESSAGES_TOTAL: Result = try_create_int_counter_vec( - "validator_monitor_sync_committee_messages_total", - "Number of sync committee messages seen", - &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_SYNC_COMMITTEE_MESSAGES_DELAY_SECONDS: Result = try_create_histogram_vec( + ) +}); +pub static VALIDATOR_MONITOR_SYNC_COMMITTEE_MESSAGES_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "validator_monitor_sync_committee_messages_total", + "Number of sync committee messages seen", + &["src", "validator"], + ) + }); +pub static VALIDATOR_MONITOR_SYNC_COMMITTEE_MESSAGES_DELAY_SECONDS: LazyLock> = + LazyLock::new(|| { + try_create_histogram_vec( "validator_monitor_sync_committee_messages_delay_seconds", "The delay between when the validator should send the sync committee message and when it was received.", &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_SYNC_CONTRIBUTIONS_TOTAL: Result = try_create_int_counter_vec( - "validator_monitor_sync_contributions_total", - "Number of sync contributions seen", - &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_SYNC_CONTRIBUTIONS_DELAY_SECONDS: Result = try_create_histogram_vec( + ) + }); +pub static VALIDATOR_MONITOR_SYNC_CONTRIBUTIONS_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "validator_monitor_sync_contributions_total", + "Number of sync contributions seen", + &["src", "validator"], + ) + }); +pub static VALIDATOR_MONITOR_SYNC_CONTRIBUTIONS_DELAY_SECONDS: LazyLock> = + LazyLock::new(|| { + try_create_histogram_vec( "validator_monitor_sync_contributions_delay_seconds", "The delay between when the aggregator should send the sync contribution and when it was received.", &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_AGGREGATED_ATTESTATION_TOTAL: Result = try_create_int_counter_vec( - "validator_monitor_aggregated_attestation_total", - "Number of aggregated attestations seen", - &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_AGGREGATED_ATTESTATION_DELAY_SECONDS: Result = try_create_histogram_vec( + ) + }); +pub static VALIDATOR_MONITOR_AGGREGATED_ATTESTATION_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "validator_monitor_aggregated_attestation_total", + "Number of aggregated attestations seen", + &["src", "validator"], + ) + }); +pub static VALIDATOR_MONITOR_AGGREGATED_ATTESTATION_DELAY_SECONDS: LazyLock> = + LazyLock::new(|| { + try_create_histogram_vec( "validator_monitor_aggregated_attestation_delay_seconds", "The delay between then the validator should send the aggregate and when it was received.", &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_ATTESTATION_IN_AGGREGATE_TOTAL: Result = try_create_int_counter_vec( - "validator_monitor_attestation_in_aggregate_total", - "Number of times an attestation has been seen in an aggregate", - &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_SYNC_COMMITTEE_MESSAGE_IN_CONTRIBUTION_TOTAL: Result = try_create_int_counter_vec( + ) + }); +pub static VALIDATOR_MONITOR_ATTESTATION_IN_AGGREGATE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "validator_monitor_attestation_in_aggregate_total", + "Number of times an attestation has been seen in an aggregate", + &["src", "validator"], + ) + }); +pub static VALIDATOR_MONITOR_SYNC_COMMITTEE_MESSAGE_IN_CONTRIBUTION_TOTAL: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_counter_vec( "validator_monitor_sync_committee_message_in_contribution_total", "Number of times a sync committee message has been seen in a sync contribution", - &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_ATTESTATION_IN_AGGREGATE_DELAY_SECONDS: Result = try_create_histogram_vec( + &["src", "validator"], + ) +}); +pub static VALIDATOR_MONITOR_ATTESTATION_IN_AGGREGATE_DELAY_SECONDS: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_histogram_vec( "validator_monitor_attestation_in_aggregate_delay_seconds", "The delay between when the validator should send the aggregate and when it was received.", - &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_ATTESTATION_IN_BLOCK_TOTAL: Result = try_create_int_counter_vec( - "validator_monitor_attestation_in_block_total", - "Number of times an attestation has been seen in a block", - &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_SYNC_COMMITTEE_MESSAGE_IN_BLOCK_TOTAL: Result = try_create_int_counter_vec( + &["src", "validator"], + ) +}); +pub static VALIDATOR_MONITOR_ATTESTATION_IN_BLOCK_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "validator_monitor_attestation_in_block_total", + "Number of times an attestation has been seen in a block", + &["src", "validator"], + ) + }); +pub static VALIDATOR_MONITOR_SYNC_COMMITTEE_MESSAGE_IN_BLOCK_TOTAL: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_counter_vec( "validator_monitor_sync_committee_message_in_block_total", "Number of times a validator's sync committee message has been seen in a sync aggregate", - &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_ATTESTATION_IN_BLOCK_DELAY_SLOTS: Result = try_create_int_gauge_vec( + &["src", "validator"], + ) +}); +pub static VALIDATOR_MONITOR_ATTESTATION_IN_BLOCK_DELAY_SLOTS: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge_vec( "validator_monitor_attestation_in_block_delay_slots", "The excess slots (beyond the minimum delay) between the attestation slot and the block slot.", &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_BEACON_BLOCK_TOTAL: Result = try_create_int_counter_vec( - "validator_monitor_beacon_block_total", - "Number of beacon blocks seen", - &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_BEACON_BLOCK_DELAY_SECONDS: Result = try_create_histogram_vec( - "validator_monitor_beacon_block_delay_seconds", - "The delay between when the validator should send the block and when it was received.", - &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_EXIT_TOTAL: Result = try_create_int_counter_vec( + ) + }); +pub static VALIDATOR_MONITOR_BEACON_BLOCK_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "validator_monitor_beacon_block_total", + "Number of beacon blocks seen", + &["src", "validator"], + ) + }); +pub static VALIDATOR_MONITOR_BEACON_BLOCK_DELAY_SECONDS: LazyLock> = + LazyLock::new(|| { + try_create_histogram_vec( + "validator_monitor_beacon_block_delay_seconds", + "The delay between when the validator should send the block and when it was received.", + &["src", "validator"], + ) + }); +pub static VALIDATOR_MONITOR_EXIT_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "validator_monitor_exit_total", "Number of beacon exits seen", - &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_PROPOSER_SLASHING_TOTAL: Result = try_create_int_counter_vec( - "validator_monitor_proposer_slashing_total", - "Number of proposer slashings seen", - &["src", "validator"] - ); - pub static ref VALIDATOR_MONITOR_ATTESTER_SLASHING_TOTAL: Result = try_create_int_counter_vec( - "validator_monitor_attester_slashing_total", - "Number of attester slashings seen", - &["src", "validator"] - ); -} + &["src", "validator"], + ) +}); +pub static VALIDATOR_MONITOR_PROPOSER_SLASHING_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "validator_monitor_proposer_slashing_total", + "Number of proposer slashings seen", + &["src", "validator"], + ) + }); +pub static VALIDATOR_MONITOR_ATTESTER_SLASHING_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "validator_monitor_attester_slashing_total", + "Number of attester slashings seen", + &["src", "validator"], + ) + }); // Prevent recursion limit -lazy_static! { - /* - * Block Delay Metrics - */ - pub static ref BEACON_BLOCK_DELAY_TOTAL: Result = try_create_int_gauge( +/* + * Block Delay Metrics + */ +pub static BEACON_BLOCK_DELAY_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "beacon_block_delay_total", "Duration between the start of the block's slot and the time when it was set as head.", - ); + ) +}); - pub static ref BEACON_BLOCK_DELAY_OBSERVED_SLOT_START: Result = try_create_int_gauge( - "beacon_block_delay_observed_slot_start", - "Duration between the start of the block's slot and the time the block was observed.", - ); +pub static BEACON_BLOCK_DELAY_OBSERVED_SLOT_START: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_block_delay_observed_slot_start", + "Duration between the start of the block's slot and the time the block was observed.", + ) + }); - pub static ref BEACON_BLOB_DELAY_ALL_OBSERVED_SLOT_START: Result = try_create_int_gauge( - "beacon_blob_delay_all_observed_slot_start", - "Duration between the start of the block's slot and the time the block was observed.", - ); +pub static BEACON_BLOB_DELAY_ALL_OBSERVED_SLOT_START: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_blob_delay_all_observed_slot_start", + "Duration between the start of the block's slot and the time the block was observed.", + ) + }); - pub static ref BEACON_BLOCK_DELAY_CONSENSUS_VERIFICATION_TIME: Result = try_create_int_gauge( - "beacon_block_delay_consensus_verification_time", - "The time taken to verify the block within Lighthouse", - ); +pub static BEACON_BLOCK_DELAY_CONSENSUS_VERIFICATION_TIME: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_block_delay_consensus_verification_time", + "The time taken to verify the block within Lighthouse", + ) + }); - pub static ref BEACON_BLOCK_DELAY_EXECUTION_TIME: Result = try_create_int_gauge( +pub static BEACON_BLOCK_DELAY_EXECUTION_TIME: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "beacon_block_delay_execution_time", "The duration in verifying the block with the execution layer.", - ); + ) +}); - pub static ref BEACON_BLOCK_DELAY_AVAILABLE_SLOT_START: Result = try_create_int_gauge( - "beacon_block_delay_available_slot_start", - "Duration between the time that block became available and the start of the slot.", - ); - pub static ref BEACON_BLOCK_DELAY_ATTESTABLE_SLOT_START: Result = try_create_int_gauge( - "beacon_block_delay_attestable_slot_start", - "Duration between the time that block became attestable and the start of the slot.", - ); +pub static BEACON_BLOCK_DELAY_AVAILABLE_SLOT_START: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_block_delay_available_slot_start", + "Duration between the time that block became available and the start of the slot.", + ) + }); +pub static BEACON_BLOCK_DELAY_ATTESTABLE_SLOT_START: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_block_delay_attestable_slot_start", + "Duration between the time that block became attestable and the start of the slot.", + ) + }); - pub static ref BEACON_BLOCK_DELAY_IMPORTED_TIME: Result = try_create_int_gauge( +pub static BEACON_BLOCK_DELAY_IMPORTED_TIME: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "beacon_block_delay_imported_time", "Duration between the time the block became available and the time when it was imported.", - ); + ) +}); - pub static ref BEACON_BLOCK_DELAY_HEAD_IMPORTED_TIME: Result = try_create_int_gauge( +pub static BEACON_BLOCK_DELAY_HEAD_IMPORTED_TIME: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( "beacon_block_delay_head_imported_time", "Duration between the time that block was imported and the time when it was set as head.", - ); - pub static ref BEACON_BLOCK_DELAY_HEAD_SLOT_START_EXCEEDED_TOTAL: Result = try_create_int_counter( + ) + }); +pub static BEACON_BLOCK_DELAY_HEAD_SLOT_START_EXCEEDED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( "beacon_block_delay_head_slot_start_exceeded_total", "A counter that is triggered when the duration between the start of the block's slot and the current time \ will result in failed attestations.", - ); + ) + }); - /* - * General block metrics - */ - pub static ref GOSSIP_BEACON_BLOCK_SKIPPED_SLOTS: Result = - try_create_int_gauge( - "gossip_beacon_block_skipped_slots", - "For each gossip blocks, the number of skip slots between it and its parent" - ); -} +/* + * General block metrics + */ +pub static GOSSIP_BEACON_BLOCK_SKIPPED_SLOTS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "gossip_beacon_block_skipped_slots", + "For each gossip blocks, the number of skip slots between it and its parent", + ) +}); -// Fourth lazy-static block is used to account for macro recursion limit. -lazy_static! { - /* - * Sync Committee Message Verification - */ - pub static ref SYNC_MESSAGE_PROCESSING_REQUESTS: Result = try_create_int_counter( +/* + * Sync Committee Message Verification + */ +pub static SYNC_MESSAGE_PROCESSING_REQUESTS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "beacon_sync_committee_message_processing_requests_total", - "Count of all sync messages submitted for processing" - ); - pub static ref SYNC_MESSAGE_PROCESSING_SUCCESSES: Result = try_create_int_counter( + "Count of all sync messages submitted for processing", + ) +}); +pub static SYNC_MESSAGE_PROCESSING_SUCCESSES: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "beacon_sync_committee_message_processing_successes_total", - "Number of sync messages verified for gossip" - ); - pub static ref SYNC_MESSAGE_GOSSIP_VERIFICATION_TIMES: Result = try_create_histogram( - "beacon_sync_committee_message_gossip_verification_seconds", - "Full runtime of sync contribution gossip verification" - ); - pub static ref SYNC_MESSAGE_EQUIVOCATIONS: Result = try_create_int_counter( + "Number of sync messages verified for gossip", + ) +}); +pub static SYNC_MESSAGE_GOSSIP_VERIFICATION_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_sync_committee_message_gossip_verification_seconds", + "Full runtime of sync contribution gossip verification", + ) + }); +pub static SYNC_MESSAGE_EQUIVOCATIONS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "sync_message_equivocations_total", - "Number of sync messages with the same validator index for different blocks" - ); - pub static ref SYNC_MESSAGE_EQUIVOCATIONS_TO_HEAD: Result = try_create_int_counter( + "Number of sync messages with the same validator index for different blocks", + ) +}); +pub static SYNC_MESSAGE_EQUIVOCATIONS_TO_HEAD: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "sync_message_equivocations_to_head_total", - "Number of sync message which conflict with a previous message but elect the head" - ); + "Number of sync message which conflict with a previous message but elect the head", + ) +}); - /* - * Sync Committee Contribution Verification - */ - pub static ref SYNC_CONTRIBUTION_PROCESSING_REQUESTS: Result = try_create_int_counter( - "beacon_sync_contribution_processing_requests_total", - "Count of all sync contributions submitted for processing" - ); - pub static ref SYNC_CONTRIBUTION_PROCESSING_SUCCESSES: Result = try_create_int_counter( - "beacon_sync_contribution_processing_successes_total", - "Number of sync contributions verified for gossip" - ); - pub static ref SYNC_CONTRIBUTION_GOSSIP_VERIFICATION_TIMES: Result = try_create_histogram( - "beacon_sync_contribution_gossip_verification_seconds", - "Full runtime of sync contribution gossip verification" - ); +/* + * Sync Committee Contribution Verification + */ +pub static SYNC_CONTRIBUTION_PROCESSING_REQUESTS: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_sync_contribution_processing_requests_total", + "Count of all sync contributions submitted for processing", + ) + }); +pub static SYNC_CONTRIBUTION_PROCESSING_SUCCESSES: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_sync_contribution_processing_successes_total", + "Number of sync contributions verified for gossip", + ) + }); +pub static SYNC_CONTRIBUTION_GOSSIP_VERIFICATION_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_sync_contribution_gossip_verification_seconds", + "Full runtime of sync contribution gossip verification", + ) + }); - /* - * General Sync Committee Contribution Processing - */ - pub static ref SYNC_CONTRIBUTION_PROCESSING_APPLY_TO_AGG_POOL: Result = try_create_histogram( - "beacon_sync_contribution_processing_apply_to_agg_pool", - "Time spent applying a sync contribution to the naive aggregation pool" - ); - pub static ref SYNC_CONTRIBUTION_PROCESSING_AGG_POOL_PRUNE: Result = try_create_histogram( - "beacon_sync_contribution_processing_agg_pool_prune", - "Time spent for the agg pool to prune" - ); - pub static ref SYNC_CONTRIBUTION_PROCESSING_AGG_POOL_INSERT: Result = try_create_histogram( - "beacon_sync_contribution_processing_agg_pool_insert", - "Time spent for the outer pool.insert() function of agg pool" - ); - pub static ref SYNC_CONTRIBUTION_PROCESSING_AGG_POOL_CORE_INSERT: Result = try_create_histogram( - "beacon_sync_contribution_processing_agg_pool_core_insert", - "Time spent for the core map.insert() function of agg pool" - ); - pub static ref SYNC_CONTRIBUTION_PROCESSING_AGG_POOL_AGGREGATION: Result = try_create_histogram( - "beacon_sync_contribution_processing_agg_pool_aggregation", - "Time spent doing signature aggregation when adding to the agg poll" - ); - pub static ref SYNC_CONTRIBUTION_PROCESSING_AGG_POOL_CREATE_MAP: Result = try_create_histogram( - "beacon_sync_contribution_processing_agg_pool_create_map", - "Time spent for creating a map for a new slot" - ); - pub static ref SYNC_CONTRIBUTION_PROCESSING_APPLY_TO_OP_POOL: Result = try_create_histogram( - "beacon_sync_contribution_processing_apply_to_op_pool", - "Time spent applying a sync contribution to the block inclusion pool" - ); - pub static ref SYNC_CONTRIBUTION_PROCESSING_SIGNATURE_SETUP_TIMES: Result = try_create_histogram( +/* + * General Sync Committee Contribution Processing + */ +pub static SYNC_CONTRIBUTION_PROCESSING_APPLY_TO_AGG_POOL: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_sync_contribution_processing_apply_to_agg_pool", + "Time spent applying a sync contribution to the naive aggregation pool", + ) + }); +pub static SYNC_CONTRIBUTION_PROCESSING_AGG_POOL_PRUNE: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_sync_contribution_processing_agg_pool_prune", + "Time spent for the agg pool to prune", + ) + }); +pub static SYNC_CONTRIBUTION_PROCESSING_AGG_POOL_INSERT: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_sync_contribution_processing_agg_pool_insert", + "Time spent for the outer pool.insert() function of agg pool", + ) + }); +pub static SYNC_CONTRIBUTION_PROCESSING_AGG_POOL_CORE_INSERT: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_sync_contribution_processing_agg_pool_core_insert", + "Time spent for the core map.insert() function of agg pool", + ) + }); +pub static SYNC_CONTRIBUTION_PROCESSING_AGG_POOL_AGGREGATION: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_sync_contribution_processing_agg_pool_aggregation", + "Time spent doing signature aggregation when adding to the agg poll", + ) + }); +pub static SYNC_CONTRIBUTION_PROCESSING_AGG_POOL_CREATE_MAP: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_sync_contribution_processing_agg_pool_create_map", + "Time spent for creating a map for a new slot", + ) + }); +pub static SYNC_CONTRIBUTION_PROCESSING_APPLY_TO_OP_POOL: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_sync_contribution_processing_apply_to_op_pool", + "Time spent applying a sync contribution to the block inclusion pool", + ) + }); +pub static SYNC_CONTRIBUTION_PROCESSING_SIGNATURE_SETUP_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( "beacon_sync_contribution_processing_signature_setup_seconds", "Time spent on setting up for the signature verification of sync contribution processing" - ); - pub static ref SYNC_CONTRIBUTION_PROCESSING_SIGNATURE_TIMES: Result = try_create_histogram( - "beacon_sync_contribution_processing_signature_seconds", - "Time spent on the signature verification of sync contribution processing" - ); + ) + }); +pub static SYNC_CONTRIBUTION_PROCESSING_SIGNATURE_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_sync_contribution_processing_signature_seconds", + "Time spent on the signature verification of sync contribution processing", + ) + }); - /* - * General Sync Committee Contribution Processing - */ - pub static ref SYNC_MESSAGE_PROCESSING_SIGNATURE_SETUP_TIMES: Result = try_create_histogram( - "beacon_sync_committee_message_processing_signature_setup_seconds", - "Time spent on setting up for the signature verification of sync message processing" - ); - pub static ref SYNC_MESSAGE_PROCESSING_SIGNATURE_TIMES: Result = try_create_histogram( - "beacon_sync_committee_message_processing_signature_seconds", - "Time spent on the signature verification of sync message processing" - ); +/* + * General Sync Committee Contribution Processing + */ +pub static SYNC_MESSAGE_PROCESSING_SIGNATURE_SETUP_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_sync_committee_message_processing_signature_setup_seconds", + "Time spent on setting up for the signature verification of sync message processing", + ) + }); +pub static SYNC_MESSAGE_PROCESSING_SIGNATURE_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_sync_committee_message_processing_signature_seconds", + "Time spent on the signature verification of sync message processing", + ) + }); - /* - * Checkpoint sync & backfill - */ - pub static ref BACKFILL_SIGNATURE_SETUP_TIMES: Result = try_create_histogram( +/* + * Checkpoint sync & backfill + */ +pub static BACKFILL_SIGNATURE_SETUP_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_backfill_signature_setup_seconds", - "Time spent constructing the signature set during backfill sync" - ); - pub static ref BACKFILL_SIGNATURE_VERIFY_TIMES: Result = try_create_histogram( + "Time spent constructing the signature set during backfill sync", + ) +}); +pub static BACKFILL_SIGNATURE_VERIFY_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_backfill_signature_verify_seconds", - "Time spent verifying the signature set during backfill sync" - ); - pub static ref BACKFILL_SIGNATURE_TOTAL_TIMES: Result = try_create_histogram( + "Time spent verifying the signature set during backfill sync", + ) +}); +pub static BACKFILL_SIGNATURE_TOTAL_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_backfill_signature_total_seconds", - "Time spent verifying the signature set during backfill sync, including setup" - ); + "Time spent verifying the signature set during backfill sync, including setup", + ) +}); - /* - * Pre-finalization block cache. - */ - pub static ref PRE_FINALIZATION_BLOCK_CACHE_SIZE: Result = - try_create_int_gauge( - "beacon_pre_finalization_block_cache_size", - "Number of pre-finalization block roots cached for quick rejection" - ); - pub static ref PRE_FINALIZATION_BLOCK_LOOKUP_COUNT: Result = - try_create_int_gauge( - "beacon_pre_finalization_block_lookup_count", - "Number of block roots subject to single block lookups" - ); +/* + * Pre-finalization block cache. + */ +pub static PRE_FINALIZATION_BLOCK_CACHE_SIZE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_pre_finalization_block_cache_size", + "Number of pre-finalization block roots cached for quick rejection", + ) +}); +pub static PRE_FINALIZATION_BLOCK_LOOKUP_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "beacon_pre_finalization_block_lookup_count", + "Number of block roots subject to single block lookups", + ) +}); - /* - * Blob sidecar Verification - */ - pub static ref BLOBS_SIDECAR_PROCESSING_REQUESTS: Result = try_create_int_counter( - "beacon_blobs_sidecar_processing_requests_total", - "Count of all blob sidecars submitted for processing" - ); - pub static ref BLOBS_SIDECAR_PROCESSING_SUCCESSES: Result = try_create_int_counter( - "beacon_blobs_sidecar_processing_successes_total", - "Number of blob sidecars verified for gossip" - ); - pub static ref BLOBS_SIDECAR_GOSSIP_VERIFICATION_TIMES: Result = try_create_histogram( - "beacon_blobs_sidecar_gossip_verification_seconds", - "Full runtime of blob sidecars gossip verification" - ); - pub static ref BLOB_SIDECAR_INCLUSION_PROOF_VERIFICATION: Result = try_create_histogram( - "blob_sidecar_inclusion_proof_verification_seconds", - "Time taken to verify blob sidecar inclusion proof" - ); - pub static ref BLOB_SIDECAR_INCLUSION_PROOF_COMPUTATION: Result = try_create_histogram( - "blob_sidecar_inclusion_proof_computation_seconds", - "Time taken to compute blob sidecar inclusion proof" - ); - pub static ref DATA_COLUMN_SIDECAR_PROCESSING_REQUESTS: Result = try_create_int_counter( - "beacon_data_column_sidecar_processing_requests_total", - "Count of all data column sidecars submitted for processing" - ); - pub static ref DATA_COLUMN_SIDECAR_PROCESSING_SUCCESSES: Result = try_create_int_counter( - "beacon_data_column_sidecar_processing_successes_total", - "Number of data column sidecars verified for gossip" - ); - pub static ref DATA_COLUMN_SIDECAR_GOSSIP_VERIFICATION_TIMES: Result = try_create_histogram( - "beacon_data_column_sidecar_gossip_verification_seconds", - "Full runtime of data column sidecars gossip verification" - ); -} - -// Fifth lazy-static block is used to account for macro recursion limit. -lazy_static! { - /* - * Light server message verification - */ - pub static ref FINALITY_UPDATE_PROCESSING_SUCCESSES: Result = try_create_int_counter( - "light_client_finality_update_verification_success_total", - "Number of light client finality updates verified for gossip" - ); - /* - * Light server message verification - */ - pub static ref OPTIMISTIC_UPDATE_PROCESSING_SUCCESSES: Result = try_create_int_counter( - "light_client_optimistic_update_verification_success_total", - "Number of light client optimistic updates verified for gossip" - ); - /* - * Aggregate subset metrics - */ - pub static ref SYNC_CONTRIBUTION_SUBSETS: Result = try_create_int_counter( - "beacon_sync_contribution_subsets_total", - "Count of new sync contributions that are subsets of already known aggregates" - ); - pub static ref AGGREGATED_ATTESTATION_SUBSETS: Result = try_create_int_counter( - "beacon_aggregated_attestation_subsets_total", - "Count of new aggregated attestations that are subsets of already known aggregates" - ); - /* - * Attestation simulator metrics - */ - pub static ref VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_HIT: Result = +/* + * Blob sidecar Verification + */ +pub static BLOBS_SIDECAR_PROCESSING_REQUESTS: LazyLock> = LazyLock::new(|| { try_create_int_counter( - VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_HIT_TOTAL, - "Incremented if a validator is flagged as a previous slot head attester \ + "beacon_blobs_sidecar_processing_requests_total", + "Count of all blob sidecars submitted for processing", + ) +}); +pub static BLOBS_SIDECAR_PROCESSING_SUCCESSES: LazyLock> = LazyLock::new(|| { + try_create_int_counter( + "beacon_blobs_sidecar_processing_successes_total", + "Number of blob sidecars verified for gossip", + ) +}); +pub static BLOBS_SIDECAR_GOSSIP_VERIFICATION_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_blobs_sidecar_gossip_verification_seconds", + "Full runtime of blob sidecars gossip verification", + ) + }); +pub static BLOB_SIDECAR_INCLUSION_PROOF_VERIFICATION: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "blob_sidecar_inclusion_proof_verification_seconds", + "Time taken to verify blob sidecar inclusion proof", + ) + }); +pub static BLOB_SIDECAR_INCLUSION_PROOF_COMPUTATION: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "blob_sidecar_inclusion_proof_computation_seconds", + "Time taken to compute blob sidecar inclusion proof", + ) + }); +pub static DATA_COLUMN_SIDECAR_PROCESSING_REQUESTS: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_data_column_sidecar_processing_requests_total", + "Count of all data column sidecars submitted for processing", + ) + }); +pub static DATA_COLUMN_SIDECAR_PROCESSING_SUCCESSES: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_data_column_sidecar_processing_successes_total", + "Number of data column sidecars verified for gossip", + ) + }); +pub static DATA_COLUMN_SIDECAR_GOSSIP_VERIFICATION_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_data_column_sidecar_gossip_verification_seconds", + "Full runtime of data column sidecars gossip verification", + ) + }); + +/* + * Light server message verification + */ +pub static FINALITY_UPDATE_PROCESSING_SUCCESSES: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "light_client_finality_update_verification_success_total", + "Number of light client finality updates verified for gossip", + ) + }); +/* + * Light server message verification + */ +pub static OPTIMISTIC_UPDATE_PROCESSING_SUCCESSES: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "light_client_optimistic_update_verification_success_total", + "Number of light client optimistic updates verified for gossip", + ) + }); +/* + * Aggregate subset metrics + */ +pub static SYNC_CONTRIBUTION_SUBSETS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( + "beacon_sync_contribution_subsets_total", + "Count of new sync contributions that are subsets of already known aggregates", + ) +}); +pub static AGGREGATED_ATTESTATION_SUBSETS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( + "beacon_aggregated_attestation_subsets_total", + "Count of new aggregated attestations that are subsets of already known aggregates", + ) +}); +/* + * Attestation simulator metrics + */ +pub static VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_HIT: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_HIT_TOTAL, + "Incremented if a validator is flagged as a previous slot head attester \ during per slot processing", - ); - pub static ref VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_MISS: Result = + ) + }); +pub static VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_MISS: LazyLock< + Result, +> = LazyLock::new(|| { try_create_int_counter( VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_MISS_TOTAL, "Incremented if a validator is not flagged as a previous slot head attester \ during per slot processing", - ); - pub static ref VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_TARGET_ATTESTER_HIT: Result = + ) +}); +pub static VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_TARGET_ATTESTER_HIT: LazyLock< + Result, +> = LazyLock::new(|| { try_create_int_counter( VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_TARGET_ATTESTER_HIT_TOTAL, "Incremented if a validator is flagged as a previous slot target attester \ during per slot processing", - ); - pub static ref VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_TARGET_ATTESTER_MISS: Result = + ) +}); +pub static VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_TARGET_ATTESTER_MISS: LazyLock< + Result, +> = LazyLock::new(|| { try_create_int_counter( VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_TARGET_ATTESTER_MISS_TOTAL, "Incremented if a validator is not flagged as a previous slot target attester \ during per slot processing", - ); - pub static ref VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_HIT: Result = + ) +}); +pub static VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_HIT: LazyLock< + Result, +> = LazyLock::new(|| { try_create_int_counter( VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_HIT_TOTAL, "Incremented if a validator is flagged as a previous slot source attester \ during per slot processing", - ); - pub static ref VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_MISS: Result = + ) +}); +pub static VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_MISS: LazyLock< + Result, +> = LazyLock::new(|| { try_create_int_counter( VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_MISS_TOTAL, "Incremented if a validator is not flagged as a previous slot source attester \ during per slot processing", - ); - /* - * Missed block metrics - */ - pub static ref VALIDATOR_MONITOR_MISSED_BLOCKS_TOTAL: Result = try_create_int_counter_vec( - "validator_monitor_missed_blocks_total", - "Number of non-finalized blocks missed", - &["validator"] - ); + ) +}); +/* + * Missed block metrics + */ +pub static VALIDATOR_MONITOR_MISSED_BLOCKS_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "validator_monitor_missed_blocks_total", + "Number of non-finalized blocks missed", + &["validator"], + ) + }); - /* - * Kzg related metrics - */ - pub static ref KZG_VERIFICATION_SINGLE_TIMES: Result = - try_create_histogram("kzg_verification_single_seconds", "Runtime of single kzg verification"); - pub static ref KZG_VERIFICATION_BATCH_TIMES: Result = - try_create_histogram("kzg_verification_batch_seconds", "Runtime of batched kzg verification"); +/* + * Kzg related metrics + */ +pub static KZG_VERIFICATION_SINGLE_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( + "kzg_verification_single_seconds", + "Runtime of single kzg verification", + ) +}); +pub static KZG_VERIFICATION_BATCH_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( + "kzg_verification_batch_seconds", + "Runtime of batched kzg verification", + ) +}); - pub static ref BLOCK_PRODUCTION_BLOBS_VERIFICATION_TIMES: Result = try_create_histogram( +pub static BLOCK_PRODUCTION_BLOBS_VERIFICATION_TIMES: LazyLock> = LazyLock::new( + || { + try_create_histogram( "beacon_block_production_blobs_verification_seconds", "Time taken to verify blobs against commitments and creating BlobSidecar objects in block production" - ); - /* - * Availability related metrics - */ - pub static ref BLOCK_AVAILABILITY_DELAY: Result = try_create_int_gauge( + ) + }, +); +/* + * Availability related metrics + */ +pub static BLOCK_AVAILABILITY_DELAY: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "block_availability_delay", "Duration between start of the slot and the time at which all components of the block are available.", - ); + ) +}); - /* - * Data Availability cache metrics - */ - pub static ref DATA_AVAILABILITY_OVERFLOW_MEMORY_BLOCK_CACHE_SIZE: Result = +/* + * Data Availability cache metrics + */ +pub static DATA_AVAILABILITY_OVERFLOW_MEMORY_BLOCK_CACHE_SIZE: LazyLock> = + LazyLock::new(|| { try_create_int_gauge( "data_availability_overflow_memory_block_cache_size", - "Number of entries in the data availability overflow block memory cache." - ); - pub static ref DATA_AVAILABILITY_OVERFLOW_MEMORY_STATE_CACHE_SIZE: Result = + "Number of entries in the data availability overflow block memory cache.", + ) + }); +pub static DATA_AVAILABILITY_OVERFLOW_MEMORY_STATE_CACHE_SIZE: LazyLock> = + LazyLock::new(|| { try_create_int_gauge( "data_availability_overflow_memory_state_cache_size", - "Number of entries in the data availability overflow state memory cache." - ); - pub static ref DATA_AVAILABILITY_OVERFLOW_STORE_CACHE_SIZE: Result = + "Number of entries in the data availability overflow state memory cache.", + ) + }); +pub static DATA_AVAILABILITY_OVERFLOW_STORE_CACHE_SIZE: LazyLock> = + LazyLock::new(|| { try_create_int_gauge( "data_availability_overflow_store_cache_size", - "Number of entries in the data availability overflow store cache." - ); + "Number of entries in the data availability overflow store cache.", + ) + }); - /* - * light_client server metrics - */ - pub static ref LIGHT_CLIENT_SERVER_CACHE_STATE_DATA_TIMES: Result = try_create_histogram( - "beacon_light_client_server_cache_state_data_seconds", - "Time taken to produce and cache state data", - ); - pub static ref LIGHT_CLIENT_SERVER_CACHE_RECOMPUTE_UPDATES_TIMES: Result = try_create_histogram( - "beacon_light_client_server_cache_recompute_updates_seconds", - "Time taken to recompute and cache updates", - ); - pub static ref LIGHT_CLIENT_SERVER_CACHE_PREV_BLOCK_CACHE_MISS: Result = try_create_int_counter( - "beacon_light_client_server_cache_prev_block_cache_miss", - "Count of prev block cache misses", - ); -} +/* + * light_client server metrics + */ +pub static LIGHT_CLIENT_SERVER_CACHE_STATE_DATA_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_light_client_server_cache_state_data_seconds", + "Time taken to produce and cache state data", + ) + }); +pub static LIGHT_CLIENT_SERVER_CACHE_RECOMPUTE_UPDATES_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_light_client_server_cache_recompute_updates_seconds", + "Time taken to recompute and cache updates", + ) + }); +pub static LIGHT_CLIENT_SERVER_CACHE_PREV_BLOCK_CACHE_MISS: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_light_client_server_cache_prev_block_cache_miss", + "Count of prev block cache misses", + ) + }); /// Scrape the `beacon_chain` for metrics that are not constantly updated (e.g., the present slot, /// head state info, etc) and update the Prometheus `DEFAULT_REGISTRY`. diff --git a/beacon_node/beacon_chain/src/test_utils.rs b/beacon_node/beacon_chain/src/test_utils.rs index 4e33f1661b..87a3eeb359 100644 --- a/beacon_node/beacon_chain/src/test_utils.rs +++ b/beacon_node/beacon_chain/src/test_utils.rs @@ -31,7 +31,6 @@ use futures::channel::mpsc::Receiver; pub use genesis::{interop_genesis_state_with_eth1, DEFAULT_ETH1_BLOCK_HASH}; use int_to_bytes::int_to_bytes32; use kzg::{Kzg, TrustedSetup}; -use lazy_static::lazy_static; use merkle_proof::MerkleTree; use operation_pool::ReceivedPreCapella; use parking_lot::Mutex; @@ -52,7 +51,7 @@ use std::collections::{HashMap, HashSet}; use std::fmt; use std::str::FromStr; use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use std::time::Duration; use store::{config::StoreConfig, HotColdDB, ItemStore, LevelDB, MemoryStore}; use task_executor::TaskExecutor; @@ -75,15 +74,13 @@ pub const FORK_NAME_ENV_VAR: &str = "FORK_NAME"; // a different value. pub const DEFAULT_TARGET_AGGREGATORS: u64 = u64::MAX; -lazy_static! { - pub static ref KZG: Arc = { - let trusted_setup: TrustedSetup = serde_json::from_reader(TRUSTED_SETUP_BYTES) - .map_err(|e| format!("Unable to read trusted setup file: {}", e)) - .expect("should have trusted setup"); - let kzg = Kzg::new_from_trusted_setup(trusted_setup).expect("should create kzg"); - Arc::new(kzg) - }; -} +pub static KZG: LazyLock> = LazyLock::new(|| { + let trusted_setup: TrustedSetup = serde_json::from_reader(TRUSTED_SETUP_BYTES) + .map_err(|e| format!("Unable to read trusted setup file: {}", e)) + .expect("should have trusted setup"); + let kzg = Kzg::new_from_trusted_setup(trusted_setup).expect("should create kzg"); + Arc::new(kzg) +}); pub type BaseHarnessType = Witness, E, THotStore, TColdStore>; diff --git a/beacon_node/beacon_chain/tests/attestation_production.rs b/beacon_node/beacon_chain/tests/attestation_production.rs index 697e449dc6..e1f2cbb284 100644 --- a/beacon_node/beacon_chain/tests/attestation_production.rs +++ b/beacon_node/beacon_chain/tests/attestation_production.rs @@ -5,8 +5,7 @@ use beacon_chain::block_verification_types::RpcBlock; use beacon_chain::test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy}; use beacon_chain::validator_monitor::UNAGGREGATED_ATTESTATION_LAG_SLOTS; use beacon_chain::{metrics, StateSkipConfig, WhenSlotSkipped}; -use lazy_static::lazy_static; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use tree_hash::TreeHash; use types::{ AggregateSignature, Attestation, EthSpec, Keypair, MainnetEthSpec, RelativeEpoch, Slot, @@ -14,10 +13,9 @@ use types::{ pub const VALIDATOR_COUNT: usize = 16; -lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); -} +/// A cached set of keys. +static KEYPAIRS: LazyLock> = + LazyLock::new(|| types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT)); /// This test builds a chain that is testing the performance of the unaggregated attestations /// produced by the attestation simulator service. diff --git a/beacon_node/beacon_chain/tests/attestation_verification.rs b/beacon_node/beacon_chain/tests/attestation_verification.rs index 19efe10c6d..a52437e003 100644 --- a/beacon_node/beacon_chain/tests/attestation_verification.rs +++ b/beacon_node/beacon_chain/tests/attestation_verification.rs @@ -14,11 +14,11 @@ use beacon_chain::{ }; use genesis::{interop_genesis_state, DEFAULT_ETH1_BLOCK_HASH}; use int_to_bytes::int_to_bytes32; -use lazy_static::lazy_static; use ssz_types::BitVector; use state_processing::{ per_block_processing::errors::AttestationValidationError, per_slot_processing, }; +use std::sync::LazyLock; use tree_hash::TreeHash; use types::{ signed_aggregate_and_proof::SignedAggregateAndProofRefMut, @@ -36,10 +36,9 @@ pub const VALIDATOR_COUNT: usize = 256; pub const CAPELLA_FORK_EPOCH: usize = 1; -lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); -} +/// A cached set of keys. +static KEYPAIRS: LazyLock> = + LazyLock::new(|| types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT)); /// Returns a beacon chain harness. fn get_harness(validator_count: usize) -> BeaconChainHarness> { diff --git a/beacon_node/beacon_chain/tests/block_verification.rs b/beacon_node/beacon_chain/tests/block_verification.rs index d9c9a3b6a7..046a3468af 100644 --- a/beacon_node/beacon_chain/tests/block_verification.rs +++ b/beacon_node/beacon_chain/tests/block_verification.rs @@ -11,7 +11,6 @@ use beacon_chain::{ BeaconSnapshot, BlockError, ChainConfig, ChainSegmentResult, IntoExecutionPendingBlock, NotifyExecutionLayer, }; -use lazy_static::lazy_static; use logging::test_logger; use slasher::{Config as SlasherConfig, Slasher}; use state_processing::{ @@ -20,7 +19,7 @@ use state_processing::{ per_slot_processing, BlockProcessingError, ConsensusContext, VerifyBlockRoot, }; use std::marker::PhantomData; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use tempfile::tempdir; use types::{test_utils::generate_deterministic_keypair, *}; @@ -31,10 +30,9 @@ const VALIDATOR_COUNT: usize = 24; const CHAIN_SEGMENT_LENGTH: usize = 64 * 5; const BLOCK_INDICES: &[usize] = &[0, 1, 32, 64, 68 + 1, 129, CHAIN_SEGMENT_LENGTH - 1]; -lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); -} +/// A cached set of keys. +static KEYPAIRS: LazyLock> = + LazyLock::new(|| types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT)); async fn get_chain_segment() -> (Vec>, Vec>>) { let harness = get_harness(VALIDATOR_COUNT); diff --git a/beacon_node/beacon_chain/tests/op_verification.rs b/beacon_node/beacon_chain/tests/op_verification.rs index 40910b9b9f..2f8fb6d2bc 100644 --- a/beacon_node/beacon_chain/tests/op_verification.rs +++ b/beacon_node/beacon_chain/tests/op_verification.rs @@ -9,23 +9,20 @@ use beacon_chain::{ }, BeaconChainError, }; -use lazy_static::lazy_static; use sloggers::{null::NullLoggerBuilder, Build}; use state_processing::per_block_processing::errors::{ AttesterSlashingInvalid, BlockOperationError, ExitInvalid, ProposerSlashingInvalid, }; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use store::{LevelDB, StoreConfig}; use tempfile::{tempdir, TempDir}; use types::*; pub const VALIDATOR_COUNT: usize = 24; -lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = - types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); -} +/// A cached set of keys. +static KEYPAIRS: LazyLock> = + LazyLock::new(|| types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT)); type E = MinimalEthSpec; type TestHarness = BeaconChainHarness>; diff --git a/beacon_node/beacon_chain/tests/rewards.rs b/beacon_node/beacon_chain/tests/rewards.rs index 1c80525223..f04f4062f1 100644 --- a/beacon_node/beacon_chain/tests/rewards.rs +++ b/beacon_node/beacon_chain/tests/rewards.rs @@ -1,6 +1,7 @@ #![cfg(test)] use std::collections::HashMap; +use std::sync::LazyLock; use beacon_chain::test_utils::{ generate_deterministic_keypairs, BeaconChainHarness, EphemeralHarnessType, @@ -12,7 +13,6 @@ use beacon_chain::{ use eth2::lighthouse::attestation_rewards::TotalAttestationRewards; use eth2::lighthouse::StandardAttestationRewards; use eth2::types::ValidatorId; -use lazy_static::lazy_static; use types::beacon_state::Error as BeaconStateError; use types::{BeaconState, ChainSpec, ForkName, Slot}; @@ -20,9 +20,8 @@ pub const VALIDATOR_COUNT: usize = 64; type E = MinimalEthSpec; -lazy_static! { - static ref KEYPAIRS: Vec = generate_deterministic_keypairs(VALIDATOR_COUNT); -} +static KEYPAIRS: LazyLock> = + LazyLock::new(|| generate_deterministic_keypairs(VALIDATOR_COUNT)); fn get_harness(spec: ChainSpec) -> BeaconChainHarness> { let harness = BeaconChainHarness::builder(E::default()) diff --git a/beacon_node/beacon_chain/tests/store_tests.rs b/beacon_node/beacon_chain/tests/store_tests.rs index e675d6956e..12f2702822 100644 --- a/beacon_node/beacon_chain/tests/store_tests.rs +++ b/beacon_node/beacon_chain/tests/store_tests.rs @@ -14,7 +14,6 @@ use beacon_chain::{ migrate::MigratorConfig, BeaconChain, BeaconChainError, BeaconChainTypes, BeaconSnapshot, BlockError, ChainConfig, NotifyExecutionLayer, ServerSentEventHandler, WhenSlotSkipped, }; -use lazy_static::lazy_static; use logging::test_logger; use maplit::hashset; use rand::Rng; @@ -23,7 +22,7 @@ use state_processing::{state_advance::complete_state_advance, BlockReplayer}; use std::collections::HashMap; use std::collections::HashSet; use std::convert::TryInto; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use std::time::Duration; use store::chunked_vector::Chunk; use store::metadata::{SchemaVersion, CURRENT_SCHEMA_VERSION, STATE_UPPER_LIMIT_NO_RETAIN}; @@ -42,10 +41,9 @@ use types::*; pub const LOW_VALIDATOR_COUNT: usize = 24; pub const HIGH_VALIDATOR_COUNT: usize = 64; -lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = types::test_utils::generate_deterministic_keypairs(HIGH_VALIDATOR_COUNT); -} +/// A cached set of keys. +static KEYPAIRS: LazyLock> = + LazyLock::new(|| types::test_utils::generate_deterministic_keypairs(HIGH_VALIDATOR_COUNT)); type E = MinimalEthSpec; type TestHarness = BeaconChainHarness>; diff --git a/beacon_node/beacon_chain/tests/sync_committee_verification.rs b/beacon_node/beacon_chain/tests/sync_committee_verification.rs index 242ed55847..5cbb26ffbf 100644 --- a/beacon_node/beacon_chain/tests/sync_committee_verification.rs +++ b/beacon_node/beacon_chain/tests/sync_committee_verification.rs @@ -3,12 +3,12 @@ use beacon_chain::sync_committee_verification::{Error as SyncCommitteeError, SyncCommitteeData}; use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType, RelativeSyncCommittee}; use int_to_bytes::int_to_bytes32; -use lazy_static::lazy_static; use safe_arith::SafeArith; use state_processing::{ per_block_processing::{altair::sync_committee::process_sync_aggregate, VerifySignatures}, state_advance::complete_state_advance, }; +use std::sync::LazyLock; use store::{SignedContributionAndProof, SyncCommitteeMessage}; use tree_hash::TreeHash; use types::consts::altair::SYNC_COMMITTEE_SUBNET_COUNT; @@ -21,10 +21,9 @@ pub type E = MainnetEthSpec; pub const VALIDATOR_COUNT: usize = 256; -lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); -} +/// A cached set of keys. +static KEYPAIRS: LazyLock> = + LazyLock::new(|| types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT)); /// Returns a beacon chain harness. fn get_harness(validator_count: usize) -> BeaconChainHarness> { diff --git a/beacon_node/beacon_chain/tests/tests.rs b/beacon_node/beacon_chain/tests/tests.rs index 2a0854e78f..7ae34ccf38 100644 --- a/beacon_node/beacon_chain/tests/tests.rs +++ b/beacon_node/beacon_chain/tests/tests.rs @@ -8,9 +8,9 @@ use beacon_chain::{ }, BeaconChain, ChainConfig, NotifyExecutionLayer, StateSkipConfig, WhenSlotSkipped, }; -use lazy_static::lazy_static; use operation_pool::PersistedOperationPool; use state_processing::{per_slot_processing, per_slot_processing::Error as SlotProcessingError}; +use std::sync::LazyLock; use types::{ BeaconState, BeaconStateError, BlockImportSource, EthSpec, Hash256, Keypair, MinimalEthSpec, RelativeEpoch, Slot, @@ -19,10 +19,9 @@ use types::{ // Should ideally be divisible by 3. pub const VALIDATOR_COUNT: usize = 48; -lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); -} +/// A cached set of keys. +static KEYPAIRS: LazyLock> = + LazyLock::new(|| types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT)); fn get_harness(validator_count: usize) -> BeaconChainHarness> { let harness = BeaconChainHarness::builder(MinimalEthSpec) diff --git a/beacon_node/beacon_chain/tests/validator_monitor.rs b/beacon_node/beacon_chain/tests/validator_monitor.rs index ea9ef73575..c2c03baff0 100644 --- a/beacon_node/beacon_chain/tests/validator_monitor.rs +++ b/beacon_node/beacon_chain/tests/validator_monitor.rs @@ -2,17 +2,16 @@ use beacon_chain::test_utils::{ AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType, }; use beacon_chain::validator_monitor::{ValidatorMonitorConfig, MISSED_BLOCK_LAG_SLOTS}; -use lazy_static::lazy_static; use logging::test_logger; +use std::sync::LazyLock; use types::{Epoch, EthSpec, Keypair, MainnetEthSpec, PublicKeyBytes, Slot}; // Should ideally be divisible by 3. pub const VALIDATOR_COUNT: usize = 48; -lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); -} +/// A cached set of keys. +static KEYPAIRS: LazyLock> = + LazyLock::new(|| types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT)); type E = MainnetEthSpec; diff --git a/beacon_node/beacon_processor/Cargo.toml b/beacon_node/beacon_processor/Cargo.toml index 3373dd1c72..554010be07 100644 --- a/beacon_node/beacon_processor/Cargo.toml +++ b/beacon_node/beacon_processor/Cargo.toml @@ -16,7 +16,6 @@ task_executor = { workspace = true } slot_clock = { workspace = true } lighthouse_network = { workspace = true } types = { workspace = true } -lazy_static = { workspace = true } lighthouse_metrics = { workspace = true } parking_lot = { workspace = true } num_cpus = { workspace = true } diff --git a/beacon_node/beacon_processor/src/metrics.rs b/beacon_node/beacon_processor/src/metrics.rs index bcd422b357..56105f1e10 100644 --- a/beacon_node/beacon_processor/src/metrics.rs +++ b/beacon_node/beacon_processor/src/metrics.rs @@ -1,165 +1,253 @@ pub use lighthouse_metrics::*; +use std::sync::LazyLock; -lazy_static::lazy_static! { - - /* - * Gossip processor - */ - pub static ref BEACON_PROCESSOR_WORK_EVENTS_RX_COUNT: Result = try_create_int_counter_vec( - "beacon_processor_work_events_rx_count", - "Count of work events received (but not necessarily processed)", - &["type"] - ); - pub static ref BEACON_PROCESSOR_WORK_EVENTS_IGNORED_COUNT: Result = try_create_int_counter_vec( - "beacon_processor_work_events_ignored_count", - "Count of work events purposefully ignored", - &["type"] - ); - pub static ref BEACON_PROCESSOR_WORK_EVENTS_STARTED_COUNT: Result = try_create_int_counter_vec( - "beacon_processor_work_events_started_count", - "Count of work events which have been started by a worker", - &["type"] - ); - pub static ref BEACON_PROCESSOR_WORKER_TIME: Result = try_create_histogram_vec( +/* + * Gossip processor + */ +pub static BEACON_PROCESSOR_WORK_EVENTS_RX_COUNT: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "beacon_processor_work_events_rx_count", + "Count of work events received (but not necessarily processed)", + &["type"], + ) + }); +pub static BEACON_PROCESSOR_WORK_EVENTS_IGNORED_COUNT: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "beacon_processor_work_events_ignored_count", + "Count of work events purposefully ignored", + &["type"], + ) + }); +pub static BEACON_PROCESSOR_WORK_EVENTS_STARTED_COUNT: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "beacon_processor_work_events_started_count", + "Count of work events which have been started by a worker", + &["type"], + ) + }); +pub static BEACON_PROCESSOR_WORKER_TIME: LazyLock> = LazyLock::new(|| { + try_create_histogram_vec( "beacon_processor_worker_time", "Time taken for a worker to fully process some parcel of work.", - &["type"] - ); - pub static ref BEACON_PROCESSOR_WORKERS_SPAWNED_TOTAL: Result = try_create_int_counter( - "beacon_processor_workers_spawned_total", - "The number of workers ever spawned by the gossip processing pool." - ); - pub static ref BEACON_PROCESSOR_WORKERS_ACTIVE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_workers_active_total", - "Count of active workers in the gossip processing pool." - ); - pub static ref BEACON_PROCESSOR_IDLE_EVENTS_TOTAL: Result = try_create_int_counter( + &["type"], + ) +}); +pub static BEACON_PROCESSOR_WORKERS_SPAWNED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_workers_spawned_total", + "The number of workers ever spawned by the gossip processing pool.", + ) + }); +pub static BEACON_PROCESSOR_WORKERS_ACTIVE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_workers_active_total", + "Count of active workers in the gossip processing pool.", + ) + }); +pub static BEACON_PROCESSOR_IDLE_EVENTS_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "beacon_processor_idle_events_total", - "Count of idle events processed by the gossip processor manager." - ); - pub static ref BEACON_PROCESSOR_EVENT_HANDLING_SECONDS: Result = try_create_histogram( - "beacon_processor_event_handling_seconds", - "Time spent handling a new message and allocating it to a queue or worker." - ); - // Gossip blocks. - pub static ref BEACON_PROCESSOR_GOSSIP_BLOCK_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_gossip_block_queue_total", - "Count of blocks from gossip waiting to be verified." - ); - // Gossip blobs. - pub static ref BEACON_PROCESSOR_GOSSIP_BLOB_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_gossip_blob_queue_total", - "Count of blobs from gossip waiting to be verified." - ); - // Gossip data column sidecars. - pub static ref BEACON_PROCESSOR_GOSSIP_DATA_COLUMN_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_gossip_data_column_queue_total", - "Count of data column sidecars from gossip waiting to be verified." - ); - // Gossip Exits. - pub static ref BEACON_PROCESSOR_EXIT_QUEUE_TOTAL: Result = try_create_int_gauge( + "Count of idle events processed by the gossip processor manager.", + ) +}); +pub static BEACON_PROCESSOR_EVENT_HANDLING_SECONDS: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "beacon_processor_event_handling_seconds", + "Time spent handling a new message and allocating it to a queue or worker.", + ) + }); +// Gossip blocks. +pub static BEACON_PROCESSOR_GOSSIP_BLOCK_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_gossip_block_queue_total", + "Count of blocks from gossip waiting to be verified.", + ) + }); +// Gossip blobs. +pub static BEACON_PROCESSOR_GOSSIP_BLOB_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_gossip_blob_queue_total", + "Count of blobs from gossip waiting to be verified.", + ) + }); +// Gossip data column sidecars. +pub static BEACON_PROCESSOR_GOSSIP_DATA_COLUMN_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_gossip_data_column_queue_total", + "Count of data column sidecars from gossip waiting to be verified.", + ) + }); +// Gossip Exits. +pub static BEACON_PROCESSOR_EXIT_QUEUE_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "beacon_processor_exit_queue_total", - "Count of exits from gossip waiting to be verified." - ); - // Gossip proposer slashings. - pub static ref BEACON_PROCESSOR_PROPOSER_SLASHING_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_proposer_slashing_queue_total", - "Count of proposer slashings from gossip waiting to be verified." - ); - // Gossip attester slashings. - pub static ref BEACON_PROCESSOR_ATTESTER_SLASHING_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_attester_slashing_queue_total", - "Count of attester slashings from gossip waiting to be verified." - ); - // Gossip BLS to execution changes. - pub static ref BEACON_PROCESSOR_BLS_TO_EXECUTION_CHANGE_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_bls_to_execution_change_queue_total", - "Count of address changes from gossip waiting to be verified." - ); - // Rpc blocks. - pub static ref BEACON_PROCESSOR_RPC_BLOCK_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_rpc_block_queue_total", - "Count of blocks from the rpc waiting to be verified." - ); - // Rpc blobs. - pub static ref BEACON_PROCESSOR_RPC_BLOB_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_rpc_blob_queue_total", - "Count of blobs from the rpc waiting to be verified." - ); - // Chain segments. - pub static ref BEACON_PROCESSOR_CHAIN_SEGMENT_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_chain_segment_queue_total", - "Count of chain segments from the rpc waiting to be verified." - ); - pub static ref BEACON_PROCESSOR_BACKFILL_CHAIN_SEGMENT_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_backfill_chain_segment_queue_total", - "Count of backfill chain segments from the rpc waiting to be verified." - ); - // Unaggregated attestations. - pub static ref BEACON_PROCESSOR_UNAGGREGATED_ATTESTATION_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_unaggregated_attestation_queue_total", - "Count of unagg. attestations waiting to be processed." - ); - // Aggregated attestations. - pub static ref BEACON_PROCESSOR_AGGREGATED_ATTESTATION_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_aggregated_attestation_queue_total", - "Count of agg. attestations waiting to be processed." - ); - // Sync committee messages. - pub static ref BEACON_PROCESSOR_SYNC_MESSAGE_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_sync_message_queue_total", - "Count of sync committee messages waiting to be processed." - ); - // Sync contribution. - pub static ref BEACON_PROCESSOR_SYNC_CONTRIBUTION_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_sync_contribution_queue_total", - "Count of sync committee contributions waiting to be processed." - ); - // HTTP API requests. - pub static ref BEACON_PROCESSOR_API_REQUEST_P0_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_api_request_p0_queue_total", - "Count of P0 HTTP requesets waiting to be processed." - ); - pub static ref BEACON_PROCESSOR_API_REQUEST_P1_QUEUE_TOTAL: Result = try_create_int_gauge( - "beacon_processor_api_request_p1_queue_total", - "Count of P1 HTTP requesets waiting to be processed." - ); + "Count of exits from gossip waiting to be verified.", + ) +}); +// Gossip proposer slashings. +pub static BEACON_PROCESSOR_PROPOSER_SLASHING_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_proposer_slashing_queue_total", + "Count of proposer slashings from gossip waiting to be verified.", + ) + }); +// Gossip attester slashings. +pub static BEACON_PROCESSOR_ATTESTER_SLASHING_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_attester_slashing_queue_total", + "Count of attester slashings from gossip waiting to be verified.", + ) + }); +// Gossip BLS to execution changes. +pub static BEACON_PROCESSOR_BLS_TO_EXECUTION_CHANGE_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_bls_to_execution_change_queue_total", + "Count of address changes from gossip waiting to be verified.", + ) + }); +// Rpc blocks. +pub static BEACON_PROCESSOR_RPC_BLOCK_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_rpc_block_queue_total", + "Count of blocks from the rpc waiting to be verified.", + ) + }); +// Rpc blobs. +pub static BEACON_PROCESSOR_RPC_BLOB_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_rpc_blob_queue_total", + "Count of blobs from the rpc waiting to be verified.", + ) + }); +// Chain segments. +pub static BEACON_PROCESSOR_CHAIN_SEGMENT_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_chain_segment_queue_total", + "Count of chain segments from the rpc waiting to be verified.", + ) + }); +pub static BEACON_PROCESSOR_BACKFILL_CHAIN_SEGMENT_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_backfill_chain_segment_queue_total", + "Count of backfill chain segments from the rpc waiting to be verified.", + ) + }); +// Unaggregated attestations. +pub static BEACON_PROCESSOR_UNAGGREGATED_ATTESTATION_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_unaggregated_attestation_queue_total", + "Count of unagg. attestations waiting to be processed.", + ) + }); +// Aggregated attestations. +pub static BEACON_PROCESSOR_AGGREGATED_ATTESTATION_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_aggregated_attestation_queue_total", + "Count of agg. attestations waiting to be processed.", + ) + }); +// Sync committee messages. +pub static BEACON_PROCESSOR_SYNC_MESSAGE_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_sync_message_queue_total", + "Count of sync committee messages waiting to be processed.", + ) + }); +// Sync contribution. +pub static BEACON_PROCESSOR_SYNC_CONTRIBUTION_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_sync_contribution_queue_total", + "Count of sync committee contributions waiting to be processed.", + ) + }); +// HTTP API requests. +pub static BEACON_PROCESSOR_API_REQUEST_P0_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_api_request_p0_queue_total", + "Count of P0 HTTP requesets waiting to be processed.", + ) + }); +pub static BEACON_PROCESSOR_API_REQUEST_P1_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_processor_api_request_p1_queue_total", + "Count of P1 HTTP requesets waiting to be processed.", + ) + }); - /* - * Attestation reprocessing queue metrics. - */ - pub static ref BEACON_PROCESSOR_REPROCESSING_QUEUE_TOTAL: Result = +/* + * Attestation reprocessing queue metrics. + */ +pub static BEACON_PROCESSOR_REPROCESSING_QUEUE_TOTAL: LazyLock> = + LazyLock::new(|| { try_create_int_gauge_vec( - "beacon_processor_reprocessing_queue_total", - "Count of items in a reprocessing queue.", - &["type"] - ); - pub static ref BEACON_PROCESSOR_REPROCESSING_QUEUE_EXPIRED_ATTESTATIONS: Result = try_create_int_counter( + "beacon_processor_reprocessing_queue_total", + "Count of items in a reprocessing queue.", + &["type"], + ) + }); +pub static BEACON_PROCESSOR_REPROCESSING_QUEUE_EXPIRED_ATTESTATIONS: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( "beacon_processor_reprocessing_queue_expired_attestations", "Number of queued attestations which have expired before a matching block has been found." - ); - pub static ref BEACON_PROCESSOR_REPROCESSING_QUEUE_MATCHED_ATTESTATIONS: Result = try_create_int_counter( - "beacon_processor_reprocessing_queue_matched_attestations", - "Number of queued attestations where as matching block has been imported." - ); + ) + }); +pub static BEACON_PROCESSOR_REPROCESSING_QUEUE_MATCHED_ATTESTATIONS: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_reprocessing_queue_matched_attestations", + "Number of queued attestations where as matching block has been imported.", + ) + }); - /* - * Light client update reprocessing queue metrics. - */ - pub static ref BEACON_PROCESSOR_REPROCESSING_QUEUE_EXPIRED_OPTIMISTIC_UPDATES: Result = try_create_int_counter( +/* + * Light client update reprocessing queue metrics. + */ +pub static BEACON_PROCESSOR_REPROCESSING_QUEUE_EXPIRED_OPTIMISTIC_UPDATES: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_counter( "beacon_processor_reprocessing_queue_expired_optimistic_updates", "Number of queued light client optimistic updates which have expired before a matching block has been found." - ); - pub static ref BEACON_PROCESSOR_REPROCESSING_QUEUE_MATCHED_OPTIMISTIC_UPDATES: Result = try_create_int_counter( + ) +}); +pub static BEACON_PROCESSOR_REPROCESSING_QUEUE_MATCHED_OPTIMISTIC_UPDATES: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_counter( "beacon_processor_reprocessing_queue_matched_optimistic_updates", "Number of queued light client optimistic updates where as matching block has been imported." - ); + ) +}); - /// Errors and Debugging Stats - pub static ref BEACON_PROCESSOR_SEND_ERROR_PER_WORK_TYPE: Result = +/// Errors and Debugging Stats +pub static BEACON_PROCESSOR_SEND_ERROR_PER_WORK_TYPE: LazyLock> = + LazyLock::new(|| { try_create_int_counter_vec( "beacon_processor_send_error_per_work_type", "Total number of beacon processor send error per work type", - &["type"] - ); -} + &["type"], + ) + }); diff --git a/beacon_node/client/Cargo.toml b/beacon_node/client/Cargo.toml index 4ac035d17b..88ae650e72 100644 --- a/beacon_node/client/Cargo.toml +++ b/beacon_node/client/Cargo.toml @@ -31,7 +31,6 @@ sensitive_url = { workspace = true } genesis = { workspace = true } task_executor = { workspace = true } environment = { workspace = true } -lazy_static = { workspace = true } lighthouse_metrics = { workspace = true } time = "0.3.5" directory = { workspace = true } diff --git a/beacon_node/client/src/metrics.rs b/beacon_node/client/src/metrics.rs index f1027bb821..ebc4fe70a7 100644 --- a/beacon_node/client/src/metrics.rs +++ b/beacon_node/client/src/metrics.rs @@ -1,19 +1,23 @@ -use lazy_static::lazy_static; pub use lighthouse_metrics::*; +use std::sync::LazyLock; -lazy_static! { - pub static ref SYNC_SLOTS_PER_SECOND: Result = try_create_int_gauge( +pub static SYNC_SLOTS_PER_SECOND: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "sync_slots_per_second", - "The number of blocks being imported per second" - ); + "The number of blocks being imported per second", + ) +}); - pub static ref IS_SYNCED: Result = try_create_int_gauge( +pub static IS_SYNCED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "sync_eth2_synced", "Metric to check if the beacon chain is synced to head. 0 if not synced and non-zero if synced" - ); + ) +}); - pub static ref NOTIFIER_HEAD_SLOT: Result = try_create_int_gauge( +pub static NOTIFIER_HEAD_SLOT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "notifier_head_slot", - "The head slot sourced from the beacon chain notifier" - ); -} + "The head slot sourced from the beacon chain notifier", + ) +}); diff --git a/beacon_node/eth1/Cargo.toml b/beacon_node/eth1/Cargo.toml index 2ffca4a571..6733c5bfd3 100644 --- a/beacon_node/eth1/Cargo.toml +++ b/beacon_node/eth1/Cargo.toml @@ -25,7 +25,6 @@ superstruct = { workspace = true } tokio = { workspace = true } state_processing = { workspace = true } lighthouse_metrics = { workspace = true } -lazy_static = { workspace = true } task_executor = { workspace = true } eth2 = { workspace = true } sensitive_url = { workspace = true } diff --git a/beacon_node/eth1/src/metrics.rs b/beacon_node/eth1/src/metrics.rs index ad94d42ecb..9a11e7a692 100644 --- a/beacon_node/eth1/src/metrics.rs +++ b/beacon_node/eth1/src/metrics.rs @@ -1,30 +1,41 @@ pub use lighthouse_metrics::*; +use std::sync::LazyLock; -use lazy_static::lazy_static; +/* + * Eth1 blocks + */ +pub static BLOCK_CACHE_LEN: LazyLock> = + LazyLock::new(|| try_create_int_gauge("eth1_block_cache_len", "Count of eth1 blocks in cache")); +pub static LATEST_CACHED_BLOCK_TIMESTAMP: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "eth1_latest_cached_block_timestamp", + "Timestamp of latest block in eth1 cache", + ) +}); -lazy_static! { - /* - * Eth1 blocks - */ - pub static ref BLOCK_CACHE_LEN: Result = - try_create_int_gauge("eth1_block_cache_len", "Count of eth1 blocks in cache"); - pub static ref LATEST_CACHED_BLOCK_TIMESTAMP: Result = - try_create_int_gauge("eth1_latest_cached_block_timestamp", "Timestamp of latest block in eth1 cache"); +/* + * Eth1 deposits + */ +pub static DEPOSIT_CACHE_LEN: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "eth1_deposit_cache_len", + "Number of deposits in the eth1 cache", + ) +}); +pub static HIGHEST_PROCESSED_DEPOSIT_BLOCK: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "eth1_highest_processed_deposit_block", + "Number of the last block checked for deposits", + ) +}); - /* - * Eth1 deposits - */ - pub static ref DEPOSIT_CACHE_LEN: Result = - try_create_int_gauge("eth1_deposit_cache_len", "Number of deposits in the eth1 cache"); - pub static ref HIGHEST_PROCESSED_DEPOSIT_BLOCK: Result = - try_create_int_gauge("eth1_highest_processed_deposit_block", "Number of the last block checked for deposits"); +/* + * Eth1 rpc connection + */ - /* - * Eth1 rpc connection - */ - - pub static ref ETH1_CONNECTED: Result = try_create_int_gauge( - "sync_eth1_connected", "Set to 1 if connected to an eth1 node, otherwise set to 0" - ); - -} +pub static ETH1_CONNECTED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "sync_eth1_connected", + "Set to 1 if connected to an eth1 node, otherwise set to 0", + ) +}); diff --git a/beacon_node/execution_layer/Cargo.toml b/beacon_node/execution_layer/Cargo.toml index f9f599c769..0009cd002e 100644 --- a/beacon_node/execution_layer/Cargo.toml +++ b/beacon_node/execution_layer/Cargo.toml @@ -36,7 +36,6 @@ tempfile = { workspace = true } rand = { workspace = true } zeroize = { workspace = true } lighthouse_metrics = { workspace = true } -lazy_static = { workspace = true } ethers-core = { workspace = true } builder_client = { path = "../builder_client" } fork_choice = { workspace = true } diff --git a/beacon_node/execution_layer/src/engine_api/http.rs b/beacon_node/execution_layer/src/engine_api/http.rs index 1c03cc81fc..ecaf9c6c23 100644 --- a/beacon_node/execution_layer/src/engine_api/http.rs +++ b/beacon_node/execution_layer/src/engine_api/http.rs @@ -3,13 +3,13 @@ use super::*; use crate::auth::Auth; use crate::json_structures::*; -use lazy_static::lazy_static; use lighthouse_version::{COMMIT_PREFIX, VERSION}; use reqwest::header::CONTENT_TYPE; use sensitive_url::SensitiveUrl; use serde::de::DeserializeOwned; use serde_json::json; use std::collections::HashSet; +use std::sync::LazyLock; use tokio::sync::Mutex; use std::time::{Duration, Instant}; @@ -81,18 +81,17 @@ pub static LIGHTHOUSE_CAPABILITIES: &[&str] = &[ ENGINE_GET_CLIENT_VERSION_V1, ]; -lazy_static! { - /// We opt to initialize the JsonClientVersionV1 rather than the ClientVersionV1 - /// for two reasons: - /// 1. This saves the overhead of converting into Json for every engine call - /// 2. The Json version lacks error checking so we can avoid calling `unwrap()` - pub static ref LIGHTHOUSE_JSON_CLIENT_VERSION: JsonClientVersionV1 = JsonClientVersionV1 { +/// We opt to initialize the JsonClientVersionV1 rather than the ClientVersionV1 +/// for two reasons: +/// 1. This saves the overhead of converting into Json for every engine call +/// 2. The Json version lacks error checking so we can avoid calling `unwrap()` +pub static LIGHTHOUSE_JSON_CLIENT_VERSION: LazyLock = + LazyLock::new(|| JsonClientVersionV1 { code: ClientCode::Lighthouse.to_string(), name: "Lighthouse".to_string(), version: VERSION.replace("Lighthouse/", ""), commit: COMMIT_PREFIX.to_string(), - }; -} + }); /// Contains methods to convert arbitrary bytes to an ETH2 deposit contract object. pub mod deposit_log { diff --git a/beacon_node/execution_layer/src/metrics.rs b/beacon_node/execution_layer/src/metrics.rs index 6aaada3dff..c3da449535 100644 --- a/beacon_node/execution_layer/src/metrics.rs +++ b/beacon_node/execution_layer/src/metrics.rs @@ -1,4 +1,5 @@ pub use lighthouse_metrics::*; +use std::sync::LazyLock; pub const HIT: &str = "hit"; pub const MISS: &str = "miss"; @@ -16,72 +17,109 @@ pub const BUILDER: &str = "builder"; pub const SUCCESS: &str = "success"; pub const FAILURE: &str = "failure"; -lazy_static::lazy_static! { - pub static ref EXECUTION_LAYER_PROPOSER_INSERTED: Result = try_create_int_counter( +pub static EXECUTION_LAYER_PROPOSER_INSERTED: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "execution_layer_proposer_inserted", "Count of times a new proposer is known", - ); - pub static ref EXECUTION_LAYER_PROPOSER_DATA_UPDATED: Result = try_create_int_counter( - "execution_layer_proposer_data_updated", - "Count of times new proposer data is supplied", - ); - pub static ref EXECUTION_LAYER_REQUEST_TIMES: Result = - try_create_histogram_vec_with_buckets( + ) +}); +pub static EXECUTION_LAYER_PROPOSER_DATA_UPDATED: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "execution_layer_proposer_data_updated", + "Count of times new proposer data is supplied", + ) + }); +pub static EXECUTION_LAYER_REQUEST_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram_vec_with_buckets( "execution_layer_request_times", "Duration of calls to ELs", decimal_buckets(-2, 1), - &["method"] - ); - pub static ref EXECUTION_LAYER_PAYLOAD_ATTRIBUTES_LOOKAHEAD: Result = try_create_histogram( + &["method"], + ) +}); +pub static EXECUTION_LAYER_PAYLOAD_ATTRIBUTES_LOOKAHEAD: LazyLock> = + LazyLock::new(|| { + try_create_histogram( "execution_layer_payload_attributes_lookahead", "Duration between an fcU call with PayloadAttributes and when the block should be produced", - ); - pub static ref EXECUTION_LAYER_PRE_PREPARED_PAYLOAD_ID: Result = try_create_int_counter_vec( + ) + }); +pub static EXECUTION_LAYER_PRE_PREPARED_PAYLOAD_ID: LazyLock> = LazyLock::new( + || { + try_create_int_counter_vec( "execution_layer_pre_prepared_payload_id", "Indicates hits or misses for already having prepared a payload id before payload production", &["event"] - ); - pub static ref EXECUTION_LAYER_GET_PAYLOAD_BY_BLOCK_HASH: Result = try_create_histogram( - "execution_layer_get_payload_by_block_hash_time", - "Time to reconstruct a payload from the EE using eth_getBlockByHash" - ); - pub static ref EXECUTION_LAYER_GET_PAYLOAD_BODIES_BY_RANGE: Result = try_create_histogram( - "execution_layer_get_payload_bodies_by_range_time", - "Time to fetch a range of payload bodies from the EE" - ); - pub static ref EXECUTION_LAYER_VERIFY_BLOCK_HASH: Result = try_create_histogram_with_buckets( + ) + }, +); +pub static EXECUTION_LAYER_GET_PAYLOAD_BY_BLOCK_HASH: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "execution_layer_get_payload_by_block_hash_time", + "Time to reconstruct a payload from the EE using eth_getBlockByHash", + ) + }); +pub static EXECUTION_LAYER_GET_PAYLOAD_BODIES_BY_RANGE: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "execution_layer_get_payload_bodies_by_range_time", + "Time to fetch a range of payload bodies from the EE", + ) + }); +pub static EXECUTION_LAYER_VERIFY_BLOCK_HASH: LazyLock> = LazyLock::new(|| { + try_create_histogram_with_buckets( "execution_layer_verify_block_hash_time", "Time to verify the execution block hash in Lighthouse, without the EL", - Ok(vec![10e-6, 50e-6, 100e-6, 500e-6, 1e-3, 5e-3, 10e-3, 50e-3, 100e-3, 500e-3]), - ); - pub static ref EXECUTION_LAYER_PAYLOAD_STATUS: Result = try_create_int_counter_vec( + Ok(vec![ + 10e-6, 50e-6, 100e-6, 500e-6, 1e-3, 5e-3, 10e-3, 50e-3, 100e-3, 500e-3, + ]), + ) +}); +pub static EXECUTION_LAYER_PAYLOAD_STATUS: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "execution_layer_payload_status", "Indicates the payload status returned for a particular method", - &["method", "status"] - ); - pub static ref EXECUTION_LAYER_GET_PAYLOAD_OUTCOME: Result = try_create_int_counter_vec( - "execution_layer_get_payload_outcome", - "The success/failure outcomes from calling get_payload", - &["outcome"] - ); - pub static ref EXECUTION_LAYER_BUILDER_REVEAL_PAYLOAD_OUTCOME: Result = try_create_int_counter_vec( - "execution_layer_builder_reveal_payload_outcome", - "The success/failure outcomes from a builder un-blinding a payload", - &["outcome"] - ); - pub static ref EXECUTION_LAYER_GET_PAYLOAD_SOURCE: Result = try_create_int_counter_vec( - "execution_layer_get_payload_source", - "The source of each payload returned from get_payload", - &["source"] - ); - pub static ref EXECUTION_LAYER_GET_PAYLOAD_BUILDER_REJECTIONS: Result = try_create_int_counter_vec( - "execution_layer_get_payload_builder_rejections", - "The reasons why a payload from a builder was rejected", - &["reason"] - ); - pub static ref EXECUTION_LAYER_PAYLOAD_BIDS: Result = try_create_int_gauge_vec( + &["method", "status"], + ) +}); +pub static EXECUTION_LAYER_GET_PAYLOAD_OUTCOME: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "execution_layer_get_payload_outcome", + "The success/failure outcomes from calling get_payload", + &["outcome"], + ) + }); +pub static EXECUTION_LAYER_BUILDER_REVEAL_PAYLOAD_OUTCOME: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "execution_layer_builder_reveal_payload_outcome", + "The success/failure outcomes from a builder un-blinding a payload", + &["outcome"], + ) + }); +pub static EXECUTION_LAYER_GET_PAYLOAD_SOURCE: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "execution_layer_get_payload_source", + "The source of each payload returned from get_payload", + &["source"], + ) + }); +pub static EXECUTION_LAYER_GET_PAYLOAD_BUILDER_REJECTIONS: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "execution_layer_get_payload_builder_rejections", + "The reasons why a payload from a builder was rejected", + &["reason"], + ) + }); +pub static EXECUTION_LAYER_PAYLOAD_BIDS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "execution_layer_payload_bids", "The gwei bid value of payloads received by local EEs or builders. Only shows values up to i64::MAX.", &["source"] - ); -} + ) +}); diff --git a/beacon_node/execution_layer/src/test_utils/mod.rs b/beacon_node/execution_layer/src/test_utils/mod.rs index 7b00ca9fbc..6fd853975d 100644 --- a/beacon_node/execution_layer/src/test_utils/mod.rs +++ b/beacon_node/execution_layer/src/test_utils/mod.rs @@ -10,7 +10,6 @@ use environment::null_logger; use execution_block_generator::PoWBlock; use handle_rpc::handle_rpc; use kzg::Kzg; -use lazy_static::lazy_static; use parking_lot::{Mutex, RwLock, RwLockWriteGuard}; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -20,7 +19,7 @@ use std::convert::Infallible; use std::future::Future; use std::marker::PhantomData; use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use tokio::{runtime, sync::oneshot}; use types::{EthSpec, ExecutionBlockHash, Uint256}; use warp::{http::StatusCode, Filter, Rejection}; @@ -56,14 +55,13 @@ pub const DEFAULT_ENGINE_CAPABILITIES: EngineCapabilities = EngineCapabilities { get_client_version_v1: true, }; -lazy_static! { - pub static ref DEFAULT_CLIENT_VERSION: JsonClientVersionV1 = JsonClientVersionV1 { +pub static DEFAULT_CLIENT_VERSION: LazyLock = + LazyLock::new(|| JsonClientVersionV1 { code: "MC".to_string(), // "mock client" name: "Mock Execution Client".to_string(), version: "0.1.0".to_string(), commit: "0xabcdef01".to_string(), - }; -} + }); mod execution_block_generator; mod handle_rpc; diff --git a/beacon_node/http_api/Cargo.toml b/beacon_node/http_api/Cargo.toml index b58e0442f7..2c54c1375a 100644 --- a/beacon_node/http_api/Cargo.toml +++ b/beacon_node/http_api/Cargo.toml @@ -21,7 +21,6 @@ eth1 = { workspace = true } state_processing = { workspace = true } lighthouse_version = { workspace = true } lighthouse_metrics = { workspace = true } -lazy_static = { workspace = true } warp_utils = { workspace = true } slot_clock = { workspace = true } ethereum_ssz = { workspace = true } diff --git a/beacon_node/http_api/src/metrics.rs b/beacon_node/http_api/src/metrics.rs index 3eada3a3d4..970eef8dd0 100644 --- a/beacon_node/http_api/src/metrics.rs +++ b/beacon_node/http_api/src/metrics.rs @@ -1,51 +1,41 @@ pub use lighthouse_metrics::*; +use std::sync::LazyLock; -lazy_static::lazy_static! { - pub static ref HTTP_API_PATHS_TOTAL: Result = try_create_int_counter_vec( +pub static HTTP_API_PATHS_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "http_api_paths_total", "Count of HTTP requests received", - &["path"] - ); - pub static ref HTTP_API_STATUS_CODES_TOTAL: Result = try_create_int_counter_vec( + &["path"], + ) +}); +pub static HTTP_API_STATUS_CODES_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "http_api_status_codes_total", "Count of HTTP status codes returned", - &["status"] - ); - pub static ref HTTP_API_PATHS_TIMES: Result = try_create_histogram_vec( + &["status"], + ) +}); +pub static HTTP_API_PATHS_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram_vec( "http_api_paths_times", "Duration to process HTTP requests per path", - &["path"] - ); + &["path"], + ) +}); - pub static ref HTTP_API_BEACON_PROPOSER_CACHE_TIMES: Result = try_create_histogram( - "http_api_beacon_proposer_cache_build_times", - "Duration to process HTTP requests per path", - ); - pub static ref HTTP_API_BEACON_PROPOSER_CACHE_HITS_TOTAL: Result = try_create_int_counter( - "http_api_beacon_proposer_cache_hits_total", - "Count of times the proposer cache has been hit", - ); - pub static ref HTTP_API_BEACON_PROPOSER_CACHE_MISSES_TOTAL: Result = try_create_int_counter( - "http_api_beacon_proposer_cache_misses_total", - "Count of times the proposer cache has been missed", - ); - pub static ref HTTP_API_BLOCK_BROADCAST_DELAY_TIMES: Result = try_create_histogram_vec( - "http_api_block_broadcast_delay_times", - "Time between start of the slot and when the block completed broadcast and processing", - &["provenance"] - ); - pub static ref HTTP_API_BLOCK_GOSSIP_TIMES: Result = try_create_histogram_vec_with_buckets( +pub static HTTP_API_BLOCK_BROADCAST_DELAY_TIMES: LazyLock> = + LazyLock::new(|| { + try_create_histogram_vec( + "http_api_block_broadcast_delay_times", + "Time between start of the slot and when the block completed broadcast and processing", + &["provenance"], + ) + }); +pub static HTTP_API_BLOCK_GOSSIP_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram_vec_with_buckets( "http_api_block_gossip_times", "Time between receiving the block on HTTP and publishing it on gossip", decimal_buckets(-2, 2), - &["provenance"] - ); - pub static ref HTTP_API_BLOCK_PUBLISHED_LATE_TOTAL: Result = try_create_int_counter( - "http_api_block_published_late_total", - "The count of times a block was published beyond more than half way to the attestation deadline" - ); - pub static ref HTTP_API_BLOCK_PUBLISHED_VERY_LATE_TOTAL: Result = try_create_int_counter( - "http_api_block_published_very_late_total", - "The count of times a block was published beyond the attestation deadline" - ); -} + &["provenance"], + ) +}); diff --git a/beacon_node/http_metrics/src/metrics.rs b/beacon_node/http_metrics/src/metrics.rs index e6e06caa84..d68efff432 100644 --- a/beacon_node/http_metrics/src/metrics.rs +++ b/beacon_node/http_metrics/src/metrics.rs @@ -17,7 +17,7 @@ pub fn gather_prometheus_metrics( // - Statically updated: things which are only updated at the time of the scrape (used where we // can avoid cluttering up code with metrics calls). // - // The `lighthouse_metrics` crate has a `DEFAULT_REGISTRY` global singleton (via `lazy_static`) + // The `lighthouse_metrics` crate has a `DEFAULT_REGISTRY` global singleton // which keeps the state of all the metrics. Dynamically updated things will already be // up-to-date in the registry (because they update themselves) however statically updated // things need to be "scraped". diff --git a/beacon_node/lighthouse_network/Cargo.toml b/beacon_node/lighthouse_network/Cargo.toml index 3dfa24d467..cb89d492d1 100644 --- a/beacon_node/lighthouse_network/Cargo.toml +++ b/beacon_node/lighthouse_network/Cargo.toml @@ -20,7 +20,6 @@ futures = { workspace = true } error-chain = { workspace = true } dirs = { workspace = true } fnv = { workspace = true } -lazy_static = { workspace = true } lighthouse_metrics = { workspace = true } smallvec = { workspace = true } tokio-io-timeout = "1" diff --git a/beacon_node/lighthouse_network/src/metrics.rs b/beacon_node/lighthouse_network/src/metrics.rs index 8efed44eb4..9b11fe5a38 100644 --- a/beacon_node/lighthouse_network/src/metrics.rs +++ b/beacon_node/lighthouse_network/src/metrics.rs @@ -1,152 +1,194 @@ pub use lighthouse_metrics::*; +use std::sync::LazyLock; -use lazy_static::lazy_static; - -lazy_static! { - pub static ref NAT_OPEN: Result = try_create_int_gauge_vec( +pub static NAT_OPEN: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "nat_open", "An estimate indicating if the local node is reachable from external nodes", - &["protocol"] - ); - pub static ref ADDRESS_UPDATE_COUNT: Result = try_create_int_counter( + &["protocol"], + ) +}); +pub static ADDRESS_UPDATE_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "libp2p_address_update_total", - "Count of libp2p socked updated events (when our view of our IP address has changed)" - ); - pub static ref PEERS_CONNECTED: Result = try_create_int_gauge( - "libp2p_peers", - "Count of libp2p peers currently connected" - ); + "Count of libp2p socked updated events (when our view of our IP address has changed)", + ) +}); +pub static PEERS_CONNECTED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge("libp2p_peers", "Count of libp2p peers currently connected") +}); - pub static ref PEERS_CONNECTED_MULTI: Result = - try_create_int_gauge_vec("libp2p_peers_multi", "Count of libp2p peers currently connected", &["direction", "transport"]); +pub static PEERS_CONNECTED_MULTI: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( + "libp2p_peers_multi", + "Count of libp2p peers currently connected", + &["direction", "transport"], + ) +}); - pub static ref TCP_PEERS_CONNECTED: Result = try_create_int_gauge( +pub static TCP_PEERS_CONNECTED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "libp2p_tcp_peers", - "Count of libp2p peers currently connected via TCP" - ); + "Count of libp2p peers currently connected via TCP", + ) +}); - pub static ref QUIC_PEERS_CONNECTED: Result = try_create_int_gauge( +pub static QUIC_PEERS_CONNECTED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "libp2p_quic_peers", - "Count of libp2p peers currently connected via QUIC" - ); + "Count of libp2p peers currently connected via QUIC", + ) +}); - pub static ref PEER_CONNECT_EVENT_COUNT: Result = try_create_int_counter( +pub static PEER_CONNECT_EVENT_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "libp2p_peer_connect_event_total", - "Count of libp2p peer connect events (not the current number of connected peers)" - ); - pub static ref PEER_DISCONNECT_EVENT_COUNT: Result = try_create_int_counter( + "Count of libp2p peer connect events (not the current number of connected peers)", + ) +}); +pub static PEER_DISCONNECT_EVENT_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "libp2p_peer_disconnect_event_total", - "Count of libp2p peer disconnect events" - ); - pub static ref DISCOVERY_BYTES: Result = try_create_int_gauge_vec( + "Count of libp2p peer disconnect events", + ) +}); +pub static DISCOVERY_BYTES: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "discovery_bytes", "The number of bytes sent and received in discovery", - &["direction"] - ); - pub static ref DISCOVERY_QUEUE: Result = try_create_int_gauge( + &["direction"], + ) +}); +pub static DISCOVERY_QUEUE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "discovery_queue_size", - "The number of discovery queries awaiting execution" - ); - pub static ref DISCOVERY_REQS: Result = try_create_float_gauge( + "The number of discovery queries awaiting execution", + ) +}); +pub static DISCOVERY_REQS: LazyLock> = LazyLock::new(|| { + try_create_float_gauge( "discovery_requests", - "The number of unsolicited discovery requests per second" - ); - pub static ref DISCOVERY_SESSIONS: Result = try_create_int_gauge( + "The number of unsolicited discovery requests per second", + ) +}); +pub static DISCOVERY_SESSIONS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "discovery_sessions", - "The number of active discovery sessions with peers" - ); + "The number of active discovery sessions with peers", + ) +}); - pub static ref PEERS_PER_CLIENT: Result = try_create_int_gauge_vec( +pub static PEERS_PER_CLIENT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "libp2p_peers_per_client", "The connected peers via client implementation", - &["Client"] - ); - pub static ref FAILED_ATTESTATION_PUBLISHES_PER_SUBNET: Result = + &["Client"], + ) +}); +pub static FAILED_ATTESTATION_PUBLISHES_PER_SUBNET: LazyLock> = + LazyLock::new(|| { try_create_int_gauge_vec( "gossipsub_failed_attestation_publishes_per_subnet", "Failed attestation publishes per subnet", - &["subnet"] - ); - pub static ref FAILED_PUBLISHES_PER_MAIN_TOPIC: Result = try_create_int_gauge_vec( + &["subnet"], + ) + }); +pub static FAILED_PUBLISHES_PER_MAIN_TOPIC: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "gossipsub_failed_publishes_per_main_topic", "Failed gossip publishes", - &["topic_hash"] - ); - pub static ref TOTAL_RPC_ERRORS_PER_CLIENT: Result = try_create_int_counter_vec( + &["topic_hash"], + ) +}); +pub static TOTAL_RPC_ERRORS_PER_CLIENT: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "libp2p_rpc_errors_per_client", "RPC errors per client", - &["client", "rpc_error", "direction"] - ); - pub static ref TOTAL_RPC_REQUESTS: Result = try_create_int_counter_vec( - "libp2p_rpc_requests_total", - "RPC requests total", - &["type"] - ); - pub static ref PEER_ACTION_EVENTS_PER_CLIENT: Result = - try_create_int_counter_vec( - "libp2p_peer_actions_per_client", - "Score reports per client", - &["client", "action", "source"] - ); - pub static ref GOSSIP_UNACCEPTED_MESSAGES_PER_CLIENT: Result = + &["client", "rpc_error", "direction"], + ) +}); +pub static TOTAL_RPC_REQUESTS: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec("libp2p_rpc_requests_total", "RPC requests total", &["type"]) +}); +pub static PEER_ACTION_EVENTS_PER_CLIENT: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( + "libp2p_peer_actions_per_client", + "Score reports per client", + &["client", "action", "source"], + ) +}); +pub static GOSSIP_UNACCEPTED_MESSAGES_PER_CLIENT: LazyLock> = + LazyLock::new(|| { try_create_int_counter_vec( "gossipsub_unaccepted_messages_per_client", "Gossipsub messages that we did not accept, per client", - &["client", "validation_result"] - ); - pub static ref GOSSIP_LATE_PUBLISH_PER_TOPIC_KIND: Result = + &["client", "validation_result"], + ) + }); +pub static GOSSIP_LATE_PUBLISH_PER_TOPIC_KIND: LazyLock> = + LazyLock::new(|| { try_create_int_counter_vec( "gossipsub_late_publish_per_topic_kind", "Messages published late to gossipsub per topic kind.", - &["topic_kind"] - ); - pub static ref GOSSIP_EXPIRED_LATE_PUBLISH_PER_TOPIC_KIND: Result = + &["topic_kind"], + ) + }); +pub static GOSSIP_EXPIRED_LATE_PUBLISH_PER_TOPIC_KIND: LazyLock> = + LazyLock::new(|| { try_create_int_counter_vec( "gossipsub_expired_late_publish_per_topic_kind", "Messages that expired waiting to be published on retry to gossipsub per topic kind.", - &["topic_kind"] - ); - pub static ref GOSSIP_FAILED_LATE_PUBLISH_PER_TOPIC_KIND: Result = + &["topic_kind"], + ) + }); +pub static GOSSIP_FAILED_LATE_PUBLISH_PER_TOPIC_KIND: LazyLock> = + LazyLock::new(|| { try_create_int_counter_vec( "gossipsub_failed_late_publish_per_topic_kind", "Messages that failed to be published on retry to gossipsub per topic kind.", - &["topic_kind"] - ); - pub static ref PEER_SCORE_DISTRIBUTION: Result = - try_create_int_gauge_vec( - "peer_score_distribution", - "The distribution of connected peer scores", - &["position"] - ); - pub static ref PEER_SCORE_PER_CLIENT: Result = - try_create_float_gauge_vec( - "peer_score_per_client", - "Average score per client", - &["client"] - ); + &["topic_kind"], + ) + }); +pub static PEER_SCORE_DISTRIBUTION: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( + "peer_score_distribution", + "The distribution of connected peer scores", + &["position"], + ) +}); +pub static PEER_SCORE_PER_CLIENT: LazyLock> = LazyLock::new(|| { + try_create_float_gauge_vec( + "peer_score_per_client", + "Average score per client", + &["client"], + ) +}); - pub static ref SUBNET_PEERS_FOUND: Result = - try_create_int_counter_vec( - "discovery_query_peers_found", - "Total number of peers found in attestation subnets and sync subnets", - &["type"] - ); - pub static ref TOTAL_SUBNET_QUERIES: Result = - try_create_int_counter_vec( - "discovery_total_queries", - "Total number of discovery subnet queries", - &["type"] - ); +pub static SUBNET_PEERS_FOUND: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( + "discovery_query_peers_found", + "Total number of peers found in attestation subnets and sync subnets", + &["type"], + ) +}); +pub static TOTAL_SUBNET_QUERIES: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( + "discovery_total_queries", + "Total number of discovery subnet queries", + &["type"], + ) +}); - /* - * Peer Reporting - */ - pub static ref REPORT_PEER_MSGS: Result = try_create_int_counter_vec( +/* + * Peer Reporting + */ +pub static REPORT_PEER_MSGS: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "libp2p_report_peer_msgs_total", "Number of peer reports per msg", - &["msg"] - ); -} + &["msg"], + ) +}); pub fn scrape_discovery_metrics() { let metrics = diff --git a/beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs b/beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs index 8187dc4ba4..c8425fc104 100644 --- a/beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs +++ b/beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs @@ -6,15 +6,13 @@ //! //! The scoring algorithms are currently experimental. use crate::service::gossipsub_scoring_parameters::GREYLIST_THRESHOLD as GOSSIPSUB_GREYLIST_THRESHOLD; -use lazy_static::lazy_static; use serde::Serialize; +use std::sync::LazyLock; use std::time::Instant; use strum::AsRefStr; use tokio::time::Duration; -lazy_static! { - static ref HALFLIFE_DECAY: f64 = -(2.0f64.ln()) / SCORE_HALFLIFE; -} +static HALFLIFE_DECAY: LazyLock = LazyLock::new(|| -(2.0f64.ln()) / SCORE_HALFLIFE); /// The default score for new peers. pub(crate) const DEFAULT_SCORE: f64 = 0.0; diff --git a/beacon_node/lighthouse_network/src/rpc/protocol.rs b/beacon_node/lighthouse_network/src/rpc/protocol.rs index bfaaef9b3b..2cdd730a2b 100644 --- a/beacon_node/lighthouse_network/src/rpc/protocol.rs +++ b/beacon_node/lighthouse_network/src/rpc/protocol.rs @@ -3,13 +3,12 @@ use crate::rpc::codec::{base::BaseInboundCodec, ssz_snappy::SSZSnappyInboundCode use futures::future::BoxFuture; use futures::prelude::{AsyncRead, AsyncWrite}; use futures::{FutureExt, StreamExt}; -use lazy_static::lazy_static; use libp2p::core::{InboundUpgrade, UpgradeInfo}; use ssz::Encode; use ssz_types::VariableList; use std::io; use std::marker::PhantomData; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use std::time::Duration; use strum::{AsRefStr, Display, EnumString, IntoStaticStr}; use tokio_io_timeout::TimeoutStream; @@ -18,112 +17,131 @@ use tokio_util::{ compat::{Compat, FuturesAsyncReadCompatExt}, }; use types::{ - BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockBellatrix, BeaconBlockCapella, - BeaconBlockElectra, BlobSidecar, ChainSpec, EmptyBlock, EthSpec, ForkContext, ForkName, - LightClientBootstrap, LightClientBootstrapAltair, LightClientFinalityUpdate, - LightClientFinalityUpdateAltair, LightClientOptimisticUpdate, - LightClientOptimisticUpdateAltair, MainnetEthSpec, Signature, SignedBeaconBlock, + BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockCapella, BeaconBlockElectra, + BlobSidecar, ChainSpec, EmptyBlock, EthSpec, ForkContext, ForkName, LightClientBootstrap, + LightClientBootstrapAltair, LightClientFinalityUpdate, LightClientFinalityUpdateAltair, + LightClientOptimisticUpdate, LightClientOptimisticUpdateAltair, MainnetEthSpec, Signature, + SignedBeaconBlock, }; -lazy_static! { - // Note: Hardcoding the `EthSpec` type for `SignedBeaconBlock` as min/max values is - // same across different `EthSpec` implementations. - pub static ref SIGNED_BEACON_BLOCK_BASE_MIN: usize = SignedBeaconBlock::::from_block( - BeaconBlock::Base(BeaconBlockBase::::empty(&MainnetEthSpec::default_spec())), +// Note: Hardcoding the `EthSpec` type for `SignedBeaconBlock` as min/max values is +// same across different `EthSpec` implementations. +pub static SIGNED_BEACON_BLOCK_BASE_MIN: LazyLock = LazyLock::new(|| { + SignedBeaconBlock::::from_block( + BeaconBlock::Base(BeaconBlockBase::::empty( + &MainnetEthSpec::default_spec(), + )), Signature::empty(), ) .as_ssz_bytes() - .len(); - pub static ref SIGNED_BEACON_BLOCK_BASE_MAX: usize = SignedBeaconBlock::::from_block( + .len() +}); +pub static SIGNED_BEACON_BLOCK_BASE_MAX: LazyLock = LazyLock::new(|| { + SignedBeaconBlock::::from_block( BeaconBlock::Base(BeaconBlockBase::full(&MainnetEthSpec::default_spec())), Signature::empty(), ) .as_ssz_bytes() - .len(); + .len() +}); - pub static ref SIGNED_BEACON_BLOCK_ALTAIR_MIN: usize = SignedBeaconBlock::::from_block( - BeaconBlock::Altair(BeaconBlockAltair::::empty(&MainnetEthSpec::default_spec())), - Signature::empty(), - ) - .as_ssz_bytes() - .len(); - pub static ref SIGNED_BEACON_BLOCK_ALTAIR_MAX: usize = SignedBeaconBlock::::from_block( +pub static SIGNED_BEACON_BLOCK_ALTAIR_MAX: LazyLock = LazyLock::new(|| { + SignedBeaconBlock::::from_block( BeaconBlock::Altair(BeaconBlockAltair::full(&MainnetEthSpec::default_spec())), Signature::empty(), ) .as_ssz_bytes() - .len(); + .len() +}); - pub static ref SIGNED_BEACON_BLOCK_BELLATRIX_MIN: usize = SignedBeaconBlock::::from_block( - BeaconBlock::Bellatrix(BeaconBlockBellatrix::::empty(&MainnetEthSpec::default_spec())), - Signature::empty(), - ) - .as_ssz_bytes() - .len(); - - pub static ref SIGNED_BEACON_BLOCK_CAPELLA_MAX_WITHOUT_PAYLOAD: usize = SignedBeaconBlock::::from_block( +pub static SIGNED_BEACON_BLOCK_CAPELLA_MAX_WITHOUT_PAYLOAD: LazyLock = LazyLock::new(|| { + SignedBeaconBlock::::from_block( BeaconBlock::Capella(BeaconBlockCapella::full(&MainnetEthSpec::default_spec())), Signature::empty(), ) .as_ssz_bytes() - .len(); + .len() +}); - pub static ref SIGNED_BEACON_BLOCK_ELECTRA_MAX_WITHOUT_PAYLOAD: usize = SignedBeaconBlock::::from_block( +pub static SIGNED_BEACON_BLOCK_ELECTRA_MAX_WITHOUT_PAYLOAD: LazyLock = LazyLock::new(|| { + SignedBeaconBlock::::from_block( BeaconBlock::Electra(BeaconBlockElectra::full(&MainnetEthSpec::default_spec())), Signature::empty(), ) .as_ssz_bytes() - .len(); + .len() +}); - /// The `BeaconBlockBellatrix` block has an `ExecutionPayload` field which has a max size ~16 GiB for future proofing. - /// We calculate the value from its fields instead of constructing the block and checking the length. - /// Note: This is only the theoretical upper bound. We further bound the max size we receive over the network - /// with `max_chunk_size`. - pub static ref SIGNED_BEACON_BLOCK_BELLATRIX_MAX: usize = - // Size of a full altair block +/// The `BeaconBlockBellatrix` block has an `ExecutionPayload` field which has a max size ~16 GiB for future proofing. +/// We calculate the value from its fields instead of constructing the block and checking the length. +/// Note: This is only the theoretical upper bound. We further bound the max size we receive over the network +/// with `max_chunk_size`. +pub static SIGNED_BEACON_BLOCK_BELLATRIX_MAX: LazyLock = + LazyLock::new(|| // Size of a full altair block *SIGNED_BEACON_BLOCK_ALTAIR_MAX + types::ExecutionPayload::::max_execution_payload_bellatrix_size() // adding max size of execution payload (~16gb) - + ssz::BYTES_PER_LENGTH_OFFSET; // Adding the additional ssz offset for the `ExecutionPayload` field + + ssz::BYTES_PER_LENGTH_OFFSET); // Adding the additional ssz offset for the `ExecutionPayload` field - pub static ref SIGNED_BEACON_BLOCK_CAPELLA_MAX: usize = *SIGNED_BEACON_BLOCK_CAPELLA_MAX_WITHOUT_PAYLOAD +pub static SIGNED_BEACON_BLOCK_CAPELLA_MAX: LazyLock = LazyLock::new(|| { + *SIGNED_BEACON_BLOCK_CAPELLA_MAX_WITHOUT_PAYLOAD + types::ExecutionPayload::::max_execution_payload_capella_size() // adding max size of execution payload (~16gb) - + ssz::BYTES_PER_LENGTH_OFFSET; // Adding the additional ssz offset for the `ExecutionPayload` field + + ssz::BYTES_PER_LENGTH_OFFSET +}); // Adding the additional ssz offset for the `ExecutionPayload` field - pub static ref SIGNED_BEACON_BLOCK_DENEB_MAX: usize = *SIGNED_BEACON_BLOCK_CAPELLA_MAX_WITHOUT_PAYLOAD +pub static SIGNED_BEACON_BLOCK_DENEB_MAX: LazyLock = LazyLock::new(|| { + *SIGNED_BEACON_BLOCK_CAPELLA_MAX_WITHOUT_PAYLOAD + types::ExecutionPayload::::max_execution_payload_deneb_size() // adding max size of execution payload (~16gb) + ssz::BYTES_PER_LENGTH_OFFSET // Adding the additional offsets for the `ExecutionPayload` + (::ssz_fixed_len() * ::max_blobs_per_block()) - + ssz::BYTES_PER_LENGTH_OFFSET; // Length offset for the blob commitments field. - // - pub static ref SIGNED_BEACON_BLOCK_ELECTRA_MAX: usize = *SIGNED_BEACON_BLOCK_ELECTRA_MAX_WITHOUT_PAYLOAD + + ssz::BYTES_PER_LENGTH_OFFSET +}); // Length offset for the blob commitments field. + // +pub static SIGNED_BEACON_BLOCK_ELECTRA_MAX: LazyLock = LazyLock::new(|| { + *SIGNED_BEACON_BLOCK_ELECTRA_MAX_WITHOUT_PAYLOAD + types::ExecutionPayload::::max_execution_payload_electra_size() // adding max size of execution payload (~16gb) + ssz::BYTES_PER_LENGTH_OFFSET // Adding the additional ssz offset for the `ExecutionPayload` field + (::ssz_fixed_len() * ::max_blobs_per_block()) - + ssz::BYTES_PER_LENGTH_OFFSET; // Length offset for the blob commitments field. + + ssz::BYTES_PER_LENGTH_OFFSET +}); // Length offset for the blob commitments field. - pub static ref ERROR_TYPE_MIN: usize = - VariableList::::from(Vec::::new()) - .as_ssz_bytes() - .len(); - pub static ref ERROR_TYPE_MAX: usize = - VariableList::::from(vec![ - 0u8; - MAX_ERROR_LEN - as usize - ]) - .as_ssz_bytes() - .len(); +pub static ERROR_TYPE_MIN: LazyLock = LazyLock::new(|| { + VariableList::::from(Vec::::new()) + .as_ssz_bytes() + .len() +}); - pub static ref LIGHT_CLIENT_FINALITY_UPDATE_CAPELLA_MAX: usize = LightClientFinalityUpdate::::ssz_max_len_for_fork(ForkName::Capella); - pub static ref LIGHT_CLIENT_FINALITY_UPDATE_DENEB_MAX: usize = LightClientFinalityUpdate::::ssz_max_len_for_fork(ForkName::Deneb); - pub static ref LIGHT_CLIENT_FINALITY_UPDATE_ELECTRA_MAX: usize = LightClientFinalityUpdate::::ssz_max_len_for_fork(ForkName::Electra); - pub static ref LIGHT_CLIENT_OPTIMISTIC_UPDATE_CAPELLA_MAX: usize = LightClientOptimisticUpdate::::ssz_max_len_for_fork(ForkName::Capella); - pub static ref LIGHT_CLIENT_OPTIMISTIC_UPDATE_DENEB_MAX: usize = LightClientOptimisticUpdate::::ssz_max_len_for_fork(ForkName::Deneb); - pub static ref LIGHT_CLIENT_OPTIMISTIC_UPDATE_ELECTRA_MAX: usize = LightClientOptimisticUpdate::::ssz_max_len_for_fork(ForkName::Electra); - pub static ref LIGHT_CLIENT_BOOTSTRAP_CAPELLA_MAX: usize = LightClientBootstrap::::ssz_max_len_for_fork(ForkName::Capella); - pub static ref LIGHT_CLIENT_BOOTSTRAP_DENEB_MAX: usize = LightClientBootstrap::::ssz_max_len_for_fork(ForkName::Deneb); - pub static ref LIGHT_CLIENT_BOOTSTRAP_ELECTRA_MAX: usize = LightClientBootstrap::::ssz_max_len_for_fork(ForkName::Electra); -} +pub static ERROR_TYPE_MAX: LazyLock = LazyLock::new(|| { + VariableList::::from(vec![0u8; MAX_ERROR_LEN as usize]) + .as_ssz_bytes() + .len() +}); + +pub static LIGHT_CLIENT_FINALITY_UPDATE_CAPELLA_MAX: LazyLock = LazyLock::new(|| { + LightClientFinalityUpdate::::ssz_max_len_for_fork(ForkName::Capella) +}); +pub static LIGHT_CLIENT_FINALITY_UPDATE_DENEB_MAX: LazyLock = LazyLock::new(|| { + LightClientFinalityUpdate::::ssz_max_len_for_fork(ForkName::Deneb) +}); +pub static LIGHT_CLIENT_FINALITY_UPDATE_ELECTRA_MAX: LazyLock = LazyLock::new(|| { + LightClientFinalityUpdate::::ssz_max_len_for_fork(ForkName::Electra) +}); +pub static LIGHT_CLIENT_OPTIMISTIC_UPDATE_CAPELLA_MAX: LazyLock = LazyLock::new(|| { + LightClientOptimisticUpdate::::ssz_max_len_for_fork(ForkName::Capella) +}); +pub static LIGHT_CLIENT_OPTIMISTIC_UPDATE_DENEB_MAX: LazyLock = LazyLock::new(|| { + LightClientOptimisticUpdate::::ssz_max_len_for_fork(ForkName::Deneb) +}); +pub static LIGHT_CLIENT_OPTIMISTIC_UPDATE_ELECTRA_MAX: LazyLock = LazyLock::new(|| { + LightClientOptimisticUpdate::::ssz_max_len_for_fork(ForkName::Electra) +}); +pub static LIGHT_CLIENT_BOOTSTRAP_CAPELLA_MAX: LazyLock = LazyLock::new(|| { + LightClientBootstrap::::ssz_max_len_for_fork(ForkName::Capella) +}); +pub static LIGHT_CLIENT_BOOTSTRAP_DENEB_MAX: LazyLock = + LazyLock::new(|| LightClientBootstrap::::ssz_max_len_for_fork(ForkName::Deneb)); +pub static LIGHT_CLIENT_BOOTSTRAP_ELECTRA_MAX: LazyLock = LazyLock::new(|| { + LightClientBootstrap::::ssz_max_len_for_fork(ForkName::Electra) +}); /// The protocol prefix the RPC protocol id. const PROTOCOL_PREFIX: &str = "/eth2/beacon_chain/req"; diff --git a/beacon_node/network/Cargo.toml b/beacon_node/network/Cargo.toml index 0ad7f53ee7..511cbc3e3c 100644 --- a/beacon_node/network/Cargo.toml +++ b/beacon_node/network/Cargo.toml @@ -33,7 +33,6 @@ smallvec = { workspace = true } rand = { workspace = true } fnv = { workspace = true } rlp = "0.5.0" -lazy_static = { workspace = true } lighthouse_metrics = { workspace = true } logging = { workspace = true } task_executor = { workspace = true } diff --git a/beacon_node/network/src/metrics.rs b/beacon_node/network/src/metrics.rs index 0fadb51edb..bb1e546870 100644 --- a/beacon_node/network/src/metrics.rs +++ b/beacon_node/network/src/metrics.rs @@ -5,347 +5,500 @@ use beacon_chain::{ sync_committee_verification::Error as SyncCommitteeError, }; use fnv::FnvHashMap; -use lazy_static::lazy_static; pub use lighthouse_metrics::*; use lighthouse_network::{ peer_manager::peerdb::client::ClientKind, types::GossipKind, GossipTopic, Gossipsub, NetworkGlobals, }; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use strum::IntoEnumIterator; use types::EthSpec; -lazy_static! { +pub static BEACON_BLOCK_MESH_PEERS_PER_CLIENT: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge_vec( + "block_mesh_peers_per_client", + "Number of mesh peers for BeaconBlock topic per client", + &["Client"], + ) + }); - pub static ref BEACON_BLOCK_MESH_PEERS_PER_CLIENT: Result = - try_create_int_gauge_vec( - "block_mesh_peers_per_client", - "Number of mesh peers for BeaconBlock topic per client", - &["Client"] - ); - - pub static ref BEACON_AGGREGATE_AND_PROOF_MESH_PEERS_PER_CLIENT: Result = +pub static BEACON_AGGREGATE_AND_PROOF_MESH_PEERS_PER_CLIENT: LazyLock> = + LazyLock::new(|| { try_create_int_gauge_vec( "beacon_aggregate_and_proof_mesh_peers_per_client", "Number of mesh peers for BeaconAggregateAndProof topic per client", - &["Client"] - ); + &["Client"], + ) + }); - /* - * Attestation subnet subscriptions - */ - pub static ref SUBNET_SUBSCRIPTION_REQUESTS: Result = try_create_int_counter( +/* + * Attestation subnet subscriptions + */ +pub static SUBNET_SUBSCRIPTION_REQUESTS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "validator_attestation_subnet_subscriptions_total", - "Count of validator attestation subscription requests." - ); - pub static ref SUBNET_SUBSCRIPTION_AGGREGATOR_REQUESTS: Result = try_create_int_counter( - "validator_subnet_subscriptions_aggregator_total", - "Count of validator subscription requests where the subscriber is an aggregator." - ); - pub static ref SYNC_COMMITTEE_SUBSCRIPTION_REQUESTS: Result = try_create_int_counter( - "validator_sync_committee_subnet_subscriptions_total", - "Count of validator sync committee subscription requests." - ); + "Count of validator attestation subscription requests.", + ) +}); +pub static SUBNET_SUBSCRIPTION_AGGREGATOR_REQUESTS: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "validator_subnet_subscriptions_aggregator_total", + "Count of validator subscription requests where the subscriber is an aggregator.", + ) + }); +pub static SYNC_COMMITTEE_SUBSCRIPTION_REQUESTS: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "validator_sync_committee_subnet_subscriptions_total", + "Count of validator sync committee subscription requests.", + ) + }); - /* - * Gossip processor - */ +/* + * Gossip processor + */ - // Gossip blocks. - pub static ref BEACON_PROCESSOR_GOSSIP_BLOCK_VERIFIED_TOTAL: Result = try_create_int_counter( - "beacon_processor_gossip_block_verified_total", - "Total number of gossip blocks verified for propagation." - ); - pub static ref BEACON_PROCESSOR_GOSSIP_BLOCK_IMPORTED_TOTAL: Result = try_create_int_counter( - "beacon_processor_gossip_block_imported_total", - "Total number of gossip blocks imported to fork choice, etc." - ); - pub static ref BEACON_PROCESSOR_GOSSIP_BLOCK_REQUEUED_TOTAL: Result = try_create_int_counter( +// Gossip blocks. +pub static BEACON_PROCESSOR_GOSSIP_BLOCK_VERIFIED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_gossip_block_verified_total", + "Total number of gossip blocks verified for propagation.", + ) + }); +pub static BEACON_PROCESSOR_GOSSIP_BLOCK_IMPORTED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_gossip_block_imported_total", + "Total number of gossip blocks imported to fork choice, etc.", + ) + }); +pub static BEACON_PROCESSOR_GOSSIP_BLOCK_REQUEUED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( "beacon_processor_gossip_block_requeued_total", "Total number of gossip blocks that arrived early and were re-queued for later processing." - ); - pub static ref BEACON_PROCESSOR_GOSSIP_BLOCK_EARLY_SECONDS: Result = try_create_histogram( + ) + }); +pub static BEACON_PROCESSOR_GOSSIP_BLOCK_EARLY_SECONDS: LazyLock> = + LazyLock::new(|| { + try_create_histogram( "beacon_processor_gossip_block_early_seconds", "Whenever a gossip block is received early this metrics is set to how early that block was." - ); - pub static ref BEACON_PROCESSOR_GOSSIP_BLOB_VERIFIED_TOTAL: Result = try_create_int_counter( - "beacon_processor_gossip_blob_verified_total", - "Total number of gossip blob verified for propagation." - ); - pub static ref BEACON_PROCESSOR_GOSSIP_DATA_COLUMN_SIDECAR_VERIFIED_TOTAL: Result = try_create_int_counter( + ) + }); +pub static BEACON_PROCESSOR_GOSSIP_BLOB_VERIFIED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_gossip_blob_verified_total", + "Total number of gossip blob verified for propagation.", + ) + }); +pub static BEACON_PROCESSOR_GOSSIP_DATA_COLUMN_SIDECAR_VERIFIED_TOTAL: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_counter( "beacon_processor_gossip_data_column_verified_total", - "Total number of gossip data column sidecar verified for propagation." - ); - // Gossip Exits. - pub static ref BEACON_PROCESSOR_EXIT_VERIFIED_TOTAL: Result = try_create_int_counter( - "beacon_processor_exit_verified_total", - "Total number of voluntary exits verified for propagation." - ); - pub static ref BEACON_PROCESSOR_EXIT_IMPORTED_TOTAL: Result = try_create_int_counter( - "beacon_processor_exit_imported_total", - "Total number of voluntary exits imported to the op pool." - ); - // Gossip proposer slashings. - pub static ref BEACON_PROCESSOR_PROPOSER_SLASHING_VERIFIED_TOTAL: Result = try_create_int_counter( - "beacon_processor_proposer_slashing_verified_total", - "Total number of proposer slashings verified for propagation." - ); - pub static ref BEACON_PROCESSOR_PROPOSER_SLASHING_IMPORTED_TOTAL: Result = try_create_int_counter( - "beacon_processor_proposer_slashing_imported_total", - "Total number of proposer slashings imported to the op pool." - ); - // Gossip attester slashings. - pub static ref BEACON_PROCESSOR_ATTESTER_SLASHING_VERIFIED_TOTAL: Result = try_create_int_counter( - "beacon_processor_attester_slashing_verified_total", - "Total number of attester slashings verified for propagation." - ); - pub static ref BEACON_PROCESSOR_ATTESTER_SLASHING_IMPORTED_TOTAL: Result = try_create_int_counter( - "beacon_processor_attester_slashing_imported_total", - "Total number of attester slashings imported to the op pool." - ); - // Gossip BLS to execution changes. - pub static ref BEACON_PROCESSOR_BLS_TO_EXECUTION_CHANGE_VERIFIED_TOTAL: Result = try_create_int_counter( - "beacon_processor_bls_to_execution_change_verified_total", - "Total number of address changes verified for propagation." - ); - pub static ref BEACON_PROCESSOR_BLS_TO_EXECUTION_CHANGE_IMPORTED_TOTAL: Result = try_create_int_counter( - "beacon_processor_bls_to_execution_change_imported_total", - "Total number of address changes imported to the op pool." - ); -} + "Total number of gossip data column sidecar verified for propagation.", + ) +}); +// Gossip Exits. +pub static BEACON_PROCESSOR_EXIT_VERIFIED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_exit_verified_total", + "Total number of voluntary exits verified for propagation.", + ) + }); +pub static BEACON_PROCESSOR_EXIT_IMPORTED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_exit_imported_total", + "Total number of voluntary exits imported to the op pool.", + ) + }); +// Gossip proposer slashings. +pub static BEACON_PROCESSOR_PROPOSER_SLASHING_VERIFIED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_proposer_slashing_verified_total", + "Total number of proposer slashings verified for propagation.", + ) + }); +pub static BEACON_PROCESSOR_PROPOSER_SLASHING_IMPORTED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_proposer_slashing_imported_total", + "Total number of proposer slashings imported to the op pool.", + ) + }); +// Gossip attester slashings. +pub static BEACON_PROCESSOR_ATTESTER_SLASHING_VERIFIED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_attester_slashing_verified_total", + "Total number of attester slashings verified for propagation.", + ) + }); +pub static BEACON_PROCESSOR_ATTESTER_SLASHING_IMPORTED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_attester_slashing_imported_total", + "Total number of attester slashings imported to the op pool.", + ) + }); +// Gossip BLS to execution changes. +pub static BEACON_PROCESSOR_BLS_TO_EXECUTION_CHANGE_VERIFIED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_bls_to_execution_change_verified_total", + "Total number of address changes verified for propagation.", + ) + }); +pub static BEACON_PROCESSOR_BLS_TO_EXECUTION_CHANGE_IMPORTED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_bls_to_execution_change_imported_total", + "Total number of address changes imported to the op pool.", + ) + }); -// Need to split up this `lazy_static!` due to recursion limits. -lazy_static! { - // Rpc blocks. - pub static ref BEACON_PROCESSOR_RPC_BLOCK_IMPORTED_TOTAL: Result = try_create_int_counter( - "beacon_processor_rpc_block_imported_total", - "Total number of gossip blocks imported to fork choice, etc." - ); - // Chain segments. - pub static ref BEACON_PROCESSOR_CHAIN_SEGMENT_SUCCESS_TOTAL: Result = try_create_int_counter( - "beacon_processor_chain_segment_success_total", - "Total number of chain segments successfully processed." - ); - pub static ref BEACON_PROCESSOR_BACKFILL_CHAIN_SEGMENT_SUCCESS_TOTAL: Result = try_create_int_counter( - "beacon_processor_backfill_chain_segment_success_total", - "Total number of chain segments successfully processed." - ); - pub static ref BEACON_PROCESSOR_CHAIN_SEGMENT_FAILED_TOTAL: Result = try_create_int_counter( - "beacon_processor_chain_segment_failed_total", - "Total number of chain segments that failed processing." - ); - pub static ref BEACON_PROCESSOR_BACKFILL_CHAIN_SEGMENT_FAILED_TOTAL: Result = try_create_int_counter( - "beacon_processor_backfill_chain_segment_failed_total", - "Total number of backfill chain segments that failed processing." - ); - // Unaggregated attestations. - pub static ref BEACON_PROCESSOR_UNAGGREGATED_ATTESTATION_VERIFIED_TOTAL: Result = try_create_int_counter( - "beacon_processor_unaggregated_attestation_verified_total", - "Total number of unaggregated attestations verified for gossip." - ); - pub static ref BEACON_PROCESSOR_UNAGGREGATED_ATTESTATION_IMPORTED_TOTAL: Result = try_create_int_counter( - "beacon_processor_unaggregated_attestation_imported_total", - "Total number of unaggregated attestations imported to fork choice, etc." - ); - pub static ref BEACON_PROCESSOR_UNAGGREGATED_ATTESTATION_REQUEUED_TOTAL: Result = try_create_int_counter( +// Rpc blocks. +pub static BEACON_PROCESSOR_RPC_BLOCK_IMPORTED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_rpc_block_imported_total", + "Total number of gossip blocks imported to fork choice, etc.", + ) + }); +// Chain segments. +pub static BEACON_PROCESSOR_CHAIN_SEGMENT_SUCCESS_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_chain_segment_success_total", + "Total number of chain segments successfully processed.", + ) + }); +pub static BEACON_PROCESSOR_BACKFILL_CHAIN_SEGMENT_SUCCESS_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_backfill_chain_segment_success_total", + "Total number of chain segments successfully processed.", + ) + }); +pub static BEACON_PROCESSOR_CHAIN_SEGMENT_FAILED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_chain_segment_failed_total", + "Total number of chain segments that failed processing.", + ) + }); +pub static BEACON_PROCESSOR_BACKFILL_CHAIN_SEGMENT_FAILED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_backfill_chain_segment_failed_total", + "Total number of backfill chain segments that failed processing.", + ) + }); +// Unaggregated attestations. +pub static BEACON_PROCESSOR_UNAGGREGATED_ATTESTATION_VERIFIED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_unaggregated_attestation_verified_total", + "Total number of unaggregated attestations verified for gossip.", + ) + }); +pub static BEACON_PROCESSOR_UNAGGREGATED_ATTESTATION_IMPORTED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_unaggregated_attestation_imported_total", + "Total number of unaggregated attestations imported to fork choice, etc.", + ) + }); +pub static BEACON_PROCESSOR_UNAGGREGATED_ATTESTATION_REQUEUED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( "beacon_processor_unaggregated_attestation_requeued_total", "Total number of unaggregated attestations that referenced an unknown block and were re-queued." - ); - // Aggregated attestations. - pub static ref BEACON_PROCESSOR_AGGREGATED_ATTESTATION_VERIFIED_TOTAL: Result = try_create_int_counter( - "beacon_processor_aggregated_attestation_verified_total", - "Total number of aggregated attestations verified for gossip." - ); - pub static ref BEACON_PROCESSOR_AGGREGATED_ATTESTATION_IMPORTED_TOTAL: Result = try_create_int_counter( - "beacon_processor_aggregated_attestation_imported_total", - "Total number of aggregated attestations imported to fork choice, etc." - ); - pub static ref BEACON_PROCESSOR_AGGREGATED_ATTESTATION_REQUEUED_TOTAL: Result = try_create_int_counter( + ) + }); +// Aggregated attestations. +pub static BEACON_PROCESSOR_AGGREGATED_ATTESTATION_VERIFIED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_aggregated_attestation_verified_total", + "Total number of aggregated attestations verified for gossip.", + ) + }); +pub static BEACON_PROCESSOR_AGGREGATED_ATTESTATION_IMPORTED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_aggregated_attestation_imported_total", + "Total number of aggregated attestations imported to fork choice, etc.", + ) + }); +pub static BEACON_PROCESSOR_AGGREGATED_ATTESTATION_REQUEUED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( "beacon_processor_aggregated_attestation_requeued_total", "Total number of aggregated attestations that referenced an unknown block and were re-queued." - ); - // Sync committee messages. - pub static ref BEACON_PROCESSOR_SYNC_MESSAGE_VERIFIED_TOTAL: Result = try_create_int_counter( - "beacon_processor_sync_message_verified_total", - "Total number of sync committee messages verified for gossip." - ); - pub static ref BEACON_PROCESSOR_SYNC_MESSAGE_IMPORTED_TOTAL: Result = try_create_int_counter( - "beacon_processor_sync_message_imported_total", - "Total number of sync committee messages imported to fork choice, etc." - ); - // Sync contribution. - pub static ref BEACON_PROCESSOR_SYNC_CONTRIBUTION_VERIFIED_TOTAL: Result = try_create_int_counter( - "beacon_processor_sync_contribution_verified_total", - "Total number of sync committee contributions verified for gossip." - ); + ) + }); +// Sync committee messages. +pub static BEACON_PROCESSOR_SYNC_MESSAGE_VERIFIED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_sync_message_verified_total", + "Total number of sync committee messages verified for gossip.", + ) + }); +pub static BEACON_PROCESSOR_SYNC_MESSAGE_IMPORTED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_sync_message_imported_total", + "Total number of sync committee messages imported to fork choice, etc.", + ) + }); +// Sync contribution. +pub static BEACON_PROCESSOR_SYNC_CONTRIBUTION_VERIFIED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_sync_contribution_verified_total", + "Total number of sync committee contributions verified for gossip.", + ) + }); - pub static ref BEACON_PROCESSOR_SYNC_CONTRIBUTION_IMPORTED_TOTAL: Result = try_create_int_counter( - "beacon_processor_sync_contribution_imported_total", - "Total number of sync committee contributions imported to fork choice, etc." - ); +pub static BEACON_PROCESSOR_SYNC_CONTRIBUTION_IMPORTED_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( + "beacon_processor_sync_contribution_imported_total", + "Total number of sync committee contributions imported to fork choice, etc.", + ) + }); - /// Errors and Debugging Stats - pub static ref GOSSIP_ATTESTATION_ERRORS_PER_TYPE: Result = +/// Errors and Debugging Stats +pub static GOSSIP_ATTESTATION_ERRORS_PER_TYPE: LazyLock> = + LazyLock::new(|| { try_create_int_counter_vec( "gossipsub_attestation_errors_per_type", "Gossipsub attestation errors per error type", - &["type"] - ); - pub static ref GOSSIP_SYNC_COMMITTEE_ERRORS_PER_TYPE: Result = + &["type"], + ) + }); +pub static GOSSIP_SYNC_COMMITTEE_ERRORS_PER_TYPE: LazyLock> = + LazyLock::new(|| { try_create_int_counter_vec( "gossipsub_sync_committee_errors_per_type", "Gossipsub sync_committee errors per error type", - &["type"] - ); - pub static ref GOSSIP_FINALITY_UPDATE_ERRORS_PER_TYPE: Result = + &["type"], + ) + }); +pub static GOSSIP_FINALITY_UPDATE_ERRORS_PER_TYPE: LazyLock> = + LazyLock::new(|| { try_create_int_counter_vec( "gossipsub_light_client_finality_update_errors_per_type", "Gossipsub light_client_finality_update errors per error type", - &["type"] - ); - pub static ref GOSSIP_OPTIMISTIC_UPDATE_ERRORS_PER_TYPE: Result = + &["type"], + ) + }); +pub static GOSSIP_OPTIMISTIC_UPDATE_ERRORS_PER_TYPE: LazyLock> = + LazyLock::new(|| { try_create_int_counter_vec( "gossipsub_light_client_optimistic_update_errors_per_type", "Gossipsub light_client_optimistic_update errors per error type", - &["type"] - ); + &["type"], + ) + }); - - /* - * Network queue metrics - */ - pub static ref NETWORK_RECEIVE_EVENTS: Result = try_create_int_counter_vec( +/* + * Network queue metrics + */ +pub static NETWORK_RECEIVE_EVENTS: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "network_receive_events", "Count of events received by the channel to the network service", - &["type"] - ); - pub static ref NETWORK_RECEIVE_TIMES: Result = try_create_histogram_vec( + &["type"], + ) +}); +pub static NETWORK_RECEIVE_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram_vec( "network_receive_times", "Time taken for network to handle an event sent to the network service.", - &["type"] - ); -} + &["type"], + ) +}); -lazy_static! { - - /* - * Sync related metrics - */ - pub static ref PEERS_PER_SYNC_TYPE: Result = try_create_int_gauge_vec( +/* + * Sync related metrics + */ +pub static PEERS_PER_SYNC_TYPE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "sync_peers_per_status", "Number of connected peers per sync status type", - &["sync_status"] - ); - pub static ref SYNCING_CHAINS_COUNT: Result = try_create_int_gauge_vec( + &["sync_status"], + ) +}); +pub static SYNCING_CHAINS_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "sync_range_chains", "Number of Syncing chains in range, per range type", - &["range_type"] - ); - pub static ref SYNCING_CHAINS_REMOVED: Result = try_create_int_counter_vec( + &["range_type"], + ) +}); +pub static SYNCING_CHAINS_REMOVED: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "sync_range_removed_chains_total", "Total count of range syncing chains removed per range type", - &["range_type"] - ); - pub static ref SYNCING_CHAINS_ADDED: Result = try_create_int_counter_vec( + &["range_type"], + ) +}); +pub static SYNCING_CHAINS_ADDED: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "sync_range_added_chains_total", "Total count of range syncing chains added per range type", - &["range_type"] - ); - pub static ref SYNCING_CHAINS_DROPPED_BLOCKS: Result = try_create_int_counter_vec( + &["range_type"], + ) +}); +pub static SYNCING_CHAINS_DROPPED_BLOCKS: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "sync_range_chains_dropped_blocks_total", "Total count of dropped blocks when removing a syncing chain per range type", - &["range_type"] - ); - pub static ref SYNCING_CHAINS_IGNORED_BLOCKS: Result = try_create_int_counter_vec( + &["range_type"], + ) +}); +pub static SYNCING_CHAINS_IGNORED_BLOCKS: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "sync_range_chains_ignored_blocks_total", "Total count of ignored blocks when processing a syncing chain batch per chain type", - &["chain_type"] - ); - pub static ref SYNCING_CHAINS_PROCESSED_BATCHES: Result = try_create_int_counter_vec( - "sync_range_chains_processed_batches_total", - "Total count of processed batches in a syncing chain batch per chain type", - &["chain_type"] - ); - pub static ref SYNCING_CHAIN_BATCH_AWAITING_PROCESSING: Result = try_create_histogram_with_buckets( - "sync_range_chain_batch_awaiting_processing_seconds", - "Time range sync batches spend in AwaitingProcessing state", - Ok(vec![0.01,0.02,0.05,0.1,0.2,0.5,1.0,2.0,5.0,10.0,20.0]) - ); - pub static ref SYNC_SINGLE_BLOCK_LOOKUPS: Result = try_create_int_gauge( + &["chain_type"], + ) +}); +pub static SYNCING_CHAINS_PROCESSED_BATCHES: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "sync_range_chains_processed_batches_total", + "Total count of processed batches in a syncing chain batch per chain type", + &["chain_type"], + ) + }); +pub static SYNCING_CHAIN_BATCH_AWAITING_PROCESSING: LazyLock> = + LazyLock::new(|| { + try_create_histogram_with_buckets( + "sync_range_chain_batch_awaiting_processing_seconds", + "Time range sync batches spend in AwaitingProcessing state", + Ok(vec![ + 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1.0, 2.0, 5.0, 10.0, 20.0, + ]), + ) + }); +pub static SYNC_SINGLE_BLOCK_LOOKUPS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "sync_single_block_lookups", - "Number of single block lookups underway" - ); - pub static ref SYNC_PARENT_BLOCK_LOOKUPS: Result = try_create_int_gauge( - "sync_parent_block_lookups", - "Number of parent block lookups underway" - ); - pub static ref SYNC_LOOKUP_CREATED: Result = try_create_int_counter( + "Number of single block lookups underway", + ) +}); +pub static SYNC_LOOKUP_CREATED: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "sync_lookups_created_total", "Total count of sync lookups created", - ); - pub static ref SYNC_LOOKUP_DROPPED: Result = try_create_int_counter_vec( + ) +}); +pub static SYNC_LOOKUP_DROPPED: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "sync_lookups_dropped_total", "Total count of sync lookups dropped by reason", - &["reason"] - ); - pub static ref SYNC_LOOKUP_COMPLETED: Result = try_create_int_counter( + &["reason"], + ) +}); +pub static SYNC_LOOKUP_COMPLETED: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "sync_lookups_completed_total", "Total count of sync lookups completed", - ); - pub static ref SYNC_LOOKUPS_STUCK: Result = try_create_int_counter( + ) +}); +pub static SYNC_LOOKUPS_STUCK: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "sync_lookups_stuck_total", "Total count of sync lookups that are stuck and dropped", - ); - pub static ref SYNC_ACTIVE_NETWORK_REQUESTS: Result = try_create_int_gauge_vec( + ) +}); +pub static SYNC_ACTIVE_NETWORK_REQUESTS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "sync_active_network_requests", "Current count of active network requests from sync", &["type"], - ); - pub static ref SYNC_UNKNOWN_NETWORK_REQUESTS: Result = try_create_int_counter_vec( + ) +}); +pub static SYNC_UNKNOWN_NETWORK_REQUESTS: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "sync_unknwon_network_request", "Total count of network messages received for unknown active requests", &["type"], - ); + ) +}); - /* - * Block Delay Metrics - */ - pub static ref BEACON_BLOCK_DELAY_GOSSIP: Result = try_create_int_gauge( +/* + * Block Delay Metrics + */ +pub static BEACON_BLOCK_DELAY_GOSSIP: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "beacon_block_delay_gossip", - "The first time we see this block from gossip as a delay from the start of the slot" - ); - pub static ref BEACON_BLOCK_DELAY_GOSSIP_VERIFICATION: Result = try_create_int_gauge( + "The first time we see this block from gossip as a delay from the start of the slot", + ) +}); +pub static BEACON_BLOCK_DELAY_GOSSIP_VERIFICATION: LazyLock> = LazyLock::new( + || { + try_create_int_gauge( "beacon_block_delay_gossip_verification", "Keeps track of the time delay from the start of the slot to the point we propagate the block" - ); - pub static ref BEACON_BLOCK_DELAY_FULL_VERIFICATION: Result = try_create_int_gauge( + ) + }, +); +pub static BEACON_BLOCK_DELAY_FULL_VERIFICATION: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "beacon_block_delay_full_verification", - "The time it takes to verify a beacon block." - ); + "The time it takes to verify a beacon block.", + ) +}); - pub static ref BEACON_BLOCK_DELAY_GOSSIP_ARRIVED_LATE_TOTAL: Result = try_create_int_counter( +pub static BEACON_BLOCK_DELAY_GOSSIP_ARRIVED_LATE_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter( "beacon_block_delay_gossip_arrived_late_total", "Count of times when a gossip block arrived from the network later than the attestation deadline.", - ); + ) + }); - /* - * Blob Delay Metrics - */ - pub static ref BEACON_BLOB_DELAY_GOSSIP: Result = try_create_int_gauge( +/* + * Blob Delay Metrics + */ +pub static BEACON_BLOB_DELAY_GOSSIP: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "beacon_blob_delay_gossip_last_delay", - "The first time we see this blob as a delay from the start of the slot" - ); + "The first time we see this blob as a delay from the start of the slot", + ) +}); - pub static ref BEACON_BLOB_DELAY_GOSSIP_VERIFICATION: Result = try_create_int_gauge( +pub static BEACON_BLOB_DELAY_GOSSIP_VERIFICATION: LazyLock> = LazyLock::new( + || { + try_create_int_gauge( "beacon_blob_delay_gossip_verification", "Keeps track of the time delay from the start of the slot to the point we propagate the blob" - ); - pub static ref BEACON_BLOB_DELAY_FULL_VERIFICATION: Result = try_create_int_gauge( + ) + }, +); +pub static BEACON_BLOB_DELAY_FULL_VERIFICATION: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "beacon_blob_last_full_verification_delay", - "The time it takes to verify a beacon blob" - ); + "The time it takes to verify a beacon blob", + ) +}); - pub static ref BEACON_BLOB_RPC_SLOT_START_DELAY_TIME: Result = try_create_histogram_with_buckets( +pub static BEACON_BLOB_RPC_SLOT_START_DELAY_TIME: LazyLock> = LazyLock::new( + || { + try_create_histogram_with_buckets( "beacon_blob_rpc_slot_start_delay_time", "Duration between when a blob is received over rpc and the start of the slot it belongs to.", // Create a custom bucket list for greater granularity in block delay @@ -354,37 +507,46 @@ lazy_static! { // [0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50] //decimal_buckets(-1,2) - ); + ) + }, +); - pub static ref BEACON_BLOB_GOSSIP_ARRIVED_LATE_TOTAL: Result = try_create_int_counter( +pub static BEACON_BLOB_GOSSIP_ARRIVED_LATE_TOTAL: LazyLock> = LazyLock::new( + || { + try_create_int_counter( "beacon_blob_gossip_arrived_late_total", "Count of times when a gossip blob arrived from the network later than the attestation deadline.", - ); + ) + }, +); - pub static ref BEACON_DATA_COLUMN_DELAY_GOSSIP: Result = try_create_int_gauge( +pub static BEACON_DATA_COLUMN_DELAY_GOSSIP: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "beacon_data_column_delay_gossip_last_delay", - "The first time we see this data column as a delay from the start of the slot" - ); + "The first time we see this data column as a delay from the start of the slot", + ) +}); - pub static ref BEACON_DATA_COLUMN_DELAY_GOSSIP_VERIFICATION: Result = try_create_int_gauge( +pub static BEACON_DATA_COLUMN_DELAY_GOSSIP_VERIFICATION: LazyLock> = LazyLock::new( + || { + try_create_int_gauge( "beacon_data_column_delay_gossip_verification", "Keeps track of the time delay from the start of the slot to the point we propagate the data column" - ); + ) + }, +); - pub static ref BEACON_DATA_COLUMN_DELAY_FULL_VERIFICATION: Result = try_create_int_gauge( - "beacon_data_column_last_full_verification_delay", - "The time it takes to verify a beacon data column" - ); - - - /* - * Light client update reprocessing queue metrics. - */ - pub static ref BEACON_PROCESSOR_REPROCESSING_QUEUE_SENT_OPTIMISTIC_UPDATES: Result = try_create_int_counter( +/* + * Light client update reprocessing queue metrics. + */ +pub static BEACON_PROCESSOR_REPROCESSING_QUEUE_SENT_OPTIMISTIC_UPDATES: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_counter( "beacon_processor_reprocessing_queue_sent_optimistic_updates", "Number of queued light client optimistic updates where as matching block has been imported." - ); -} + ) +}); pub fn register_finality_update_error(error: &LightClientFinalityUpdateError) { inc_counter_vec(&GOSSIP_FINALITY_UPDATE_ERRORS_PER_TYPE, &[error.as_ref()]); diff --git a/beacon_node/network/src/subnet_service/tests/mod.rs b/beacon_node/network/src/subnet_service/tests/mod.rs index 74f3f59df3..e8d9218ec4 100644 --- a/beacon_node/network/src/subnet_service/tests/mod.rs +++ b/beacon_node/network/src/subnet_service/tests/mod.rs @@ -6,12 +6,11 @@ use beacon_chain::{ }; use futures::prelude::*; use genesis::{generate_deterministic_keypairs, interop_genesis_state, DEFAULT_ETH1_BLOCK_HASH}; -use lazy_static::lazy_static; use lighthouse_network::NetworkConfig; use slog::{o, Drain, Logger}; use sloggers::{null::NullLoggerBuilder, Build}; use slot_clock::{SlotClock, SystemTimeSlotClock}; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use std::time::{Duration, SystemTime}; use store::config::StoreConfig; use store::{HotColdDB, MemoryStore}; @@ -110,9 +109,7 @@ fn get_logger(log_level: Option) -> Logger { } } -lazy_static! { - static ref CHAIN: TestBeaconChain = TestBeaconChain::new_with_system_clock(); -} +static CHAIN: LazyLock = LazyLock::new(TestBeaconChain::new_with_system_clock); fn get_attestation_service( log_level: Option, diff --git a/beacon_node/operation_pool/Cargo.toml b/beacon_node/operation_pool/Cargo.toml index 36595994f0..cbf6284f2a 100644 --- a/beacon_node/operation_pool/Cargo.toml +++ b/beacon_node/operation_pool/Cargo.toml @@ -7,7 +7,6 @@ edition = { workspace = true } [dependencies] derivative = { workspace = true } itertools = { workspace = true } -lazy_static = { workspace = true } lighthouse_metrics = { workspace = true } parking_lot = { workspace = true } types = { workspace = true } diff --git a/beacon_node/operation_pool/src/lib.rs b/beacon_node/operation_pool/src/lib.rs index a1c9ada03a..c60480ef37 100644 --- a/beacon_node/operation_pool/src/lib.rs +++ b/beacon_node/operation_pool/src/lib.rs @@ -797,20 +797,19 @@ mod release_tests { use beacon_chain::test_utils::{ test_spec, BeaconChainHarness, EphemeralHarnessType, RelativeSyncCommittee, }; - use lazy_static::lazy_static; use maplit::hashset; use state_processing::epoch_cache::initialize_epoch_cache; use state_processing::{common::get_attesting_indices_from_state, VerifyOperation}; use std::collections::BTreeSet; + use std::sync::LazyLock; use types::consts::altair::SYNC_COMMITTEE_SUBNET_COUNT; use types::*; pub const MAX_VALIDATOR_COUNT: usize = 4 * 32 * 128; - lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = types::test_utils::generate_deterministic_keypairs(MAX_VALIDATOR_COUNT); - } + /// A cached set of keys. + static KEYPAIRS: LazyLock> = + LazyLock::new(|| types::test_utils::generate_deterministic_keypairs(MAX_VALIDATOR_COUNT)); fn get_harness( validator_count: usize, diff --git a/beacon_node/operation_pool/src/metrics.rs b/beacon_node/operation_pool/src/metrics.rs index 6fd8567cef..e2a8b43ed1 100644 --- a/beacon_node/operation_pool/src/metrics.rs +++ b/beacon_node/operation_pool/src/metrics.rs @@ -1,31 +1,40 @@ -use lazy_static::lazy_static; - pub use lighthouse_metrics::*; +use std::sync::LazyLock; -lazy_static! { - pub static ref BUILD_REWARD_CACHE_TIME: Result = try_create_histogram( +pub static BUILD_REWARD_CACHE_TIME: LazyLock> = LazyLock::new(|| { + try_create_histogram( "op_pool_build_reward_cache_time", - "Time to build the reward cache before packing attestations" - ); - pub static ref ATTESTATION_PREV_EPOCH_PACKING_TIME: Result = try_create_histogram( + "Time to build the reward cache before packing attestations", + ) +}); +pub static ATTESTATION_PREV_EPOCH_PACKING_TIME: LazyLock> = LazyLock::new(|| { + try_create_histogram( "op_pool_attestation_prev_epoch_packing_time", - "Time to pack previous epoch attestations" - ); - pub static ref ATTESTATION_CURR_EPOCH_PACKING_TIME: Result = try_create_histogram( + "Time to pack previous epoch attestations", + ) +}); +pub static ATTESTATION_CURR_EPOCH_PACKING_TIME: LazyLock> = LazyLock::new(|| { + try_create_histogram( "op_pool_attestation_curr_epoch_packing_time", - "Time to pack current epoch attestations" - ); - pub static ref NUM_PREV_EPOCH_ATTESTATIONS: Result = try_create_int_gauge( + "Time to pack current epoch attestations", + ) +}); +pub static NUM_PREV_EPOCH_ATTESTATIONS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "op_pool_prev_epoch_attestations", - "Number of valid attestations considered for packing from the previous epoch" - ); - pub static ref NUM_CURR_EPOCH_ATTESTATIONS: Result = try_create_int_gauge( + "Number of valid attestations considered for packing from the previous epoch", + ) +}); +pub static NUM_CURR_EPOCH_ATTESTATIONS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "op_pool_curr_epoch_attestations", - "Number of valid attestations considered for packing from the current epoch" - ); - pub static ref MAX_COVER_NON_ZERO_ITEMS: Result = try_create_int_gauge_vec( + "Number of valid attestations considered for packing from the current epoch", + ) +}); +pub static MAX_COVER_NON_ZERO_ITEMS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "op_pool_max_cover_non_zero_items", "Number of non-trivial items considered in a max coverage optimisation", - &["label"] - ); -} + &["label"], + ) +}); diff --git a/beacon_node/store/Cargo.toml b/beacon_node/store/Cargo.toml index 7bf1ef76be..b26eb2bb91 100644 --- a/beacon_node/store/Cargo.toml +++ b/beacon_node/store/Cargo.toml @@ -19,7 +19,6 @@ types = { workspace = true } state_processing = { workspace = true } slog = { workspace = true } serde = { workspace = true } -lazy_static = { workspace = true } lighthouse_metrics = { workspace = true } lru = { workspace = true } sloggers = { workspace = true } diff --git a/beacon_node/store/src/metrics.rs b/beacon_node/store/src/metrics.rs index 30c5207b53..af7b5e93e8 100644 --- a/beacon_node/store/src/metrics.rs +++ b/beacon_node/store/src/metrics.rs @@ -1,110 +1,156 @@ pub use lighthouse_metrics::{set_gauge, try_create_int_gauge, *}; use directory::size_of_dir; -use lazy_static::lazy_static; use std::path::Path; +use std::sync::LazyLock; -lazy_static! { - /* - * General - */ - pub static ref DISK_DB_SIZE: Result = - try_create_int_gauge("store_disk_db_size", "Size of the hot on-disk database (bytes)"); - pub static ref FREEZER_DB_SIZE: Result = - try_create_int_gauge("store_freezer_db_size", "Size of the on-disk freezer database (bytes)"); - pub static ref DISK_DB_WRITE_BYTES: Result = try_create_int_counter_vec( +/* + * General + */ +pub static DISK_DB_SIZE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "store_disk_db_size", + "Size of the hot on-disk database (bytes)", + ) +}); +pub static FREEZER_DB_SIZE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "store_freezer_db_size", + "Size of the on-disk freezer database (bytes)", + ) +}); +pub static DISK_DB_WRITE_BYTES: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "store_disk_db_write_bytes_total", "Number of bytes attempted to be written to the hot on-disk DB", &["col"], - ); - pub static ref DISK_DB_READ_BYTES: Result = try_create_int_counter_vec( + ) +}); +pub static DISK_DB_READ_BYTES: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "store_disk_db_read_bytes_total", "Number of bytes read from the hot on-disk DB", &["col"], - ); - pub static ref DISK_DB_READ_COUNT: Result = try_create_int_counter_vec( + ) +}); +pub static DISK_DB_READ_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "store_disk_db_read_count_total", "Total number of reads to the hot on-disk DB", &["col"], - ); - pub static ref DISK_DB_WRITE_COUNT: Result = try_create_int_counter_vec( + ) +}); +pub static DISK_DB_WRITE_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "store_disk_db_write_count_total", "Total number of writes to the hot on-disk DB", &["col"], - ); - pub static ref DISK_DB_READ_TIMES: Result = try_create_histogram( + ) +}); +pub static DISK_DB_READ_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "store_disk_db_read_seconds", - "Time taken to write bytes to store." - ); - pub static ref DISK_DB_WRITE_TIMES: Result = try_create_histogram( + "Time taken to write bytes to store.", + ) +}); +pub static DISK_DB_WRITE_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "store_disk_db_write_seconds", - "Time taken to write bytes to store." - ); - pub static ref DISK_DB_EXISTS_COUNT: Result = try_create_int_counter_vec( + "Time taken to write bytes to store.", + ) +}); +pub static DISK_DB_EXISTS_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "store_disk_db_exists_count_total", "Total number of checks if a key is in the hot on-disk DB", &["col"], - ); - pub static ref DISK_DB_DELETE_COUNT: Result = try_create_int_counter_vec( + ) +}); +pub static DISK_DB_DELETE_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "store_disk_db_delete_count_total", "Total number of deletions from the hot on-disk DB", &["col"], - ); - /* - * Beacon State - */ - pub static ref BEACON_STATE_GET_COUNT: Result = try_create_int_counter( + ) +}); +/* + * Beacon State + */ +pub static BEACON_STATE_GET_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "store_beacon_state_get_total", - "Total number of beacon states requested from the store (cache or DB)" - ); - pub static ref BEACON_STATE_HOT_GET_COUNT: Result = try_create_int_counter( + "Total number of beacon states requested from the store (cache or DB)", + ) +}); +pub static BEACON_STATE_HOT_GET_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "store_beacon_state_hot_get_total", - "Total number of hot beacon states requested from the store (cache or DB)" - ); - pub static ref BEACON_STATE_READ_TIMES: Result = try_create_histogram( + "Total number of hot beacon states requested from the store (cache or DB)", + ) +}); +pub static BEACON_STATE_READ_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "store_beacon_state_read_seconds", - "Total time required to read a BeaconState from the database" - ); - pub static ref BEACON_STATE_READ_OVERHEAD_TIMES: Result = try_create_histogram( + "Total time required to read a BeaconState from the database", + ) +}); +pub static BEACON_STATE_READ_OVERHEAD_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "store_beacon_state_read_overhead_seconds", - "Overhead on reading a beacon state from the DB (e.g., decoding)" - ); - pub static ref BEACON_STATE_READ_COUNT: Result = try_create_int_counter( + "Overhead on reading a beacon state from the DB (e.g., decoding)", + ) +}); +pub static BEACON_STATE_READ_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "store_beacon_state_read_total", - "Total number of beacon state reads from the DB" - ); - pub static ref BEACON_STATE_READ_BYTES: Result = try_create_int_counter( + "Total number of beacon state reads from the DB", + ) +}); +pub static BEACON_STATE_READ_BYTES: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "store_beacon_state_read_bytes_total", - "Total number of beacon state bytes read from the DB" - ); - pub static ref BEACON_STATE_WRITE_OVERHEAD_TIMES: Result = try_create_histogram( + "Total number of beacon state bytes read from the DB", + ) +}); +pub static BEACON_STATE_WRITE_OVERHEAD_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "store_beacon_state_write_overhead_seconds", - "Overhead on writing a beacon state to the DB (e.g., encoding)" - ); - pub static ref BEACON_STATE_WRITE_COUNT: Result = try_create_int_counter( + "Overhead on writing a beacon state to the DB (e.g., encoding)", + ) +}); +pub static BEACON_STATE_WRITE_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "store_beacon_state_write_total", - "Total number of beacon state writes the DB" - ); - pub static ref BEACON_STATE_WRITE_BYTES: Result = try_create_int_counter( + "Total number of beacon state writes the DB", + ) +}); +pub static BEACON_STATE_WRITE_BYTES: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "store_beacon_state_write_bytes_total", - "Total number of beacon state bytes written to the DB" - ); - /* - * Beacon Block - */ - pub static ref BEACON_BLOCK_GET_COUNT: Result = try_create_int_counter( + "Total number of beacon state bytes written to the DB", + ) +}); +/* + * Beacon Block + */ +pub static BEACON_BLOCK_GET_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "store_beacon_block_get_total", - "Total number of beacon blocks requested from the store (cache or DB)" - ); - pub static ref BEACON_BLOCK_CACHE_HIT_COUNT: Result = try_create_int_counter( + "Total number of beacon blocks requested from the store (cache or DB)", + ) +}); +pub static BEACON_BLOCK_CACHE_HIT_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "store_beacon_block_cache_hit_total", - "Number of hits to the store's block cache" - ); - pub static ref BEACON_BLOBS_CACHE_HIT_COUNT: Result = try_create_int_counter( + "Number of hits to the store's block cache", + ) +}); +pub static BEACON_BLOBS_CACHE_HIT_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "store_beacon_blobs_cache_hit_total", - "Number of hits to the store's blob cache" - ); -} + "Number of hits to the store's blob cache", + ) +}); /// Updates the global metrics registry with store-related information. pub fn scrape_for_metrics(db_path: &Path, freezer_db_path: &Path) { diff --git a/common/eth2_interop_keypairs/Cargo.toml b/common/eth2_interop_keypairs/Cargo.toml index 6f92acc84a..5971b934e0 100644 --- a/common/eth2_interop_keypairs/Cargo.toml +++ b/common/eth2_interop_keypairs/Cargo.toml @@ -7,7 +7,6 @@ edition = { workspace = true } # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -lazy_static = { workspace = true } num-bigint = "0.4.2" ethereum_hashing = { workspace = true } hex = { workspace = true } diff --git a/common/eth2_interop_keypairs/src/lib.rs b/common/eth2_interop_keypairs/src/lib.rs index 34c3d6f87c..0d24eb92f4 100644 --- a/common/eth2_interop_keypairs/src/lib.rs +++ b/common/eth2_interop_keypairs/src/lib.rs @@ -18,22 +18,21 @@ //! tests](https://github.com/ethereum/eth2.0-pm/blob/6e41fcf383ebeb5125938850d8e9b4e9888389b4/interop/mocked_start/keygen_test_vector.yaml). use bls::{Keypair, PublicKey, SecretKey}; use ethereum_hashing::hash; -use lazy_static::lazy_static; use num_bigint::BigUint; use serde::{Deserialize, Serialize}; use std::fs::File; use std::path::PathBuf; +use std::sync::LazyLock; pub const PRIVATE_KEY_BYTES: usize = 32; pub const PUBLIC_KEY_BYTES: usize = 48; pub const HASH_BYTES: usize = 32; -lazy_static! { - static ref CURVE_ORDER: BigUint = - "52435875175126190479447740508185965837690552500527637822603658699938581184513" - .parse::() - .expect("Curve order should be valid"); -} +static CURVE_ORDER: LazyLock = LazyLock::new(|| { + "52435875175126190479447740508185965837690552500527637822603658699938581184513" + .parse::() + .expect("Curve order should be valid") +}); /// Return a G1 point for the given `validator_index`, encoded as a compressed point in /// big-endian byte-ordering. diff --git a/common/lighthouse_metrics/src/lib.rs b/common/lighthouse_metrics/src/lib.rs index f2424ccabe..fa8f47e364 100644 --- a/common/lighthouse_metrics/src/lib.rs +++ b/common/lighthouse_metrics/src/lib.rs @@ -1,5 +1,5 @@ #![allow(clippy::needless_doctest_main)] -//! A wrapper around the `prometheus` crate that provides a global, `lazy_static` metrics registry +//! A wrapper around the `prometheus` crate that provides a global metrics registry //! and functions to add and use the following components (more info at //! [Prometheus docs](https://prometheus.io/docs/concepts/metric_types/)): //! @@ -20,23 +20,20 @@ //! ## Example //! //! ```rust -//! use lazy_static::lazy_static; //! use lighthouse_metrics::*; +//! use std::sync::LazyLock; //! //! // These metrics are "magically" linked to the global registry defined in `lighthouse_metrics`. -//! lazy_static! { -//! pub static ref RUN_COUNT: Result = try_create_int_counter( -//! "runs_total", -//! "Total number of runs" -//! ); -//! pub static ref CURRENT_VALUE: Result = try_create_int_gauge( -//! "current_value", -//! "The current value" -//! ); -//! pub static ref RUN_TIME: Result = -//! try_create_histogram("run_seconds", "Time taken (measured to high precision)"); -//! } -//! +//! pub static RUN_COUNT: LazyLock> = LazyLock::new(|| try_create_int_counter( +//! "runs_total", +//! "Total number of runs" +//! )); +//! pub static CURRENT_VALUE: LazyLock> = LazyLock::new(|| try_create_int_gauge( +//! "current_value", +//! "The current value" +//! )); +//! pub static RUN_TIME: LazyLock> = +//! LazyLock::new(|| try_create_histogram("run_seconds", "Time taken (measured to high precision)")); //! //! fn main() { //! for i in 0..100 { diff --git a/common/logging/Cargo.toml b/common/logging/Cargo.toml index 3a03d22f3c..cac6d073f2 100644 --- a/common/logging/Cargo.toml +++ b/common/logging/Cargo.toml @@ -9,7 +9,6 @@ test_logger = [] # Print log output to stderr when running tests instead of drop [dependencies] chrono = { version = "0.4", default-features = false, features = ["clock", "std"] } -lazy_static = { workspace = true } lighthouse_metrics = { workspace = true } parking_lot = { workspace = true } serde = { workspace = true } diff --git a/common/logging/src/lib.rs b/common/logging/src/lib.rs index 50d04fc088..5fc473c853 100644 --- a/common/logging/src/lib.rs +++ b/common/logging/src/lib.rs @@ -1,4 +1,3 @@ -use lazy_static::lazy_static; use lighthouse_metrics::{ inc_counter, try_create_int_counter, IntCounter, Result as MetricsResult, }; @@ -6,6 +5,7 @@ use slog::Logger; use slog_term::Decorator; use std::io::{Result, Write}; use std::path::PathBuf; +use std::sync::LazyLock; use std::time::{Duration, Instant}; use tracing_appender::non_blocking::NonBlocking; use tracing_appender::rolling::{RollingFileAppender, Rotation}; @@ -25,16 +25,14 @@ pub use tracing_metrics_layer::MetricsLayer; /// The minimum interval between log messages indicating that a queue is full. const LOG_DEBOUNCE_INTERVAL: Duration = Duration::from_secs(30); -lazy_static! { - pub static ref INFOS_TOTAL: MetricsResult = - try_create_int_counter("info_total", "Count of infos logged"); - pub static ref WARNS_TOTAL: MetricsResult = - try_create_int_counter("warn_total", "Count of warns logged"); - pub static ref ERRORS_TOTAL: MetricsResult = - try_create_int_counter("error_total", "Count of errors logged"); - pub static ref CRITS_TOTAL: MetricsResult = - try_create_int_counter("crit_total", "Count of crits logged"); -} +pub static INFOS_TOTAL: LazyLock> = + LazyLock::new(|| try_create_int_counter("info_total", "Count of infos logged")); +pub static WARNS_TOTAL: LazyLock> = + LazyLock::new(|| try_create_int_counter("warn_total", "Count of warns logged")); +pub static ERRORS_TOTAL: LazyLock> = + LazyLock::new(|| try_create_int_counter("error_total", "Count of errors logged")); +pub static CRITS_TOTAL: LazyLock> = + LazyLock::new(|| try_create_int_counter("crit_total", "Count of crits logged")); pub struct AlignedTermDecorator { wrapped: D, diff --git a/common/logging/src/tracing_metrics_layer.rs b/common/logging/src/tracing_metrics_layer.rs index b9dde584b4..89a1f4d1f1 100644 --- a/common/logging/src/tracing_metrics_layer.rs +++ b/common/logging/src/tracing_metrics_layer.rs @@ -1,32 +1,36 @@ //! Exposes [`MetricsLayer`]: A tracing layer that registers metrics of logging events. -use lazy_static::lazy_static; use lighthouse_metrics as metrics; +use std::sync::LazyLock; use tracing_log::NormalizeEvent; -lazy_static! { - /// Count of `INFO` logs registered per enabled dependency. - pub static ref DEP_INFOS_TOTAL: metrics::Result = +/// Count of `INFO` logs registered per enabled dependency. +pub static DEP_INFOS_TOTAL: LazyLock> = + LazyLock::new(|| { metrics::try_create_int_counter_vec( "dep_info_total", "Count of infos logged per enabled dependency", - &["target"] - ); - /// Count of `WARN` logs registered per enabled dependency. - pub static ref DEP_WARNS_TOTAL: metrics::Result = + &["target"], + ) + }); +/// Count of `WARN` logs registered per enabled dependency. +pub static DEP_WARNS_TOTAL: LazyLock> = + LazyLock::new(|| { metrics::try_create_int_counter_vec( "dep_warn_total", "Count of warns logged per enabled dependency", - &["target"] - ); - /// Count of `ERROR` logs registered per enabled dependency. - pub static ref DEP_ERRORS_TOTAL: metrics::Result = + &["target"], + ) + }); +/// Count of `ERROR` logs registered per enabled dependency. +pub static DEP_ERRORS_TOTAL: LazyLock> = + LazyLock::new(|| { metrics::try_create_int_counter_vec( "dep_error_total", "Count of errors logged per enabled dependency", - &["target"] - ); -} + &["target"], + ) + }); /// Layer that registers Prometheus metrics for `INFO`, `WARN` and `ERROR` logs emitted per dependency. /// Dependencies are enabled via the `RUST_LOG` env flag. diff --git a/common/malloc_utils/Cargo.toml b/common/malloc_utils/Cargo.toml index 4a5f39b661..ac309cec9d 100644 --- a/common/malloc_utils/Cargo.toml +++ b/common/malloc_utils/Cargo.toml @@ -6,7 +6,6 @@ edition = { workspace = true } [dependencies] lighthouse_metrics = { workspace = true } -lazy_static = { workspace = true } libc = "0.2.79" parking_lot = { workspace = true } jemalloc-ctl = { version = "0.5.0", optional = true } diff --git a/common/malloc_utils/src/glibc.rs b/common/malloc_utils/src/glibc.rs index 681849a78c..9531102682 100644 --- a/common/malloc_utils/src/glibc.rs +++ b/common/malloc_utils/src/glibc.rs @@ -4,7 +4,6 @@ //! https://www.gnu.org/software/libc/manual/html_node/The-GNU-Allocator.html //! //! These functions are generally only suitable for Linux systems. -use lazy_static::lazy_static; use lighthouse_metrics::*; use parking_lot::Mutex; use std::env; @@ -33,50 +32,65 @@ const M_MMAP_THRESHOLD: c_int = -3; /// https://man7.org/linux/man-pages/man3/mallopt.3.html const ENV_VAR_MMAP_THRESHOLD: &str = "MALLOC_MMAP_THRESHOLD_"; -lazy_static! { - pub static ref GLOBAL_LOCK: Mutex<()> = <_>::default(); -} +pub static GLOBAL_LOCK: LazyLock> = LazyLock::new(|| <_>::default()); // Metrics for the malloc. For more information, see: // // https://man7.org/linux/man-pages/man3/mallinfo.3.html -lazy_static! { - pub static ref MALLINFO_ARENA: lighthouse_metrics::Result = try_create_int_gauge( +pub static MALLINFO_ARENA: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "mallinfo_arena", "The total amount of memory allocated by means other than mmap(2). \ This figure includes both in-use blocks and blocks on the free list.", - ); - pub static ref MALLINFO_ORDBLKS: lighthouse_metrics::Result = try_create_int_gauge( + ) +}); +pub static MALLINFO_ORDBLKS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "mallinfo_ordblks", "The number of ordinary (i.e., non-fastbin) free blocks.", - ); - pub static ref MALLINFO_SMBLKS: lighthouse_metrics::Result = - try_create_int_gauge("mallinfo_smblks", "The number of fastbin free blocks.",); - pub static ref MALLINFO_HBLKS: lighthouse_metrics::Result = try_create_int_gauge( + ) +}); +pub static MALLINFO_SMBLKS: LazyLock> = + LazyLock::new(|| try_create_int_gauge("mallinfo_smblks", "The number of fastbin free blocks.")); +pub static MALLINFO_HBLKS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "mallinfo_hblks", "The number of blocks currently allocated using mmap.", - ); - pub static ref MALLINFO_HBLKHD: lighthouse_metrics::Result = try_create_int_gauge( + ) +}); +pub static MALLINFO_HBLKHD: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "mallinfo_hblkhd", "The number of bytes in blocks currently allocated using mmap.", - ); - pub static ref MALLINFO_FSMBLKS: lighthouse_metrics::Result = try_create_int_gauge( + ) +}); +pub static MALLINFO_FSMBLKS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "mallinfo_fsmblks", "The total number of bytes in fastbin free blocks.", - ); - pub static ref MALLINFO_UORDBLKS: lighthouse_metrics::Result = try_create_int_gauge( - "mallinfo_uordblks", - "The total number of bytes used by in-use allocations.", - ); - pub static ref MALLINFO_FORDBLKS: lighthouse_metrics::Result = try_create_int_gauge( - "mallinfo_fordblks", - "The total number of bytes in free blocks.", - ); - pub static ref MALLINFO_KEEPCOST: lighthouse_metrics::Result = try_create_int_gauge( - "mallinfo_keepcost", - "The total amount of releasable free space at the top of the heap..", - ); -} + ) +}); +pub static MALLINFO_UORDBLKS: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "mallinfo_uordblks", + "The total number of bytes used by in-use allocations.", + ) + }); +pub static MALLINFO_FORDBLKS: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "mallinfo_fordblks", + "The total number of bytes in free blocks.", + ) + }); +pub static MALLINFO_KEEPCOST: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "mallinfo_keepcost", + "The total amount of releasable free space at the top of the heap..", + ) + }); /// Calls `mallinfo` and updates Prometheus metrics with the results. pub fn scrape_mallinfo_metrics() { diff --git a/common/malloc_utils/src/jemalloc.rs b/common/malloc_utils/src/jemalloc.rs index 92533048c5..70685d5960 100644 --- a/common/malloc_utils/src/jemalloc.rs +++ b/common/malloc_utils/src/jemalloc.rs @@ -8,29 +8,31 @@ //! A) `JEMALLOC_SYS_WITH_MALLOC_CONF` at compile-time. //! B) `_RJEM_MALLOC_CONF` at runtime. use jemalloc_ctl::{arenas, epoch, stats, Error}; -use lazy_static::lazy_static; use lighthouse_metrics::{set_gauge, try_create_int_gauge, IntGauge}; +use std::sync::LazyLock; #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; // Metrics for jemalloc. -lazy_static! { - pub static ref NUM_ARENAS: lighthouse_metrics::Result = - try_create_int_gauge("jemalloc_num_arenas", "The number of arenas in use"); - pub static ref BYTES_ALLOCATED: lighthouse_metrics::Result = - try_create_int_gauge("jemalloc_bytes_allocated", "Equivalent to stats.allocated"); - pub static ref BYTES_ACTIVE: lighthouse_metrics::Result = - try_create_int_gauge("jemalloc_bytes_active", "Equivalent to stats.active"); - pub static ref BYTES_MAPPED: lighthouse_metrics::Result = - try_create_int_gauge("jemalloc_bytes_mapped", "Equivalent to stats.mapped"); - pub static ref BYTES_METADATA: lighthouse_metrics::Result = - try_create_int_gauge("jemalloc_bytes_metadata", "Equivalent to stats.metadata"); - pub static ref BYTES_RESIDENT: lighthouse_metrics::Result = - try_create_int_gauge("jemalloc_bytes_resident", "Equivalent to stats.resident"); - pub static ref BYTES_RETAINED: lighthouse_metrics::Result = - try_create_int_gauge("jemalloc_bytes_retained", "Equivalent to stats.retained"); -} +pub static NUM_ARENAS: LazyLock> = + LazyLock::new(|| try_create_int_gauge("jemalloc_num_arenas", "The number of arenas in use")); +pub static BYTES_ALLOCATED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge("jemalloc_bytes_allocated", "Equivalent to stats.allocated") +}); +pub static BYTES_ACTIVE: LazyLock> = + LazyLock::new(|| try_create_int_gauge("jemalloc_bytes_active", "Equivalent to stats.active")); +pub static BYTES_MAPPED: LazyLock> = + LazyLock::new(|| try_create_int_gauge("jemalloc_bytes_mapped", "Equivalent to stats.mapped")); +pub static BYTES_METADATA: LazyLock> = LazyLock::new(|| { + try_create_int_gauge("jemalloc_bytes_metadata", "Equivalent to stats.metadata") +}); +pub static BYTES_RESIDENT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge("jemalloc_bytes_resident", "Equivalent to stats.resident") +}); +pub static BYTES_RETAINED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge("jemalloc_bytes_retained", "Equivalent to stats.retained") +}); pub fn scrape_jemalloc_metrics() { scrape_jemalloc_metrics_fallible().unwrap() diff --git a/common/monitoring_api/Cargo.toml b/common/monitoring_api/Cargo.toml index 3731229c39..55f18edd52 100644 --- a/common/monitoring_api/Cargo.toml +++ b/common/monitoring_api/Cargo.toml @@ -17,6 +17,5 @@ lighthouse_version = { workspace = true } lighthouse_metrics = { workspace = true } slog = { workspace = true } store = { workspace = true } -lazy_static = { workspace = true } regex = { workspace = true } sensitive_url = { workspace = true } diff --git a/common/monitoring_api/src/gather.rs b/common/monitoring_api/src/gather.rs index b59a6dfb89..e157d82c11 100644 --- a/common/monitoring_api/src/gather.rs +++ b/common/monitoring_api/src/gather.rs @@ -1,9 +1,9 @@ use super::types::{BeaconProcessMetrics, ValidatorProcessMetrics}; -use lazy_static::lazy_static; use lighthouse_metrics::{MetricFamily, MetricType}; use serde_json::json; use std::collections::HashMap; use std::path::Path; +use std::sync::LazyLock; /// Represents a metric that needs to be fetched from lighthouse metrics registry /// and sent to the remote monitoring service. @@ -126,19 +126,20 @@ pub enum JsonType { Boolean, } -lazy_static! { - /// HashMap representing the `BEACON_PROCESS_METRICS`. - pub static ref BEACON_METRICS_MAP: HashMap = BEACON_PROCESS_METRICS +/// HashMap representing the `BEACON_PROCESS_METRICS`. +pub static BEACON_METRICS_MAP: LazyLock> = LazyLock::new(|| { + BEACON_PROCESS_METRICS .iter() .map(|metric| (metric.lighthouse_metric_name.to_string(), metric.clone())) - .collect(); - /// HashMap representing the `VALIDATOR_PROCESS_METRICS`. - pub static ref VALIDATOR_METRICS_MAP: HashMap = - VALIDATOR_PROCESS_METRICS + .collect() +}); +/// HashMap representing the `VALIDATOR_PROCESS_METRICS`. +pub static VALIDATOR_METRICS_MAP: LazyLock> = LazyLock::new(|| { + VALIDATOR_PROCESS_METRICS .iter() .map(|metric| (metric.lighthouse_metric_name.to_string(), metric.clone())) - .collect(); -} + .collect() +}); /// Returns the value from a Counter/Gauge `MetricType` assuming that it has no associated labels /// else it returns `None`. diff --git a/common/slot_clock/Cargo.toml b/common/slot_clock/Cargo.toml index 31e53779a8..13bcf006a9 100644 --- a/common/slot_clock/Cargo.toml +++ b/common/slot_clock/Cargo.toml @@ -6,6 +6,5 @@ edition = { workspace = true } [dependencies] types = { workspace = true } -lazy_static = { workspace = true } lighthouse_metrics = { workspace = true } parking_lot = { workspace = true } diff --git a/common/slot_clock/src/metrics.rs b/common/slot_clock/src/metrics.rs index ae3a9b599f..24023c9ed7 100644 --- a/common/slot_clock/src/metrics.rs +++ b/common/slot_clock/src/metrics.rs @@ -1,20 +1,22 @@ use crate::SlotClock; -use lazy_static::lazy_static; pub use lighthouse_metrics::*; +use std::sync::LazyLock; use types::{EthSpec, Slot}; -lazy_static! { - pub static ref PRESENT_SLOT: Result = - try_create_int_gauge("slotclock_present_slot", "The present wall-clock slot"); - pub static ref PRESENT_EPOCH: Result = - try_create_int_gauge("slotclock_present_epoch", "The present wall-clock epoch"); - pub static ref SLOTS_PER_EPOCH: Result = - try_create_int_gauge("slotclock_slots_per_epoch", "Slots per epoch (constant)"); - pub static ref SECONDS_PER_SLOT: Result = try_create_int_gauge( +pub static PRESENT_SLOT: LazyLock> = + LazyLock::new(|| try_create_int_gauge("slotclock_present_slot", "The present wall-clock slot")); +pub static PRESENT_EPOCH: LazyLock> = LazyLock::new(|| { + try_create_int_gauge("slotclock_present_epoch", "The present wall-clock epoch") +}); +pub static SLOTS_PER_EPOCH: LazyLock> = LazyLock::new(|| { + try_create_int_gauge("slotclock_slots_per_epoch", "Slots per epoch (constant)") +}); +pub static SECONDS_PER_SLOT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "slotclock_slot_time_seconds", - "The duration in seconds between each slot" - ); -} + "The duration in seconds between each slot", + ) +}); /// Update the global metrics `DEFAULT_REGISTRY` with info from the slot clock. pub fn scrape_for_metrics(clock: &U) { diff --git a/common/task_executor/Cargo.toml b/common/task_executor/Cargo.toml index cc9a2c5097..7928d4a3c9 100644 --- a/common/task_executor/Cargo.toml +++ b/common/task_executor/Cargo.toml @@ -9,7 +9,6 @@ async-channel = { workspace = true } tokio = { workspace = true } slog = { workspace = true } futures = { workspace = true } -lazy_static = { workspace = true } lighthouse_metrics = { workspace = true } sloggers = { workspace = true } logging = { workspace = true } diff --git a/common/task_executor/src/metrics.rs b/common/task_executor/src/metrics.rs index 6ecea86d65..a40bfdf4e7 100644 --- a/common/task_executor/src/metrics.rs +++ b/common/task_executor/src/metrics.rs @@ -1,36 +1,46 @@ /// Handles async task metrics -use lazy_static::lazy_static; pub use lighthouse_metrics::*; +use std::sync::LazyLock; -lazy_static! { - pub static ref ASYNC_TASKS_COUNT: Result = try_create_int_gauge_vec( +pub static ASYNC_TASKS_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "async_tasks_count", "Total number of async tasks spawned using spawn", - &["async_task_count"] - ); - pub static ref BLOCKING_TASKS_COUNT: Result = try_create_int_gauge_vec( + &["async_task_count"], + ) +}); +pub static BLOCKING_TASKS_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "blocking_tasks_count", "Total number of async tasks spawned using spawn_blocking", - &["blocking_task_count"] - ); - pub static ref BLOCKING_TASKS_HISTOGRAM: Result = try_create_histogram_vec( + &["blocking_task_count"], + ) +}); +pub static BLOCKING_TASKS_HISTOGRAM: LazyLock> = LazyLock::new(|| { + try_create_histogram_vec( "blocking_tasks_histogram", "Time taken by blocking tasks", - &["blocking_task_hist"] - ); - pub static ref BLOCK_ON_TASKS_COUNT: Result = try_create_int_gauge_vec( + &["blocking_task_hist"], + ) +}); +pub static BLOCK_ON_TASKS_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "block_on_tasks_count", "Total number of block_on_dangerous tasks spawned", - &["name"] - ); - pub static ref BLOCK_ON_TASKS_HISTOGRAM: Result = try_create_histogram_vec( + &["name"], + ) +}); +pub static BLOCK_ON_TASKS_HISTOGRAM: LazyLock> = LazyLock::new(|| { + try_create_histogram_vec( "block_on_tasks_histogram", "Time taken by block_on_dangerous tasks", - &["name"] - ); - pub static ref TASKS_HISTOGRAM: Result = try_create_histogram_vec( + &["name"], + ) +}); +pub static TASKS_HISTOGRAM: LazyLock> = LazyLock::new(|| { + try_create_histogram_vec( "async_tasks_time_histogram", "Time taken by async tasks", - &["async_task_hist"] - ); -} + &["async_task_hist"], + ) +}); diff --git a/common/unused_port/Cargo.toml b/common/unused_port/Cargo.toml index 3d70cad272..95dbf59186 100644 --- a/common/unused_port/Cargo.toml +++ b/common/unused_port/Cargo.toml @@ -7,5 +7,4 @@ edition = { workspace = true } [dependencies] lru_cache = { workspace = true } -lazy_static = { workspace = true } parking_lot = { workspace = true } diff --git a/common/unused_port/src/lib.rs b/common/unused_port/src/lib.rs index 386f08a739..212ae963e3 100644 --- a/common/unused_port/src/lib.rs +++ b/common/unused_port/src/lib.rs @@ -1,7 +1,7 @@ -use lazy_static::lazy_static; use lru_cache::LRUTimeCache; use parking_lot::Mutex; use std::net::{SocketAddr, TcpListener, UdpSocket}; +use std::sync::LazyLock; use std::time::Duration; #[derive(Copy, Clone)] @@ -18,10 +18,8 @@ pub enum IpVersion { pub const CACHED_PORTS_TTL: Duration = Duration::from_secs(300); -lazy_static! { - static ref FOUND_PORTS_CACHE: Mutex> = - Mutex::new(LRUTimeCache::new(CACHED_PORTS_TTL)); -} +static FOUND_PORTS_CACHE: LazyLock>> = + LazyLock::new(|| Mutex::new(LRUTimeCache::new(CACHED_PORTS_TTL))); /// A convenience wrapper over [`zero_port`]. pub fn unused_tcp4_port() -> Result { diff --git a/common/warp_utils/Cargo.toml b/common/warp_utils/Cargo.toml index 0d33de998e..84f5ce5f18 100644 --- a/common/warp_utils/Cargo.toml +++ b/common/warp_utils/Cargo.toml @@ -18,6 +18,5 @@ serde_json = { workspace = true } tokio = { workspace = true } headers = "0.3.2" lighthouse_metrics = { workspace = true } -lazy_static = { workspace = true } serde_array_query = "0.1.0" bytes = { workspace = true } diff --git a/common/warp_utils/src/metrics.rs b/common/warp_utils/src/metrics.rs index eb061c7526..505d277583 100644 --- a/common/warp_utils/src/metrics.rs +++ b/common/warp_utils/src/metrics.rs @@ -1,86 +1,125 @@ use eth2::lighthouse::{ProcessHealth, SystemHealth}; use lighthouse_metrics::*; +use std::sync::LazyLock; -lazy_static::lazy_static! { - pub static ref PROCESS_NUM_THREADS: Result = try_create_int_gauge( +pub static PROCESS_NUM_THREADS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "process_num_threads", - "Number of threads used by the current process" - ); - pub static ref PROCESS_RES_MEM: Result = try_create_int_gauge( + "Number of threads used by the current process", + ) +}); +pub static PROCESS_RES_MEM: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "process_resident_memory_bytes", - "Resident memory used by the current process" - ); - pub static ref PROCESS_VIRT_MEM: Result = try_create_int_gauge( + "Resident memory used by the current process", + ) +}); +pub static PROCESS_VIRT_MEM: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "process_virtual_memory_bytes", - "Virtual memory used by the current process" - ); - pub static ref PROCESS_SHR_MEM: Result = try_create_int_gauge( + "Virtual memory used by the current process", + ) +}); +pub static PROCESS_SHR_MEM: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "process_shared_memory_bytes", - "Shared memory used by the current process" - ); - pub static ref PROCESS_SECONDS: Result = try_create_int_gauge( + "Shared memory used by the current process", + ) +}); +pub static PROCESS_SECONDS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "process_cpu_seconds_total", - "Total cpu time taken by the current process" - ); - pub static ref SYSTEM_VIRT_MEM_TOTAL: Result = - try_create_int_gauge("system_virt_mem_total_bytes", "Total system virtual memory"); - pub static ref SYSTEM_VIRT_MEM_AVAILABLE: Result = try_create_int_gauge( + "Total cpu time taken by the current process", + ) +}); +pub static SYSTEM_VIRT_MEM_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_gauge("system_virt_mem_total_bytes", "Total system virtual memory") +}); +pub static SYSTEM_VIRT_MEM_AVAILABLE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "system_virt_mem_available_bytes", - "Available system virtual memory" - ); - pub static ref SYSTEM_VIRT_MEM_USED: Result = - try_create_int_gauge("system_virt_mem_used_bytes", "Used system virtual memory"); - pub static ref SYSTEM_VIRT_MEM_FREE: Result = - try_create_int_gauge("system_virt_mem_free_bytes", "Free system virtual memory"); - pub static ref SYSTEM_VIRT_MEM_CACHED: Result = - try_create_int_gauge("system_virt_mem_cached_bytes", "Used system virtual memory"); - pub static ref SYSTEM_VIRT_MEM_BUFFERS: Result = - try_create_int_gauge("system_virt_mem_buffer_bytes", "Free system virtual memory"); - pub static ref SYSTEM_VIRT_MEM_PERCENTAGE: Result = try_create_float_gauge( + "Available system virtual memory", + ) +}); +pub static SYSTEM_VIRT_MEM_USED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge("system_virt_mem_used_bytes", "Used system virtual memory") +}); +pub static SYSTEM_VIRT_MEM_FREE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge("system_virt_mem_free_bytes", "Free system virtual memory") +}); +pub static SYSTEM_VIRT_MEM_CACHED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge("system_virt_mem_cached_bytes", "Used system virtual memory") +}); +pub static SYSTEM_VIRT_MEM_BUFFERS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge("system_virt_mem_buffer_bytes", "Free system virtual memory") +}); +pub static SYSTEM_VIRT_MEM_PERCENTAGE: LazyLock> = LazyLock::new(|| { + try_create_float_gauge( "system_virt_mem_percentage", - "Percentage of used virtual memory" - ); - pub static ref SYSTEM_LOADAVG_1: Result = - try_create_float_gauge("system_loadavg_1", "Loadavg over 1 minute"); - pub static ref SYSTEM_LOADAVG_5: Result = - try_create_float_gauge("system_loadavg_5", "Loadavg over 5 minutes"); - pub static ref SYSTEM_LOADAVG_15: Result = - try_create_float_gauge("system_loadavg_15", "Loadavg over 15 minutes"); + "Percentage of used virtual memory", + ) +}); +pub static SYSTEM_LOADAVG_1: LazyLock> = + LazyLock::new(|| try_create_float_gauge("system_loadavg_1", "Loadavg over 1 minute")); +pub static SYSTEM_LOADAVG_5: LazyLock> = + LazyLock::new(|| try_create_float_gauge("system_loadavg_5", "Loadavg over 5 minutes")); +pub static SYSTEM_LOADAVG_15: LazyLock> = + LazyLock::new(|| try_create_float_gauge("system_loadavg_15", "Loadavg over 15 minutes")); - pub static ref CPU_CORES: Result = - try_create_int_gauge("cpu_cores", "Number of physical cpu cores"); - pub static ref CPU_THREADS: Result = - try_create_int_gauge("cpu_threads", "Number of logical cpu cores"); +pub static CPU_CORES: LazyLock> = + LazyLock::new(|| try_create_int_gauge("cpu_cores", "Number of physical cpu cores")); +pub static CPU_THREADS: LazyLock> = + LazyLock::new(|| try_create_int_gauge("cpu_threads", "Number of logical cpu cores")); - pub static ref CPU_SYSTEM_SECONDS_TOTAL: Result = - try_create_int_gauge("cpu_system_seconds_total", "Total time spent in kernel mode"); - pub static ref CPU_USER_SECONDS_TOTAL: Result = - try_create_int_gauge("cpu_user_seconds_total", "Total time spent in user mode"); - pub static ref CPU_IOWAIT_SECONDS_TOTAL: Result = - try_create_int_gauge("cpu_iowait_seconds_total", "Total time spent waiting for io"); - pub static ref CPU_IDLE_SECONDS_TOTAL: Result = - try_create_int_gauge("cpu_idle_seconds_total", "Total time spent idle"); +pub static CPU_SYSTEM_SECONDS_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "cpu_system_seconds_total", + "Total time spent in kernel mode", + ) +}); +pub static CPU_USER_SECONDS_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_gauge("cpu_user_seconds_total", "Total time spent in user mode") +}); +pub static CPU_IOWAIT_SECONDS_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "cpu_iowait_seconds_total", + "Total time spent waiting for io", + ) +}); +pub static CPU_IDLE_SECONDS_TOTAL: LazyLock> = + LazyLock::new(|| try_create_int_gauge("cpu_idle_seconds_total", "Total time spent idle")); - pub static ref DISK_BYTES_TOTAL: Result = - try_create_int_gauge("disk_node_bytes_total", "Total capacity of disk"); +pub static DISK_BYTES_TOTAL: LazyLock> = + LazyLock::new(|| try_create_int_gauge("disk_node_bytes_total", "Total capacity of disk")); - pub static ref DISK_BYTES_FREE: Result = - try_create_int_gauge("disk_node_bytes_free", "Free space in disk"); +pub static DISK_BYTES_FREE: LazyLock> = + LazyLock::new(|| try_create_int_gauge("disk_node_bytes_free", "Free space in disk")); - pub static ref DISK_READS: Result = - try_create_int_gauge("disk_node_reads_total", "Number of disk reads"); +pub static DISK_READS: LazyLock> = + LazyLock::new(|| try_create_int_gauge("disk_node_reads_total", "Number of disk reads")); - pub static ref DISK_WRITES: Result = - try_create_int_gauge("disk_node_writes_total", "Number of disk writes"); +pub static DISK_WRITES: LazyLock> = + LazyLock::new(|| try_create_int_gauge("disk_node_writes_total", "Number of disk writes")); - pub static ref NETWORK_BYTES_RECEIVED: Result = - try_create_int_gauge("network_node_bytes_total_received", "Total bytes received over all network interfaces"); - pub static ref NETWORK_BYTES_SENT: Result = - try_create_int_gauge("network_node_bytes_total_transmit", "Total bytes sent over all network interfaces"); +pub static NETWORK_BYTES_RECEIVED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "network_node_bytes_total_received", + "Total bytes received over all network interfaces", + ) +}); +pub static NETWORK_BYTES_SENT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "network_node_bytes_total_transmit", + "Total bytes sent over all network interfaces", + ) +}); - pub static ref BOOT_TIME: Result = - try_create_int_gauge("misc_node_boot_ts_seconds", "Boot time as unix epoch timestamp"); -} +pub static BOOT_TIME: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "misc_node_boot_ts_seconds", + "Boot time as unix epoch timestamp", + ) +}); pub fn scrape_health_metrics() { scrape_process_health_metrics(); diff --git a/consensus/merkle_proof/Cargo.toml b/consensus/merkle_proof/Cargo.toml index 3bee25eaac..15f65dfe4f 100644 --- a/consensus/merkle_proof/Cargo.toml +++ b/consensus/merkle_proof/Cargo.toml @@ -7,7 +7,6 @@ edition = { workspace = true } [dependencies] ethereum-types = { workspace = true } ethereum_hashing = { workspace = true } -lazy_static = { workspace = true } safe_arith = { workspace = true } [dev-dependencies] diff --git a/consensus/merkle_proof/src/lib.rs b/consensus/merkle_proof/src/lib.rs index 2d2d2afdda..b9457fffab 100644 --- a/consensus/merkle_proof/src/lib.rs +++ b/consensus/merkle_proof/src/lib.rs @@ -1,17 +1,14 @@ use ethereum_hashing::{hash, hash32_concat, ZERO_HASHES}; use ethereum_types::H256; -use lazy_static::lazy_static; use safe_arith::ArithError; +use std::sync::LazyLock; const MAX_TREE_DEPTH: usize = 32; const EMPTY_SLICE: &[H256] = &[]; -lazy_static! { - /// Zero nodes to act as "synthetic" left and right subtrees of other zero nodes. - static ref ZERO_NODES: Vec = { - (0..=MAX_TREE_DEPTH).map(MerkleTree::Zero).collect() - }; -} +/// Zero nodes to act as "synthetic" left and right subtrees of other zero nodes. +static ZERO_NODES: LazyLock> = + LazyLock::new(|| (0..=MAX_TREE_DEPTH).map(MerkleTree::Zero).collect()); /// Right-sparse Merkle tree. /// diff --git a/consensus/state_processing/Cargo.toml b/consensus/state_processing/Cargo.toml index e05c0bcfeb..7b7c6eb0c4 100644 --- a/consensus/state_processing/Cargo.toml +++ b/consensus/state_processing/Cargo.toml @@ -26,7 +26,6 @@ int_to_bytes = { workspace = true } smallvec = { workspace = true } arbitrary = { workspace = true } lighthouse_metrics = { workspace = true } -lazy_static = { workspace = true } derivative = { workspace = true } test_random_derive = { path = "../../common/test_random_derive" } rand = { workspace = true } diff --git a/consensus/state_processing/src/metrics.rs b/consensus/state_processing/src/metrics.rs index ac5c0f659c..e6fe483776 100644 --- a/consensus/state_processing/src/metrics.rs +++ b/consensus/state_processing/src/metrics.rs @@ -1,42 +1,62 @@ -use lazy_static::lazy_static; pub use lighthouse_metrics::*; +use std::sync::LazyLock; -lazy_static! { - /* - * Participation Metrics - */ - pub static ref PARTICIPATION_PREV_EPOCH_HEAD_ATTESTING_GWEI_TOTAL: Result = try_create_int_gauge( +/* + * Participation Metrics + */ +pub static PARTICIPATION_PREV_EPOCH_HEAD_ATTESTING_GWEI_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( "beacon_participation_prev_epoch_head_attesting_gwei_total", "Total effective balance (gwei) of validators who attested to the head in the previous epoch" - ); - pub static ref PARTICIPATION_PREV_EPOCH_TARGET_ATTESTING_GWEI_TOTAL: Result = try_create_int_gauge( + ) + }); +pub static PARTICIPATION_PREV_EPOCH_TARGET_ATTESTING_GWEI_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( "beacon_participation_prev_epoch_target_attesting_gwei_total", "Total effective balance (gwei) of validators who attested to the target in the previous epoch" - ); - pub static ref PARTICIPATION_PREV_EPOCH_SOURCE_ATTESTING_GWEI_TOTAL: Result = try_create_int_gauge( + ) + }); +pub static PARTICIPATION_PREV_EPOCH_SOURCE_ATTESTING_GWEI_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( "beacon_participation_prev_epoch_source_attesting_gwei_total", "Total effective balance (gwei) of validators who attested to the source in the previous epoch" - ); - pub static ref PARTICIPATION_CURRENT_EPOCH_TOTAL_ACTIVE_GWEI_TOTAL: Result = try_create_int_gauge( - "beacon_participation_current_epoch_active_gwei_total", - "Total effective balance (gwei) of validators who are active in the current epoch" - ); - /* - * Processing metrics - */ - pub static ref PROCESS_EPOCH_TIME: Result = try_create_histogram( + ) + }); +pub static PARTICIPATION_CURRENT_EPOCH_TOTAL_ACTIVE_GWEI_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_gauge( + "beacon_participation_current_epoch_active_gwei_total", + "Total effective balance (gwei) of validators who are active in the current epoch", + ) + }); +/* + * Processing metrics + */ +pub static PROCESS_EPOCH_TIME: LazyLock> = LazyLock::new(|| { + try_create_histogram( "beacon_state_processing_process_epoch", "Time required for process_epoch", - ); - /* - * Participation Metrics (progressive balances) - */ - pub static ref PARTICIPATION_PREV_EPOCH_TARGET_ATTESTING_GWEI_PROGRESSIVE_TOTAL: Result = try_create_int_gauge( + ) +}); +/* + * Participation Metrics (progressive balances) + */ +pub static PARTICIPATION_PREV_EPOCH_TARGET_ATTESTING_GWEI_PROGRESSIVE_TOTAL: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_gauge( "beacon_participation_prev_epoch_target_attesting_gwei_progressive_total", "Progressive total effective balance (gwei) of validators who attested to the target in the previous epoch" - ); - pub static ref PARTICIPATION_CURR_EPOCH_TARGET_ATTESTING_GWEI_PROGRESSIVE_TOTAL: Result = try_create_int_gauge( + ) +}); +pub static PARTICIPATION_CURR_EPOCH_TARGET_ATTESTING_GWEI_PROGRESSIVE_TOTAL: LazyLock< + Result, +> = LazyLock::new(|| { + try_create_int_gauge( "beacon_participation_curr_epoch_target_attesting_gwei_progressive_total", "Progressive total effective balance (gwei) of validators who attested to the target in the current epoch" - ); -} + ) +}); diff --git a/consensus/state_processing/src/per_block_processing/tests.rs b/consensus/state_processing/src/per_block_processing/tests.rs index 2774dd3d87..f8b354d92d 100644 --- a/consensus/state_processing/src/per_block_processing/tests.rs +++ b/consensus/state_processing/src/per_block_processing/tests.rs @@ -11,8 +11,8 @@ use crate::{ BlockSignatureStrategy, ConsensusContext, VerifyBlockRoot, VerifySignatures, }; use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType}; -use lazy_static::lazy_static; use ssz_types::Bitfield; +use std::sync::LazyLock; use test_utils::generate_deterministic_keypairs; use types::*; @@ -22,10 +22,9 @@ pub const VALIDATOR_COUNT: usize = 64; pub const EPOCH_OFFSET: u64 = 4; pub const NUM_ATTESTATIONS: u64 = 1; -lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = generate_deterministic_keypairs(MAX_VALIDATOR_COUNT); -} +/// A cached set of keys. +static KEYPAIRS: LazyLock> = + LazyLock::new(|| generate_deterministic_keypairs(MAX_VALIDATOR_COUNT)); async fn get_harness( epoch_offset: u64, diff --git a/consensus/types/Cargo.toml b/consensus/types/Cargo.toml index f623f3d101..c6c89de570 100644 --- a/consensus/types/Cargo.toml +++ b/consensus/types/Cargo.toml @@ -43,7 +43,6 @@ rusqlite = { workspace = true } arbitrary = { workspace = true, features = ["derive"] } ethereum_serde_utils = { workspace = true } regex = { workspace = true } -lazy_static = { workspace = true } parking_lot = { workspace = true } itertools = { workspace = true } superstruct = { workspace = true } diff --git a/consensus/types/src/beacon_state/committee_cache/tests.rs b/consensus/types/src/beacon_state/committee_cache/tests.rs index 4dc06feab3..1d2ca4ccdb 100644 --- a/consensus/types/src/beacon_state/committee_cache/tests.rs +++ b/consensus/types/src/beacon_state/committee_cache/tests.rs @@ -2,15 +2,14 @@ use crate::test_utils::*; use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType}; use beacon_chain::types::*; -use lazy_static::lazy_static; +use std::sync::LazyLock; use swap_or_not_shuffle::shuffle_list; pub const VALIDATOR_COUNT: usize = 16; -lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = generate_deterministic_keypairs(VALIDATOR_COUNT); -} +/// A cached set of keys. +static KEYPAIRS: LazyLock> = + LazyLock::new(|| generate_deterministic_keypairs(VALIDATOR_COUNT)); fn get_harness(validator_count: usize) -> BeaconChainHarness> { let harness = BeaconChainHarness::builder(E::default()) diff --git a/consensus/types/src/beacon_state/tests.rs b/consensus/types/src/beacon_state/tests.rs index 16c7ff152f..7d67e96bbc 100644 --- a/consensus/types/src/beacon_state/tests.rs +++ b/consensus/types/src/beacon_state/tests.rs @@ -6,18 +6,17 @@ use beacon_chain::types::{ ChainSpec, Domain, Epoch, EthSpec, Hash256, Keypair, MainnetEthSpec, MinimalEthSpec, RelativeEpoch, Slot, Vector, }; -use lazy_static::lazy_static; use ssz::Encode; use std::ops::Mul; +use std::sync::LazyLock; use swap_or_not_shuffle::compute_shuffled_index; pub const MAX_VALIDATOR_COUNT: usize = 129; pub const SLOT_OFFSET: Slot = Slot::new(1); -lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = generate_deterministic_keypairs(MAX_VALIDATOR_COUNT); -} +/// A cached set of keys. +static KEYPAIRS: LazyLock> = + LazyLock::new(|| generate_deterministic_keypairs(MAX_VALIDATOR_COUNT)); async fn get_harness( validator_count: usize, diff --git a/consensus/types/src/subnet_id.rs b/consensus/types/src/subnet_id.rs index 66786b5129..b2a6b6a2a0 100644 --- a/consensus/types/src/subnet_id.rs +++ b/consensus/types/src/subnet_id.rs @@ -1,23 +1,21 @@ //! Identifies each shard by an integer identifier. use crate::{AttestationRef, ChainSpec, CommitteeIndex, Epoch, EthSpec, Slot}; -use lazy_static::lazy_static; use safe_arith::{ArithError, SafeArith}; use serde::{Deserialize, Serialize}; use std::ops::{Deref, DerefMut}; +use std::sync::LazyLock; use swap_or_not_shuffle::compute_shuffled_index; const MAX_SUBNET_ID: usize = 64; -lazy_static! { - static ref SUBNET_ID_TO_STRING: Vec = { - let mut v = Vec::with_capacity(MAX_SUBNET_ID); +static SUBNET_ID_TO_STRING: LazyLock> = LazyLock::new(|| { + let mut v = Vec::with_capacity(MAX_SUBNET_ID); - for i in 0..MAX_SUBNET_ID { - v.push(i.to_string()); - } - v - }; -} + for i in 0..MAX_SUBNET_ID { + v.push(i.to_string()); + } + v +}); #[derive(arbitrary::Arbitrary, Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(transparent)] diff --git a/consensus/types/src/sync_subnet_id.rs b/consensus/types/src/sync_subnet_id.rs index 7806aecfca..245ac5a6c4 100644 --- a/consensus/types/src/sync_subnet_id.rs +++ b/consensus/types/src/sync_subnet_id.rs @@ -1,24 +1,22 @@ //! Identifies each sync committee subnet by an integer identifier. use crate::consts::altair::SYNC_COMMITTEE_SUBNET_COUNT; use crate::EthSpec; -use lazy_static::lazy_static; use safe_arith::{ArithError, SafeArith}; use serde::{Deserialize, Serialize}; use ssz_types::typenum::Unsigned; use std::collections::HashSet; use std::fmt::{self, Display}; use std::ops::{Deref, DerefMut}; +use std::sync::LazyLock; -lazy_static! { - static ref SYNC_SUBNET_ID_TO_STRING: Vec = { - let mut v = Vec::with_capacity(SYNC_COMMITTEE_SUBNET_COUNT as usize); +static SYNC_SUBNET_ID_TO_STRING: LazyLock> = LazyLock::new(|| { + let mut v = Vec::with_capacity(SYNC_COMMITTEE_SUBNET_COUNT as usize); - for i in 0..SYNC_COMMITTEE_SUBNET_COUNT { - v.push(i.to_string()); - } - v - }; -} + for i in 0..SYNC_COMMITTEE_SUBNET_COUNT { + v.push(i.to_string()); + } + v +}); #[derive(arbitrary::Arbitrary, Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(transparent)] diff --git a/lcli/Dockerfile b/lcli/Dockerfile index 2cc9ce605b..d2cb6f6f14 100644 --- a/lcli/Dockerfile +++ b/lcli/Dockerfile @@ -1,7 +1,7 @@ # `lcli` requires the full project to be in scope, so this should be built either: # - from the `lighthouse` dir with the command: `docker build -f ./lcli/Dockerflie .` # - from the current directory with the command: `docker build -f ./Dockerfile ../` -FROM rust:1.75.0-bullseye AS builder +FROM rust:1.80.0-bullseye AS builder RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev COPY . lighthouse ARG FEATURES diff --git a/lighthouse/Cargo.toml b/lighthouse/Cargo.toml index b9d3eaf894..b720601e70 100644 --- a/lighthouse/Cargo.toml +++ b/lighthouse/Cargo.toml @@ -4,7 +4,7 @@ version = "5.2.1" authors = ["Sigma Prime "] edition = { workspace = true } autotests = false -rust-version = "1.78.0" +rust-version = "1.80.0" [features] default = ["slasher-lmdb"] @@ -50,7 +50,6 @@ eth2_network_config = { workspace = true } lighthouse_version = { workspace = true } account_utils = { workspace = true } lighthouse_metrics = { workspace = true } -lazy_static = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } serde_yaml = { workspace = true } diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index 481e17dbc8..1a1da45991 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -14,20 +14,20 @@ use environment::{EnvironmentBuilder, LoggerConfig}; use eth2_network_config::{Eth2NetworkConfig, DEFAULT_HARDCODED_NETWORK, HARDCODED_NET_NAMES}; use ethereum_hashing::have_sha_extensions; use futures::TryFutureExt; -use lazy_static::lazy_static; use lighthouse_version::VERSION; use malloc_utils::configure_memory_allocator; use slog::{crit, info}; use std::backtrace::Backtrace; use std::path::PathBuf; use std::process::exit; +use std::sync::LazyLock; use task_executor::ShutdownReason; use types::{EthSpec, EthSpecId}; use validator_client::ProductionValidatorClient; -lazy_static! { - pub static ref SHORT_VERSION: String = VERSION.replace("Lighthouse/", ""); - pub static ref LONG_VERSION: String = format!( +pub static SHORT_VERSION: LazyLock = LazyLock::new(|| VERSION.replace("Lighthouse/", "")); +pub static LONG_VERSION: LazyLock = LazyLock::new(|| { + format!( "{}\n\ BLS library: {}\n\ BLS hardware acceleration: {}\n\ @@ -43,8 +43,8 @@ lazy_static! { build_profile_name(), cfg!(feature = "spec-minimal"), cfg!(feature = "gnosis"), - ); -} + ) +}); fn bls_library_name() -> &'static str { if cfg!(feature = "portable") { diff --git a/lighthouse/src/metrics.rs b/lighthouse/src/metrics.rs index ef3c33d298..0002b43e7b 100644 --- a/lighthouse/src/metrics.rs +++ b/lighthouse/src/metrics.rs @@ -1,23 +1,23 @@ -use lazy_static::lazy_static; pub use lighthouse_metrics::*; use lighthouse_version::VERSION; use slog::{error, Logger}; +use std::sync::LazyLock; use std::time::{SystemTime, UNIX_EPOCH}; -lazy_static! { - pub static ref PROCESS_START_TIME_SECONDS: Result = try_create_int_gauge( +pub static PROCESS_START_TIME_SECONDS: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "process_start_time_seconds", - "The unix timestamp at which the process was started" - ); -} + "The unix timestamp at which the process was started", + ) +}); -lazy_static! { - pub static ref LIGHTHOUSE_VERSION: Result = try_create_int_gauge_vec( +pub static LIGHTHOUSE_VERSION: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "lighthouse_info", "The build of Lighthouse running on the server", &["version"], - ); -} + ) +}); pub fn expose_process_start_time(log: &Logger) { match SystemTime::now().duration_since(UNIX_EPOCH) { diff --git a/slasher/Cargo.toml b/slasher/Cargo.toml index ad0bb00963..d74b0ac062 100644 --- a/slasher/Cargo.toml +++ b/slasher/Cargo.toml @@ -18,7 +18,6 @@ derivative = { workspace = true } ethereum_ssz = { workspace = true } ethereum_ssz_derive = { workspace = true } flate2 = { version = "1.0.14", features = ["zlib"], default-features = false } -lazy_static = { workspace = true } lighthouse_metrics = { workspace = true } filesystem = { workspace = true } lru = { workspace = true } diff --git a/slasher/src/metrics.rs b/slasher/src/metrics.rs index b11d21d4b5..2e49bd4aeb 100644 --- a/slasher/src/metrics.rs +++ b/slasher/src/metrics.rs @@ -1,56 +1,78 @@ -use lazy_static::lazy_static; pub use lighthouse_metrics::*; +use std::sync::LazyLock; -lazy_static! { - pub static ref SLASHER_DATABASE_SIZE: Result = try_create_int_gauge( +pub static SLASHER_DATABASE_SIZE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "slasher_database_size", - "Size of the database backing the slasher, in bytes" - ); - pub static ref SLASHER_RUN_TIME: Result = try_create_histogram( + "Size of the database backing the slasher, in bytes", + ) +}); +pub static SLASHER_RUN_TIME: LazyLock> = LazyLock::new(|| { + try_create_histogram( "slasher_process_batch_time", - "Time taken to process a batch of blocks and attestations" - ); - pub static ref SLASHER_NUM_ATTESTATIONS_DROPPED: Result = try_create_int_gauge( + "Time taken to process a batch of blocks and attestations", + ) +}); +pub static SLASHER_NUM_ATTESTATIONS_DROPPED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "slasher_num_attestations_dropped", - "Number of attestations dropped per batch" - ); - pub static ref SLASHER_NUM_ATTESTATIONS_DEFERRED: Result = try_create_int_gauge( + "Number of attestations dropped per batch", + ) +}); +pub static SLASHER_NUM_ATTESTATIONS_DEFERRED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "slasher_num_attestations_deferred", - "Number of attestations deferred per batch" - ); - pub static ref SLASHER_NUM_ATTESTATIONS_VALID: Result = try_create_int_gauge( + "Number of attestations deferred per batch", + ) +}); +pub static SLASHER_NUM_ATTESTATIONS_VALID: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "slasher_num_attestations_valid", - "Number of valid attestations per batch" - ); - pub static ref SLASHER_NUM_ATTESTATIONS_STORED_PER_BATCH: Result = + "Number of valid attestations per batch", + ) +}); +pub static SLASHER_NUM_ATTESTATIONS_STORED_PER_BATCH: LazyLock> = + LazyLock::new(|| { try_create_int_gauge( "slasher_num_attestations_stored_per_batch", - "Number of attestations stored per batch" - ); - pub static ref SLASHER_NUM_BLOCKS_PROCESSED: Result = try_create_int_gauge( + "Number of attestations stored per batch", + ) + }); +pub static SLASHER_NUM_BLOCKS_PROCESSED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "slasher_num_blocks_processed", "Number of blocks processed per batch", - ); - pub static ref SLASHER_NUM_CHUNKS_UPDATED: Result = try_create_int_counter_vec( + ) +}); +pub static SLASHER_NUM_CHUNKS_UPDATED: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "slasher_num_chunks_updated", "Number of min or max target chunks updated on disk", &["array"], - ); - pub static ref SLASHER_COMPRESSION_RATIO: Result = try_create_float_gauge( + ) +}); +pub static SLASHER_COMPRESSION_RATIO: LazyLock> = LazyLock::new(|| { + try_create_float_gauge( "slasher_compression_ratio", - "Compression ratio for min-max array chunks (higher is better)" - ); - pub static ref SLASHER_NUM_ATTESTATION_ROOT_QUERIES: Result = + "Compression ratio for min-max array chunks (higher is better)", + ) +}); +pub static SLASHER_NUM_ATTESTATION_ROOT_QUERIES: LazyLock> = + LazyLock::new(|| { try_create_int_counter( "slasher_num_attestation_root_queries", "Number of requests for an attestation data root", - ); - pub static ref SLASHER_NUM_ATTESTATION_ROOT_HITS: Result = try_create_int_counter( + ) + }); +pub static SLASHER_NUM_ATTESTATION_ROOT_HITS: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "slasher_num_attestation_root_hits", "Number of requests for an attestation data root that hit the LRU cache", - ); - pub static ref SLASHER_ATTESTATION_ROOT_CACHE_SIZE: Result = try_create_int_gauge( + ) +}); +pub static SLASHER_ATTESTATION_ROOT_CACHE_SIZE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "slasher_attestation_root_cache_size", - "Number of attestation data roots cached in memory" - ); -} + "Number of attestation data roots cached in memory", + ) +}); diff --git a/testing/state_transition_vectors/Cargo.toml b/testing/state_transition_vectors/Cargo.toml index a1b6ed3b87..142a657f07 100644 --- a/testing/state_transition_vectors/Cargo.toml +++ b/testing/state_transition_vectors/Cargo.toml @@ -11,7 +11,6 @@ state_processing = { workspace = true } types = { workspace = true } ethereum_ssz = { workspace = true } beacon_chain = { workspace = true } -lazy_static = { workspace = true } tokio = { workspace = true } [features] diff --git a/testing/state_transition_vectors/src/main.rs b/testing/state_transition_vectors/src/main.rs index 3e7c37af54..58637b92d9 100644 --- a/testing/state_transition_vectors/src/main.rs +++ b/testing/state_transition_vectors/src/main.rs @@ -3,13 +3,13 @@ mod macros; mod exit; use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType}; -use lazy_static::lazy_static; use ssz::Encode; use std::env; use std::fs::{self, File}; use std::io::Write; use std::path::{Path, PathBuf}; use std::process::exit; +use std::sync::LazyLock; use types::{ test_utils::generate_deterministic_keypairs, BeaconState, EthSpec, Keypair, SignedBeaconBlock, }; @@ -45,10 +45,9 @@ pub struct TestVector { pub error: Option, } -lazy_static! { - /// A cached set of keys. - static ref KEYPAIRS: Vec = generate_deterministic_keypairs(VALIDATOR_COUNT); -} +/// A cached set of keys. +static KEYPAIRS: LazyLock> = + LazyLock::new(|| generate_deterministic_keypairs(VALIDATOR_COUNT)); async fn get_harness( slot: Slot, diff --git a/testing/web3signer_tests/Cargo.toml b/testing/web3signer_tests/Cargo.toml index 1bdf62cd22..7321fc1384 100644 --- a/testing/web3signer_tests/Cargo.toml +++ b/testing/web3signer_tests/Cargo.toml @@ -26,5 +26,4 @@ serde_yaml = { workspace = true } eth2_network_config = { workspace = true } serde_json = { workspace = true } zip = { workspace = true } -lazy_static = { workspace = true } parking_lot = { workspace = true } diff --git a/testing/web3signer_tests/src/lib.rs b/testing/web3signer_tests/src/lib.rs index 4187844cec..13d92d2d85 100644 --- a/testing/web3signer_tests/src/lib.rs +++ b/testing/web3signer_tests/src/lib.rs @@ -22,7 +22,6 @@ mod tests { }; use eth2_keystore::KeystoreBuilder; use eth2_network_config::Eth2NetworkConfig; - use lazy_static::lazy_static; use parking_lot::Mutex; use reqwest::Client; use serde::Serialize; @@ -33,7 +32,7 @@ mod tests { use std::future::Future; use std::path::PathBuf; use std::process::{Child, Command, Stdio}; - use std::sync::Arc; + use std::sync::{Arc, LazyLock}; use std::time::{Duration, Instant}; use task_executor::TaskExecutor; use tempfile::{tempdir, TempDir}; @@ -57,12 +56,13 @@ mod tests { /// debugging. const SUPPRESS_WEB3SIGNER_LOGS: bool = true; - lazy_static! { - static ref TEMP_DIR: Arc> = Arc::new(Mutex::new( - tempdir().expect("Failed to create temporary directory") - )); - static ref GET_WEB3SIGNER_BIN: OnceCell<()> = OnceCell::new(); - } + static TEMP_DIR: LazyLock>> = LazyLock::new(|| { + Arc::new(Mutex::new( + tempdir().expect("Failed to create temporary directory"), + )) + }); + + static GET_WEB3SIGNER_BIN: OnceCell<()> = OnceCell::const_new(); type E = MainnetEthSpec; diff --git a/validator_client/Cargo.toml b/validator_client/Cargo.toml index 0df687abec..bff40b41d5 100644 --- a/validator_client/Cargo.toml +++ b/validator_client/Cargo.toml @@ -50,7 +50,6 @@ libsecp256k1 = { workspace = true } ring = { workspace = true } rand = { workspace = true, features = ["small_rng"] } lighthouse_metrics = { workspace = true } -lazy_static = { workspace = true } monitoring_api = { workspace = true } sensitive_url = { workspace = true } task_executor = { workspace = true } diff --git a/validator_client/slashing_protection/Cargo.toml b/validator_client/slashing_protection/Cargo.toml index baba14c538..6982958bd5 100644 --- a/validator_client/slashing_protection/Cargo.toml +++ b/validator_client/slashing_protection/Cargo.toml @@ -22,7 +22,6 @@ filesystem = { workspace = true } arbitrary = { workspace = true, features = ["derive"] } [dev-dependencies] -lazy_static = { workspace = true } rayon = { workspace = true } [features] diff --git a/validator_client/slashing_protection/tests/interop.rs b/validator_client/slashing_protection/tests/interop.rs index ee8f522cd6..c32aab55a2 100644 --- a/validator_client/slashing_protection/tests/interop.rs +++ b/validator_client/slashing_protection/tests/interop.rs @@ -1,11 +1,9 @@ -use lazy_static::lazy_static; use slashing_protection::interchange_test::MultiTestCase; use std::fs::File; use std::path::PathBuf; +use std::sync::LazyLock; -lazy_static! { - pub static ref TEST_ROOT_DIR: PathBuf = test_root_dir(); -} +pub static TEST_ROOT_DIR: LazyLock = LazyLock::new(test_root_dir); fn download_tests() { let make_output = std::process::Command::new("make") diff --git a/validator_client/src/http_metrics/metrics.rs b/validator_client/src/http_metrics/metrics.rs index cc5b03bb19..8bc569c67a 100644 --- a/validator_client/src/http_metrics/metrics.rs +++ b/validator_client/src/http_metrics/metrics.rs @@ -1,6 +1,7 @@ use super::Context; use malloc_utils::scrape_allocator_metrics; use slot_clock::SlotClock; +use std::sync::LazyLock; use std::time::{SystemTime, UNIX_EPOCH}; use types::EthSpec; @@ -39,168 +40,233 @@ pub const WEB3SIGNER: &str = "web3signer"; pub use lighthouse_metrics::*; -lazy_static::lazy_static! { - pub static ref GENESIS_DISTANCE: Result = try_create_int_gauge( +pub static GENESIS_DISTANCE: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "vc_genesis_distance_seconds", - "Distance between now and genesis time" - ); - pub static ref ENABLED_VALIDATORS_COUNT: Result = try_create_int_gauge( + "Distance between now and genesis time", + ) +}); +pub static ENABLED_VALIDATORS_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "vc_validators_enabled_count", - "Number of enabled validators" - ); - pub static ref TOTAL_VALIDATORS_COUNT: Result = try_create_int_gauge( + "Number of enabled validators", + ) +}); +pub static TOTAL_VALIDATORS_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "vc_validators_total_count", - "Number of total validators (enabled and disabled)" - ); + "Number of total validators (enabled and disabled)", + ) +}); - pub static ref SIGNED_BLOCKS_TOTAL: Result = try_create_int_counter_vec( +pub static SIGNED_BLOCKS_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "vc_signed_beacon_blocks_total", "Total count of attempted block signings", - &["status"] - ); - pub static ref SIGNED_ATTESTATIONS_TOTAL: Result = try_create_int_counter_vec( + &["status"], + ) +}); +pub static SIGNED_ATTESTATIONS_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "vc_signed_attestations_total", "Total count of attempted Attestation signings", - &["status"] - ); - pub static ref SIGNED_AGGREGATES_TOTAL: Result = try_create_int_counter_vec( + &["status"], + ) +}); +pub static SIGNED_AGGREGATES_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "vc_signed_aggregates_total", "Total count of attempted SignedAggregateAndProof signings", - &["status"] - ); - pub static ref SIGNED_SELECTION_PROOFS_TOTAL: Result = try_create_int_counter_vec( + &["status"], + ) +}); +pub static SIGNED_SELECTION_PROOFS_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "vc_signed_selection_proofs_total", "Total count of attempted SelectionProof signings", - &["status"] - ); - pub static ref SIGNED_SYNC_COMMITTEE_MESSAGES_TOTAL: Result = try_create_int_counter_vec( - "vc_signed_sync_committee_messages_total", - "Total count of attempted SyncCommitteeMessage signings", - &["status"] - ); - pub static ref SIGNED_SYNC_COMMITTEE_CONTRIBUTIONS_TOTAL: Result = try_create_int_counter_vec( - "vc_signed_sync_committee_contributions_total", - "Total count of attempted ContributionAndProof signings", - &["status"] - ); - pub static ref SIGNED_SYNC_SELECTION_PROOFS_TOTAL: Result = try_create_int_counter_vec( - "vc_signed_sync_selection_proofs_total", - "Total count of attempted SyncSelectionProof signings", - &["status"] - ); - pub static ref SIGNED_VOLUNTARY_EXITS_TOTAL: Result = try_create_int_counter_vec( + &["status"], + ) +}); +pub static SIGNED_SYNC_COMMITTEE_MESSAGES_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "vc_signed_sync_committee_messages_total", + "Total count of attempted SyncCommitteeMessage signings", + &["status"], + ) + }); +pub static SIGNED_SYNC_COMMITTEE_CONTRIBUTIONS_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "vc_signed_sync_committee_contributions_total", + "Total count of attempted ContributionAndProof signings", + &["status"], + ) + }); +pub static SIGNED_SYNC_SELECTION_PROOFS_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "vc_signed_sync_selection_proofs_total", + "Total count of attempted SyncSelectionProof signings", + &["status"], + ) + }); +pub static SIGNED_VOLUNTARY_EXITS_TOTAL: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "vc_signed_voluntary_exits_total", "Total count of VoluntaryExit signings", - &["status"] - ); - pub static ref SIGNED_VALIDATOR_REGISTRATIONS_TOTAL: Result = try_create_int_counter_vec( - "builder_validator_registrations_total", - "Total count of ValidatorRegistrationData signings", - &["status"] - ); - pub static ref DUTIES_SERVICE_TIMES: Result = try_create_histogram_vec( + &["status"], + ) +}); +pub static SIGNED_VALIDATOR_REGISTRATIONS_TOTAL: LazyLock> = + LazyLock::new(|| { + try_create_int_counter_vec( + "builder_validator_registrations_total", + "Total count of ValidatorRegistrationData signings", + &["status"], + ) + }); +pub static DUTIES_SERVICE_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram_vec( "vc_duties_service_task_times_seconds", "Duration to perform duties service tasks", - &["task"] - ); - pub static ref ATTESTATION_SERVICE_TIMES: Result = try_create_histogram_vec( + &["task"], + ) +}); +pub static ATTESTATION_SERVICE_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram_vec( "vc_attestation_service_task_times_seconds", "Duration to perform attestation service tasks", - &["task"] - ); - pub static ref SLASHING_PROTECTION_PRUNE_TIMES: Result = try_create_histogram( + &["task"], + ) +}); +pub static SLASHING_PROTECTION_PRUNE_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "vc_slashing_protection_prune_times_seconds", "Time required to prune the slashing protection DB", - ); - pub static ref BLOCK_SERVICE_TIMES: Result = try_create_histogram_vec( + ) +}); +pub static BLOCK_SERVICE_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram_vec( "vc_beacon_block_service_task_times_seconds", "Duration to perform beacon block service tasks", - &["task"] - ); - pub static ref PROPOSER_COUNT: Result = try_create_int_gauge_vec( + &["task"], + ) +}); +pub static PROPOSER_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "vc_beacon_block_proposer_count", "Number of beacon block proposers on this host", - &["task"] - ); - pub static ref ATTESTER_COUNT: Result = try_create_int_gauge_vec( + &["task"], + ) +}); +pub static ATTESTER_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "vc_beacon_attester_count", "Number of attesters on this host", - &["task"] - ); - pub static ref PROPOSAL_CHANGED: Result = try_create_int_counter( + &["task"], + ) +}); +pub static PROPOSAL_CHANGED: LazyLock> = LazyLock::new(|| { + try_create_int_counter( "vc_beacon_block_proposal_changed", "A duties update discovered a new block proposer for the current slot", - ); - /* - * Endpoint metrics - */ - pub static ref ENDPOINT_ERRORS: Result = try_create_int_counter_vec( + ) +}); +/* + * Endpoint metrics + */ +pub static ENDPOINT_ERRORS: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "bn_endpoint_errors", "The number of beacon node request errors for each endpoint", - &["endpoint"] - ); - pub static ref ENDPOINT_REQUESTS: Result = try_create_int_counter_vec( + &["endpoint"], + ) +}); +pub static ENDPOINT_REQUESTS: LazyLock> = LazyLock::new(|| { + try_create_int_counter_vec( "bn_endpoint_requests", "The number of beacon node requests for each endpoint", - &["endpoint"] - ); + &["endpoint"], + ) +}); - /* - * Beacon node availability metrics - */ - pub static ref AVAILABLE_BEACON_NODES_COUNT: Result = try_create_int_gauge( +/* + * Beacon node availability metrics + */ +pub static AVAILABLE_BEACON_NODES_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "vc_beacon_nodes_available_count", "Number of available beacon nodes", - ); - pub static ref SYNCED_BEACON_NODES_COUNT: Result = try_create_int_gauge( + ) +}); +pub static SYNCED_BEACON_NODES_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "vc_beacon_nodes_synced_count", "Number of synced beacon nodes", - ); - pub static ref TOTAL_BEACON_NODES_COUNT: Result = try_create_int_gauge( + ) +}); +pub static TOTAL_BEACON_NODES_COUNT: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "vc_beacon_nodes_total_count", "Total number of beacon nodes", - ); + ) +}); - pub static ref ETH2_FALLBACK_CONFIGURED: Result = try_create_int_gauge( +pub static ETH2_FALLBACK_CONFIGURED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "sync_eth2_fallback_configured", "The number of configured eth2 fallbacks", - ); + ) +}); - pub static ref ETH2_FALLBACK_CONNECTED: Result = try_create_int_gauge( +pub static ETH2_FALLBACK_CONNECTED: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( "sync_eth2_fallback_connected", "Set to 1 if connected to atleast one synced eth2 fallback node, otherwise set to 0", - ); - /* - * Signing Metrics - */ - pub static ref SIGNING_TIMES: Result = try_create_histogram_vec( + ) +}); +/* + * Signing Metrics + */ +pub static SIGNING_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram_vec( "vc_signing_times_seconds", "Duration to obtain a signature", - &["type"] - ); - pub static ref BLOCK_SIGNING_TIMES: Result = try_create_histogram( + &["type"], + ) +}); +pub static BLOCK_SIGNING_TIMES: LazyLock> = LazyLock::new(|| { + try_create_histogram( "vc_block_signing_times_seconds", "Duration to obtain a signature for a block", - ); + ) +}); - pub static ref ATTESTATION_DUTY: Result = try_create_int_gauge_vec( +pub static ATTESTATION_DUTY: LazyLock> = LazyLock::new(|| { + try_create_int_gauge_vec( "vc_attestation_duty_slot", "Attestation duty slot for all managed validators", - &["validator"] - ); - /* - * BN latency - */ - pub static ref VC_BEACON_NODE_LATENCY: Result = try_create_histogram_vec( + &["validator"], + ) +}); +/* + * BN latency + */ +pub static VC_BEACON_NODE_LATENCY: LazyLock> = LazyLock::new(|| { + try_create_histogram_vec( "vc_beacon_node_latency", "Round-trip latency for a simple API endpoint on each BN", - &["endpoint"] - ); - pub static ref VC_BEACON_NODE_LATENCY_PRIMARY_ENDPOINT: Result = try_create_histogram( - "vc_beacon_node_latency_primary_endpoint", - "Round-trip latency for the primary BN endpoint", - ); -} + &["endpoint"], + ) +}); +pub static VC_BEACON_NODE_LATENCY_PRIMARY_ENDPOINT: LazyLock> = + LazyLock::new(|| { + try_create_histogram( + "vc_beacon_node_latency_primary_endpoint", + "Round-trip latency for the primary BN endpoint", + ) + }); pub fn gather_prometheus_metrics( ctx: &Context,