mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Replace lazy_static! with LazyLock (#6189)
* Replace `lazy_static` with `LazyLock`. * Merge branch 'unstable' into remove-lazy-static # Conflicts: # beacon_node/lighthouse_network/src/peer_manager/mod.rs * Lint fixes. * Merge branch 'unstable' into remove-lazy-static # Conflicts: # beacon_node/beacon_chain/src/metrics.rs * Moar lint fixes. * Update rust version to 1.80.0. * Merge branch 'unstable' into remove-lazy-static
This commit is contained in:
@@ -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 }
|
||||
|
||||
@@ -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<JsonClientVersionV1> =
|
||||
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 {
|
||||
|
||||
@@ -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<IntCounter> = try_create_int_counter(
|
||||
pub static EXECUTION_LAYER_PROPOSER_INSERTED: LazyLock<Result<IntCounter>> = 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<IntCounter> = 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<HistogramVec> =
|
||||
try_create_histogram_vec_with_buckets(
|
||||
)
|
||||
});
|
||||
pub static EXECUTION_LAYER_PROPOSER_DATA_UPDATED: LazyLock<Result<IntCounter>> =
|
||||
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<Result<HistogramVec>> = 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<Histogram> = try_create_histogram(
|
||||
&["method"],
|
||||
)
|
||||
});
|
||||
pub static EXECUTION_LAYER_PAYLOAD_ATTRIBUTES_LOOKAHEAD: LazyLock<Result<Histogram>> =
|
||||
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<IntCounterVec> = try_create_int_counter_vec(
|
||||
)
|
||||
});
|
||||
pub static EXECUTION_LAYER_PRE_PREPARED_PAYLOAD_ID: LazyLock<Result<IntCounterVec>> = 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<Histogram> = 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<Histogram> = 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<Histogram> = try_create_histogram_with_buckets(
|
||||
)
|
||||
},
|
||||
);
|
||||
pub static EXECUTION_LAYER_GET_PAYLOAD_BY_BLOCK_HASH: LazyLock<Result<Histogram>> =
|
||||
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<Result<Histogram>> =
|
||||
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<Result<Histogram>> = 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<IntCounterVec> = 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<Result<IntCounterVec>> = 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<IntCounterVec> = 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<IntCounterVec> = 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<IntCounterVec> = 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<IntCounterVec> = 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<IntGaugeVec> = try_create_int_gauge_vec(
|
||||
&["method", "status"],
|
||||
)
|
||||
});
|
||||
pub static EXECUTION_LAYER_GET_PAYLOAD_OUTCOME: LazyLock<Result<IntCounterVec>> =
|
||||
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<Result<IntCounterVec>> =
|
||||
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<Result<IntCounterVec>> =
|
||||
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<Result<IntCounterVec>> =
|
||||
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<Result<IntGaugeVec>> = 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"]
|
||||
);
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
@@ -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<JsonClientVersionV1> =
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user