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:
Jimmy Chen
2024-07-29 21:42:31 +10:00
committed by GitHub
parent 00038dae81
commit 96b00ef66c
85 changed files with 3512 additions and 2370 deletions

View File

@@ -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<Keypair> = types::test_utils::generate_deterministic_keypairs(MAX_VALIDATOR_COUNT);
}
/// A cached set of keys.
static KEYPAIRS: LazyLock<Vec<Keypair>> =
LazyLock::new(|| types::test_utils::generate_deterministic_keypairs(MAX_VALIDATOR_COUNT));
fn get_harness<E: EthSpec>(
validator_count: usize,

View File

@@ -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<Histogram> = try_create_histogram(
pub static BUILD_REWARD_CACHE_TIME: LazyLock<Result<Histogram>> = 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<Histogram> = try_create_histogram(
"Time to build the reward cache before packing attestations",
)
});
pub static ATTESTATION_PREV_EPOCH_PACKING_TIME: LazyLock<Result<Histogram>> = 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<Histogram> = try_create_histogram(
"Time to pack previous epoch attestations",
)
});
pub static ATTESTATION_CURR_EPOCH_PACKING_TIME: LazyLock<Result<Histogram>> = 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<IntGauge> = try_create_int_gauge(
"Time to pack current epoch attestations",
)
});
pub static NUM_PREV_EPOCH_ATTESTATIONS: LazyLock<Result<IntGauge>> = 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<IntGauge> = try_create_int_gauge(
"Number of valid attestations considered for packing from the previous epoch",
)
});
pub static NUM_CURR_EPOCH_ATTESTATIONS: LazyLock<Result<IntGauge>> = 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<IntGaugeVec> = try_create_int_gauge_vec(
"Number of valid attestations considered for packing from the current epoch",
)
});
pub static MAX_COVER_NON_ZERO_ITEMS: LazyLock<Result<IntGaugeVec>> = 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"],
)
});