Skip to content

Commit

Permalink
refactor: replace once_cell Lazy with LazyLock (paradigmxyz#9844)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
Co-authored-by: Oliver <[email protected]>
  • Loading branch information
3 people authored Aug 8, 2024
1 parent a206eb3 commit 106a0c7
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 33 deletions.
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
5 changes: 0 additions & 5 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.4"
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 @@ -448,7 +448,7 @@ itertools = "0.13"
linked_hash_set = "0.1"
modular-bitfield = "0.11.2"
nybbles = "0.2.1"
once_cell = "1.17"
once_cell = "1.19"
parking_lot = "0.12"
paste = "1.0"
rand = "0.8.5"
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
2 changes: 1 addition & 1 deletion crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ 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
once_cell.workspace = true
tempfile = { workspace = true, optional = true }
thiserror = { workspace = true, optional = true }
zstd = { workspace = true, features = ["experimental"], optional = true }
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 @@ -68,7 +68,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 @@ -62,7 +62,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

0 comments on commit 106a0c7

Please sign in to comment.