Skip to content

Commit

Permalink
Migrate to LazyLock
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanoroshiba committed Sep 26, 2024
1 parent 33dae42 commit 2515020
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 36 deletions.
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.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion crates/astria-bridge-withdrawer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{
io::Write as _,
mem,
net::SocketAddr,
sync::LazyLock,
time::Duration,
};

Expand Down Expand Up @@ -37,7 +38,6 @@ use ibc_types::core::{
channel::ChannelId,
client::Height as IbcHeight,
};
use once_cell::sync::Lazy;
use sequencer_client::{
Address,
NonceResponse,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion crates/astria-composer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
6 changes: 3 additions & 3 deletions crates/astria-composer/src/executor/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
IpAddr,
SocketAddr,
},
sync::LazyLock,
time::Duration,
};

Expand All @@ -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 _,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions crates/astria-composer/src/rollup.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Parsing strings of the form `<rollup_name>::<url>`

use std::fmt;
use std::{
fmt,
sync::LazyLock,
};

use once_cell::sync::Lazy;
use regex::Regex;

#[derive(Debug)]
Expand Down Expand Up @@ -33,7 +35,7 @@ impl std::error::Error for ParseError {}

impl Rollup {
pub(super) fn parse(from: &str) -> Result<Self, ParseError> {
static ROLLUP_RE: Lazy<Regex> = Lazy::new(|| {
static ROLLUP_RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(
r"(?x)
^(?P<rollup_name>[[:alnum:]-]+?)
Expand Down
6 changes: 3 additions & 3 deletions crates/astria-composer/tests/blackbox/helper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
IpAddr,
SocketAddr,
},
sync::LazyLock,
time::Duration,
};

Expand All @@ -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::{
Expand All @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion crates/astria-conductor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 6 additions & 4 deletions crates/astria-conductor/tests/blackbox/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::time::Duration;
use std::{
sync::LazyLock,
time::Duration,
};

use astria_conductor::{
conductor,
Expand All @@ -25,7 +28,6 @@ use celestia_types::{
nmt::Namespace,
Blob,
};
use once_cell::sync::Lazy;
use prost::Message;
use sequencer_client::{
tendermint,
Expand All @@ -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());
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions crates/astria-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ 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 }

[dev-dependencies]
serde = { workspace = true, features = ["derive"] }

[features]
tests = ["figment/test", "dep:names", "dep:once_cell", "dep:regex"]
tests = ["figment/test", "dep:names", "dep:regex"]
11 changes: 6 additions & 5 deletions crates/astria-config/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@
//! }
//! ```

use std::sync::LazyLock;

use figment::Jail;
use once_cell::sync::Lazy;
use regex::Regex;

use crate::{
Config,
_internal,
};

static TEST_PREFIX: Lazy<String> = Lazy::new(|| {
static TEST_PREFIX: LazyLock<String> = LazyLock::new(|| {
use names::{
Generator,
Name,
Expand All @@ -47,8 +48,8 @@ static TEST_PREFIX: Lazy<String> = Lazy::new(|| {
});

fn populate_environment_from_example(jail: &mut Jail, unique_test_prefix: &str, example_env: &str) {
static RE_START: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[[:space:]]+").unwrap());
static RE_END: Lazy<Regex> = Lazy::new(|| Regex::new(r"[[:space:]]+$").unwrap());
static RE_START: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^[[:space:]]+").unwrap());
static RE_END: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"[[:space:]]+$").unwrap());

for line in example_env.lines() {
if let Some((key, val)) = line.trim().split_once('=') {
Expand All @@ -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<C: Config>(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| {
Expand Down
1 change: 0 additions & 1 deletion crates/astria-sequencer-relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
io::Write,
mem,
net::SocketAddr,
sync::LazyLock,
time::Duration,
};

Expand All @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2515020

Please sign in to comment.