Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace once_cell Lazy with LazyLock #9844

Merged
merged 14 commits into from
Aug 8, 2024
Merged
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.79" # MSRV
toolchain: "1.80" # MSRV
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.79" # MSRV
toolchain: "1.80" # MSRV
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
Expand Down
6 changes: 0 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace.package]
version = "1.0.3"
edition = "2021"
rust-version = "1.79"
rust-version = "1.80"
license = "MIT OR Apache-2.0"
homepage = "https://paradigmxyz.github.io/reth"
repository = "https://github.com/paradigmxyz/reth"
Expand Down Expand Up @@ -462,7 +462,7 @@ rayon = "1.7"
itertools = "0.13"
parking_lot = "0.12"
modular-bitfield = "0.11.2"
once_cell = "1.17"
once_cell = "1.19.0"
syn = "2.0"
nybbles = "0.2.1"
smallvec = "1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ When updating this, also update:
- .github/workflows/lint.yml
-->

The Minimum Supported Rust Version (MSRV) of this project is [1.79.0](https://blog.rust-lang.org/2024/06/13/Rust-1.79.0.html).
The Minimum Supported Rust Version (MSRV) of this project is [1.80.0](https://blog.rust-lang.org/2024/07/25/Rust-1.80.0.html).

See the book for detailed instructions on how to [build from source](https://paradigmxyz.github.io/reth/installation/source.html).

Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
msrv = "1.79"
msrv = "1.80"
too-large-for-stack = 128
2 changes: 1 addition & 1 deletion crates/ethereum-forks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ workspace = true
alloy-chains.workspace = true
alloy-primitives = { workspace = true, features = ["serde", "rand", "rlp"] }
alloy-rlp = { workspace = true, features = ["arrayvec", "derive"] }
once_cell.workspace = true

# used for forkid
crc = "3"

# misc
serde = { workspace = true, features = ["derive"], optional = true }
thiserror-no-std = { workspace = true, default-features = false }
once_cell.workspace = true
dyn-clone.workspace = true
rustc-hash = { workspace = true, optional = true }

Expand Down
1 change: 0 additions & 1 deletion crates/metrics/metrics-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ proc-macro2.workspace = true
syn = { workspace = true, features = ["extra-traits"] }
quote.workspace = true
regex = "1.6.0"
once_cell.workspace = true

[dev-dependencies]
metrics.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/metrics/metrics-derive/src/expand.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use once_cell::sync::Lazy;
use quote::{quote, ToTokens};
use regex::Regex;
use std::sync::LazyLock;
use syn::{
punctuated::Punctuated, Attribute, Data, DeriveInput, Error, Expr, Field, Lit, LitBool, LitStr,
Meta, MetaNameValue, Result, Token,
Expand All @@ -11,8 +11,8 @@ use crate::{metric::Metric, with_attrs::WithAttrs};
/// Metric name regex according to Prometheus data model
///
/// See <https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels>
static METRIC_NAME_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^[a-zA-Z_:.][a-zA-Z0-9_:.]*$").unwrap());
static METRIC_NAME_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[a-zA-Z_:.][a-zA-Z0-9_:.]*$").unwrap());

/// Supported metrics separators
const SUPPORTED_SEPARATORS: &[&str] = &[".", "_", ":"];
Expand Down
8 changes: 5 additions & 3 deletions crates/metrics/metrics-derive/tests/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use metrics::{
Counter, Gauge, Histogram, Key, KeyName, Label, Metadata, Recorder, SharedString, Unit,
};
use once_cell::sync::Lazy;
use reth_metrics_derive::Metrics;
use serial_test::serial;
use std::{collections::HashMap, sync::Mutex};
use std::{
collections::HashMap,
sync::{LazyLock, Mutex},
};

#[allow(dead_code)]
#[derive(Metrics)]
Expand Down Expand Up @@ -58,7 +60,7 @@ struct DynamicScopeMetrics {
skipped_field_e: u128,
}

static RECORDER: Lazy<TestRecorder> = Lazy::new(TestRecorder::new);
static RECORDER: LazyLock<TestRecorder> = LazyLock::new(TestRecorder::new);

fn test_describe(scope: &str) {
assert_eq!(RECORDER.metrics_len(), 4);
Expand Down
2 changes: 0 additions & 2 deletions crates/node/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ metrics-util.workspace = true

tokio.workspace = true

once_cell.workspace = true

jsonrpsee = { workspace = true, features = ["server"] }
http.workspace = true
tower.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/node/metrics/src/recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use eyre::WrapErr;
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle};
use metrics_util::layers::{PrefixLayer, Stack};
use once_cell::sync::Lazy;
use std::sync::LazyLock;

/// Installs the Prometheus recorder as the global recorder.
pub fn install_prometheus_recorder() -> &'static PrometheusHandle {
Expand All @@ -12,8 +12,8 @@ pub fn install_prometheus_recorder() -> &'static PrometheusHandle {

/// The default Prometheus recorder handle. We use a global static to ensure that it is only
/// installed once.
static PROMETHEUS_RECORDER_HANDLE: Lazy<PrometheusHandle> =
Lazy::new(|| PrometheusRecorder::install().unwrap());
static PROMETHEUS_RECORDER_HANDLE: LazyLock<PrometheusHandle> =
LazyLock::new(|| PrometheusRecorder::install().unwrap());

/// Prometheus recorder installer
#[derive(Debug)]
Expand Down
1 change: 0 additions & 1 deletion crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ c-kzg = { workspace = true, features = ["serde"], optional = true }
bytes.workspace = true
derive_more.workspace = true
modular-bitfield = { workspace = true, optional = true }
once_cell.workspace = true
rayon.workspace = true
serde.workspace = true
tempfile = { workspace = true, optional = true }
Expand Down
6 changes: 3 additions & 3 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use alloy_rlp::{
use bytes::Buf;
use core::mem;
use derive_more::{AsRef, Deref};
use once_cell::sync::Lazy;
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
use serde::{Deserialize, Serialize};
use std::sync::LazyLock;

pub use access_list::{AccessList, AccessListItem};
pub use eip1559::TxEip1559;
Expand Down Expand Up @@ -76,8 +76,8 @@ pub type TxHashOrNumber = BlockHashOrNumber;

// Expected number of transactions where we can expect a speed-up by recovering the senders in
// parallel.
pub(crate) static PARALLEL_SENDER_RECOVERY_THRESHOLD: Lazy<usize> =
Lazy::new(|| match rayon::current_num_threads() {
pub(crate) static PARALLEL_SENDER_RECOVERY_THRESHOLD: LazyLock<usize> =
LazyLock::new(|| match rayon::current_num_threads() {
0..=1 => usize::MAX,
2..=8 => 10,
_ => 5,
Expand Down
1 change: 0 additions & 1 deletion crates/trie/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ tokio = { workspace = true, default-features = false, features = [
"macros",
] }
tokio-stream.workspace = true
once_cell.workspace = true
serde_json.workspace = true
similar-asserts.workspace = true
criterion.workspace = true
Expand Down
8 changes: 5 additions & 3 deletions crates/trie/db/tests/proof.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use once_cell::sync::Lazy;
use reth_chainspec::{Chain, ChainSpec, HOLESKY, MAINNET};
use reth_db_api::database::Database;
use reth_primitives::{
Expand All @@ -11,7 +10,10 @@ use reth_storage_errors::provider::ProviderResult;
use reth_trie::{proof::Proof, Nibbles, StateRoot};
use reth_trie_common::{AccountProof, StorageProof};
use reth_trie_db::{DatabaseProof, DatabaseStateRoot};
use std::{str::FromStr, sync::Arc};
use std::{
str::FromStr,
sync::{Arc, LazyLock},
};

/*
World State (sampled from <https://ethereum.stackexchange.com/questions/268/ethereum-block-architecture/6413#6413>)
Expand All @@ -24,7 +26,7 @@ use std::{str::FromStr, sync::Arc};

All expected testspec results were obtained from querying proof RPC on the running geth instance `geth init crates/trie/testdata/proof-genesis.json && geth --http`.
*/
static TEST_SPEC: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
static TEST_SPEC: LazyLock<Arc<ChainSpec>> = LazyLock::new(|| {
ChainSpec {
chain: Chain::from_id(12345),
genesis: serde_json::from_str(include_str!("../../trie/testdata/proof-genesis.json"))
Expand Down
1 change: 0 additions & 1 deletion crates/trie/trie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ tokio = { workspace = true, default-features = false, features = [
"macros",
] }
tokio-stream.workspace = true
once_cell.workspace = true
serde_json.workspace = true
similar-asserts.workspace = true
criterion.workspace = true
Expand Down
1 change: 0 additions & 1 deletion examples/manual-p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ futures.workspace = true
tokio.workspace = true

eyre.workspace = true
once_cell.workspace = true
4 changes: 2 additions & 2 deletions examples/manual-p2p/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use std::time::Duration;

use futures::StreamExt;
use once_cell::sync::Lazy;
use reth_chainspec::{Chain, MAINNET};
use reth_discv4::{DiscoveryUpdate, Discv4, Discv4ConfigBuilder, DEFAULT_DISCOVERY_ADDRESS};
use reth_ecies::stream::ECIESStream;
Expand All @@ -20,12 +19,13 @@ use reth_network::config::rng_secret_key;
use reth_network_peers::{mainnet_nodes, pk2id, NodeRecord};
use reth_primitives::{EthereumHardfork, Head, MAINNET_GENESIS_HASH};
use secp256k1::{SecretKey, SECP256K1};
use std::sync::LazyLock;
use tokio::net::TcpStream;

type AuthedP2PStream = P2PStream<ECIESStream<TcpStream>>;
type AuthedEthStream = EthStream<P2PStream<ECIESStream<TcpStream>>>;

pub static MAINNET_BOOT_NODES: Lazy<Vec<NodeRecord>> = Lazy::new(mainnet_nodes);
pub static MAINNET_BOOT_NODES: LazyLock<Vec<NodeRecord>> = LazyLock::new(mainnet_nodes);

#[tokio::main]
async fn main() -> eyre::Result<()> {
Expand Down
Loading