From 251502060c92090312d7370ebb317fb21398f251 Mon Sep 17 00:00:00 2001 From: ethanoroshiba Date: Thu, 26 Sep 2024 13:21:00 -0500 Subject: [PATCH] Migrate to `LazyLock` --- Cargo.lock | 5 ----- Cargo.toml | 1 - crates/astria-bridge-withdrawer/Cargo.toml | 1 - .../tests/blackbox/helpers/test_bridge_withdrawer.rs | 6 +++--- crates/astria-composer/Cargo.toml | 1 - crates/astria-composer/src/executor/tests.rs | 6 +++--- crates/astria-composer/src/rollup.rs | 8 +++++--- crates/astria-composer/tests/blackbox/helper/mod.rs | 6 +++--- crates/astria-conductor/Cargo.toml | 1 - crates/astria-conductor/tests/blackbox/helpers/mod.rs | 10 ++++++---- crates/astria-config/Cargo.toml | 3 +-- crates/astria-config/src/tests.rs | 11 ++++++----- crates/astria-sequencer-relayer/Cargo.toml | 1 - .../tests/blackbox/helpers/test_sequencer_relayer.rs | 6 +++--- 14 files changed, 30 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2559a1f088..522729f894 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -532,7 +532,6 @@ dependencies = [ "humantime", "hyper 0.14.30", "ibc-types", - "once_cell", "pin-project-lite", "prost", "reqwest", @@ -606,7 +605,6 @@ dependencies = [ "hyper 0.14.30", "insta", "itertools 0.12.1", - "once_cell", "pin-project-lite", "prost", "rand 0.8.5", @@ -660,7 +658,6 @@ dependencies = [ "itoa", "jsonrpsee", "moka", - "once_cell", "pbjson-types", "pin-project-lite", "prost", @@ -688,7 +685,6 @@ version = "0.1.0" dependencies = [ "figment", "names", - "once_cell", "regex", "serde", ] @@ -890,7 +886,6 @@ dependencies = [ "itertools 0.12.1", "itoa", "k256", - "once_cell", "pbjson-types", "pin-project-lite", "prost", diff --git a/Cargo.toml b/Cargo.toml index 649ba90f08..5225f08429 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,7 +73,6 @@ insta = "1.36.1" itertools = "0.12.1" itoa = "1.0.10" jsonrpsee = { version = "0.20" } -once_cell = "1.17.1" pbjson-types = "0.6" # Note that when updating the penumbra versions, vendored types in `proto/sequencerapis/astria_vendored` may need to be updated as well. # can update to a tagged release when https://github.com/penumbra-zone/penumbra/pull/4822 is included diff --git a/crates/astria-bridge-withdrawer/Cargo.toml b/crates/astria-bridge-withdrawer/Cargo.toml index b3b6c53519..6da072432e 100644 --- a/crates/astria-bridge-withdrawer/Cargo.toml +++ b/crates/astria-bridge-withdrawer/Cargo.toml @@ -21,7 +21,6 @@ ethers = { workspace = true, features = ["ws"] } hyper = { workspace = true } humantime = { workspace = true } ibc-types = { workspace = true } -once_cell = { workspace = true } pin-project-lite = { workspace = true } prost = { workspace = true } serde = { workspace = true, features = ["derive"] } diff --git a/crates/astria-bridge-withdrawer/tests/blackbox/helpers/test_bridge_withdrawer.rs b/crates/astria-bridge-withdrawer/tests/blackbox/helpers/test_bridge_withdrawer.rs index 3b2a8a33eb..dbb8a53b1b 100644 --- a/crates/astria-bridge-withdrawer/tests/blackbox/helpers/test_bridge_withdrawer.rs +++ b/crates/astria-bridge-withdrawer/tests/blackbox/helpers/test_bridge_withdrawer.rs @@ -2,6 +2,7 @@ use std::{ io::Write as _, mem, net::SocketAddr, + sync::LazyLock, time::Duration, }; @@ -37,7 +38,6 @@ use ibc_types::core::{ channel::ChannelId, client::Height as IbcHeight, }; -use once_cell::sync::Lazy; use sequencer_client::{ Address, NonceResponse, @@ -74,7 +74,7 @@ pub(crate) const DEFAULT_IBC_DENOM: &str = "transfer/channel-0/utia"; pub(crate) const SEQUENCER_CHAIN_ID: &str = "test-sequencer"; const ASTRIA_ADDRESS_PREFIX: &str = "astria"; -static TELEMETRY: Lazy<()> = Lazy::new(|| { +static TELEMETRY: LazyLock<()> = LazyLock::new(|| { if std::env::var_os("TEST_LOG").is_some() { let filter_directives = std::env::var("RUST_LOG").unwrap_or_else(|_| "info".into()); telemetry::configure() @@ -251,7 +251,7 @@ impl TestBridgeWithdrawerConfig { ethereum_config, asset_denom, } = self; - Lazy::force(&TELEMETRY); + LazyLock::force(&TELEMETRY); // sequencer signer key let keyfile = NamedTempFile::new().unwrap(); diff --git a/crates/astria-composer/Cargo.toml b/crates/astria-composer/Cargo.toml index 28fc349e75..5ab89db77b 100644 --- a/crates/astria-composer/Cargo.toml +++ b/crates/astria-composer/Cargo.toml @@ -30,7 +30,6 @@ humantime = { workspace = true } hyper = { workspace = true } hex = { workspace = true } itertools = { workspace = true } -once_cell = { workspace = true } pin-project-lite = { workspace = true } prost = { workspace = true } reqwest = { workspace = true, features = ["json"] } diff --git a/crates/astria-composer/src/executor/tests.rs b/crates/astria-composer/src/executor/tests.rs index bb0e4af537..bf0f8d9ee9 100644 --- a/crates/astria-composer/src/executor/tests.rs +++ b/crates/astria-composer/src/executor/tests.rs @@ -4,6 +4,7 @@ use std::{ IpAddr, SocketAddr, }, + sync::LazyLock, time::Duration, }; @@ -20,7 +21,6 @@ use astria_core::{ protocol::transaction::v1alpha1::action::SequenceAction, }; use astria_eyre::eyre; -use once_cell::sync::Lazy; use prost::{ bytes::Bytes, Message as _, @@ -72,7 +72,7 @@ use crate::{ Config, }; -static TELEMETRY: Lazy<()> = Lazy::new(|| { +static TELEMETRY: LazyLock<()> = LazyLock::new(|| { // This config can be meaningless - it's only used inside `try_init` to init the metrics, but we // haven't configured telemetry to provide metrics here. let config = Config { @@ -121,7 +121,7 @@ fn sequence_action() -> SequenceAction { /// Start a mock sequencer server and mount a mock for the `accounts/nonce` query. async fn setup() -> (MockServer, Config, NamedTempFile) { - Lazy::force(&TELEMETRY); + LazyLock::force(&TELEMETRY); let server = MockServer::start().await; let keyfile = NamedTempFile::new().unwrap(); diff --git a/crates/astria-composer/src/rollup.rs b/crates/astria-composer/src/rollup.rs index 310fcb98b3..962e237f5f 100644 --- a/crates/astria-composer/src/rollup.rs +++ b/crates/astria-composer/src/rollup.rs @@ -1,8 +1,10 @@ //! Parsing strings of the form `::` -use std::fmt; +use std::{ + fmt, + sync::LazyLock, +}; -use once_cell::sync::Lazy; use regex::Regex; #[derive(Debug)] @@ -33,7 +35,7 @@ impl std::error::Error for ParseError {} impl Rollup { pub(super) fn parse(from: &str) -> Result { - static ROLLUP_RE: Lazy = Lazy::new(|| { + static ROLLUP_RE: LazyLock = LazyLock::new(|| { Regex::new( r"(?x) ^(?P[[:alnum:]-]+?) diff --git a/crates/astria-composer/tests/blackbox/helper/mod.rs b/crates/astria-composer/tests/blackbox/helper/mod.rs index 8b564b3001..ecd5090441 100644 --- a/crates/astria-composer/tests/blackbox/helper/mod.rs +++ b/crates/astria-composer/tests/blackbox/helper/mod.rs @@ -5,6 +5,7 @@ use std::{ IpAddr, SocketAddr, }, + sync::LazyLock, time::Duration, }; @@ -28,7 +29,6 @@ use astria_core::{ }; use astria_eyre::eyre; use ethers::prelude::Transaction; -use once_cell::sync::Lazy; use telemetry::metrics; use tempfile::NamedTempFile; use tendermint_rpc::{ @@ -50,7 +50,7 @@ use wiremock::{ pub mod mock_sequencer; -static TELEMETRY: Lazy<()> = Lazy::new(|| { +static TELEMETRY: LazyLock<()> = LazyLock::new(|| { // This config can be meaningless - it's only used inside `try_init` to init the metrics, but we // haven't configured telemetry to provide metrics here. let config = Config { @@ -107,7 +107,7 @@ pub struct TestComposer { /// There is no explicit error handling in favour of panicking loudly /// and early. pub async fn spawn_composer(rollup_ids: &[&str]) -> TestComposer { - Lazy::force(&TELEMETRY); + LazyLock::force(&TELEMETRY); let mut rollup_nodes = HashMap::new(); let mut rollups = String::new(); diff --git a/crates/astria-conductor/Cargo.toml b/crates/astria-conductor/Cargo.toml index 602536a607..6dd08e24d4 100644 --- a/crates/astria-conductor/Cargo.toml +++ b/crates/astria-conductor/Cargo.toml @@ -83,7 +83,6 @@ config = { package = "astria-config", path = "../astria-config", features = [ celestia-tendermint = { workspace = true } insta = { workspace = true, features = ["json"] } -once_cell = { workspace = true } wiremock = { workspace = true } chrono = "0.4.35" diff --git a/crates/astria-conductor/tests/blackbox/helpers/mod.rs b/crates/astria-conductor/tests/blackbox/helpers/mod.rs index 4cf9835176..04d1c6aee9 100644 --- a/crates/astria-conductor/tests/blackbox/helpers/mod.rs +++ b/crates/astria-conductor/tests/blackbox/helpers/mod.rs @@ -1,4 +1,7 @@ -use std::time::Duration; +use std::{ + sync::LazyLock, + time::Duration, +}; use astria_conductor::{ conductor, @@ -25,7 +28,6 @@ use celestia_types::{ nmt::Namespace, Blob, }; -use once_cell::sync::Lazy; use prost::Message; use sequencer_client::{ tendermint, @@ -52,7 +54,7 @@ pub const SEQUENCER_CHAIN_ID: &str = "test_sequencer-1000"; pub const INITIAL_SOFT_HASH: [u8; 64] = [1; 64]; pub const INITIAL_FIRM_HASH: [u8; 64] = [1; 64]; -static TELEMETRY: Lazy<()> = Lazy::new(|| { +static TELEMETRY: LazyLock<()> = LazyLock::new(|| { astria_eyre::install().unwrap(); if std::env::var_os("TEST_LOG").is_some() { let filter_directives = std::env::var("RUST_LOG").unwrap_or_else(|_| "info".into()); @@ -82,7 +84,7 @@ pub async fn spawn_conductor(execution_commit_level: CommitLevel) -> TestConduct environment does not stall the runtime: the test could be configured using \ `#[tokio::test(flavor = \"multi_thread\", worker_threads = 1)]`" ); - Lazy::force(&TELEMETRY); + LazyLock::force(&TELEMETRY); let mock_grpc = MockGrpc::spawn().await; let mock_http = wiremock::MockServer::start().await; diff --git a/crates/astria-config/Cargo.toml b/crates/astria-config/Cargo.toml index 89a476cf32..6066f28aa2 100644 --- a/crates/astria-config/Cargo.toml +++ b/crates/astria-config/Cargo.toml @@ -14,7 +14,6 @@ homepage = "https://astria.org" figment = { version = "0.10.8", features = ["env"] } names = { version = "0.14", optional = true, default-features = false } -once_cell = { workspace = true, optional = true } regex = { workspace = true, optional = true } serde = { workspace = true } @@ -22,4 +21,4 @@ serde = { workspace = true } serde = { workspace = true, features = ["derive"] } [features] -tests = ["figment/test", "dep:names", "dep:once_cell", "dep:regex"] +tests = ["figment/test", "dep:names", "dep:regex"] diff --git a/crates/astria-config/src/tests.rs b/crates/astria-config/src/tests.rs index 6411f48815..4165d98cec 100644 --- a/crates/astria-config/src/tests.rs +++ b/crates/astria-config/src/tests.rs @@ -29,8 +29,9 @@ //! } //! ``` +use std::sync::LazyLock; + use figment::Jail; -use once_cell::sync::Lazy; use regex::Regex; use crate::{ @@ -38,7 +39,7 @@ use crate::{ _internal, }; -static TEST_PREFIX: Lazy = Lazy::new(|| { +static TEST_PREFIX: LazyLock = LazyLock::new(|| { use names::{ Generator, Name, @@ -47,8 +48,8 @@ static TEST_PREFIX: Lazy = Lazy::new(|| { }); fn populate_environment_from_example(jail: &mut Jail, unique_test_prefix: &str, example_env: &str) { - static RE_START: Lazy = Lazy::new(|| Regex::new(r"^[[:space:]]+").unwrap()); - static RE_END: Lazy = Lazy::new(|| Regex::new(r"[[:space:]]+$").unwrap()); + static RE_START: LazyLock = LazyLock::new(|| Regex::new(r"^[[:space:]]+").unwrap()); + static RE_END: LazyLock = LazyLock::new(|| Regex::new(r"[[:space:]]+$").unwrap()); for line in example_env.lines() { if let Some((key, val)) = line.trim().split_once('=') { @@ -71,7 +72,7 @@ fn populate_environment_from_example(jail: &mut Jail, unique_test_prefix: &str, /// Panics if a config `C` could not be created from `example_env`. #[track_caller] pub fn example_env_config_is_up_to_date(example_env: &str) { - let unique_test_prefix = Lazy::force(&TEST_PREFIX); + let unique_test_prefix = LazyLock::force(&TEST_PREFIX); let full_test_prefix = format!("{unique_test_prefix}_{}", C::PREFIX); Jail::expect_with(|jail| { diff --git a/crates/astria-sequencer-relayer/Cargo.toml b/crates/astria-sequencer-relayer/Cargo.toml index a2fcb71fbd..ffb70fd44d 100644 --- a/crates/astria-sequencer-relayer/Cargo.toml +++ b/crates/astria-sequencer-relayer/Cargo.toml @@ -77,7 +77,6 @@ celestia-tendermint = { workspace = true } celestia-types = { workspace = true } hyper = { workspace = true } itertools = { workspace = true } -once_cell = { workspace = true } rand_core = { version = "0.6", features = ["getrandom"] } tempfile = { workspace = true } tendermint-rpc = { workspace = true, features = ["http-client"] } diff --git a/crates/astria-sequencer-relayer/tests/blackbox/helpers/test_sequencer_relayer.rs b/crates/astria-sequencer-relayer/tests/blackbox/helpers/test_sequencer_relayer.rs index 041e6a488b..b1d57f9a4c 100644 --- a/crates/astria-sequencer-relayer/tests/blackbox/helpers/test_sequencer_relayer.rs +++ b/crates/astria-sequencer-relayer/tests/blackbox/helpers/test_sequencer_relayer.rs @@ -10,6 +10,7 @@ use std::{ io::Write, mem, net::SocketAddr, + sync::LazyLock, time::Duration, }; @@ -28,7 +29,6 @@ use astria_sequencer_relayer::{ use http::StatusCode; use isahc::AsyncReadResponseExt; use itertools::Itertools; -use once_cell::sync::Lazy; use serde::Deserialize; use serde_json::json; use telemetry::metrics; @@ -123,7 +123,7 @@ const STATUS_RESPONSE: &str = r#" } }"#; -static TELEMETRY: Lazy<()> = Lazy::new(|| { +static TELEMETRY: LazyLock<()> = LazyLock::new(|| { astria_eyre::install().unwrap(); if std::env::var_os("TEST_LOG").is_some() { let filter_directives = std::env::var("RUST_LOG") @@ -675,7 +675,7 @@ impl TestSequencerRelayerConfig { "the sequencer relayer must be run on a multi-threaded runtime, e.g. the test could \ be configured using `#[tokio::test(flavor = \"multi_thread\", worker_threads = 1)]`" ); - Lazy::force(&TELEMETRY); + LazyLock::force(&TELEMETRY); let celestia_app = MockCelestiaAppServer::spawn(self.celestia_chain_id.clone()).await; let celestia_app_grpc_endpoint = format!("http://{}", celestia_app.local_addr);