From c1f53bddfc2e2d819eefed7048f20cfe545a86d7 Mon Sep 17 00:00:00 2001 From: Dori Medini Date: Thu, 22 Aug 2024 18:26:09 +0300 Subject: [PATCH] chore: move from once_cell Lazy to LazyLock Signed-off-by: Dori Medini --- Cargo.lock | 3 --- Dockerfile | 2 +- crates/blockifier/Cargo.toml | 1 - .../src/transaction/transactions_test.rs | 7 +++---- crates/blockifier/src/versioned_constants.rs | 5 ++--- crates/papyrus_execution/Cargo.toml | 1 - crates/papyrus_execution/src/lib.rs | 9 ++++---- crates/papyrus_load_test/src/lib.rs | 5 +++-- crates/starknet_api/Cargo.toml | 1 - .../src/block_hash/block_hash_calculator.rs | 5 +++-- .../src/block_hash/state_diff_hash.rs | 5 +++-- crates/starknet_api/src/core.rs | 4 ++-- crates/starknet_api/src/transaction_hash.rs | 21 ++++++++++--------- 13 files changed, 32 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 37f3e4bd9a..519d8d65a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -993,7 +993,6 @@ dependencies = [ "num-integer", "num-rational 0.4.2", "num-traits 0.2.19", - "once_cell", "papyrus_config", "paste", "phf", @@ -6218,7 +6217,6 @@ dependencies = [ "indexmap 2.2.6", "itertools 0.10.5", "lazy_static", - "once_cell", "papyrus_common", "papyrus_config", "papyrus_storage", @@ -8776,7 +8774,6 @@ dependencies = [ "hex", "indexmap 2.2.6", "itertools 0.12.1", - "once_cell", "primitive-types", "rstest", "serde", diff --git a/Dockerfile b/Dockerfile index 25fc653bbd..c362597fc2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ # More info on Cargo Chef: https://github.com/LukeMathWalker/cargo-chef # We start by creating a base image using 'clux/muslrust' with additional required tools. -FROM clux/muslrust:1.78.0-stable AS chef +FROM clux/muslrust:1.80.0-stable AS chef WORKDIR /app RUN apt update && apt install -y clang unzip RUN cargo install cargo-chef diff --git a/crates/blockifier/Cargo.toml b/crates/blockifier/Cargo.toml index 3b5166d4bc..ff05d295a1 100644 --- a/crates/blockifier/Cargo.toml +++ b/crates/blockifier/Cargo.toml @@ -37,7 +37,6 @@ num-bigint.workspace = true num-integer.workspace = true num-rational.workspace = true num-traits.workspace = true -once_cell.workspace = true papyrus_config.workspace = true paste.workspace = true phf.workspace = true diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index ba19708ece..d2cc57470a 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -1,12 +1,11 @@ use std::collections::{HashMap, HashSet}; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use assert_matches::assert_matches; use cairo_vm::types::builtin_name::BuiltinName; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use num_bigint::BigUint; use num_traits::Pow; -use once_cell::sync::Lazy; use pretty_assertions::assert_eq; use rstest::{fixture, rstest}; use starknet_api::core::{ChainId, ClassHash, ContractAddress, EthAddress, Nonce, PatriciaKey}; @@ -131,8 +130,8 @@ use crate::{ retdata, }; -static VERSIONED_CONSTANTS: Lazy = - Lazy::new(VersionedConstants::create_for_testing); +static VERSIONED_CONSTANTS: LazyLock = + LazyLock::new(VersionedConstants::create_for_testing); #[fixture] fn tx_initial_gas() -> u64 { diff --git a/crates/blockifier/src/versioned_constants.rs b/crates/blockifier/src/versioned_constants.rs index cb7d7086a1..f6b50e855c 100644 --- a/crates/blockifier/src/versioned_constants.rs +++ b/crates/blockifier/src/versioned_constants.rs @@ -1,13 +1,12 @@ use std::collections::{HashMap, HashSet}; use std::io; use std::path::Path; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use cairo_vm::types::builtin_name::BuiltinName; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use indexmap::{IndexMap, IndexSet}; use num_rational::Ratio; -use once_cell::sync::Lazy; use paste::paste; use serde::de::Error as DeserializationError; use serde::{Deserialize, Deserializer}; @@ -43,7 +42,7 @@ macro_rules! define_versioned_constants { $( pub(crate) const []: &str = include_str!($path_to_json); - static []: Lazy = Lazy::new(|| { + static []: LazyLock = LazyLock::new(|| { serde_json::from_str([]) .expect(&format!("Versioned constants {} is malformed.", $path_to_json)) }); diff --git a/crates/papyrus_execution/Cargo.toml b/crates/papyrus_execution/Cargo.toml index fbfff50d3c..1cfe387fd5 100644 --- a/crates/papyrus_execution/Cargo.toml +++ b/crates/papyrus_execution/Cargo.toml @@ -17,7 +17,6 @@ cairo-vm.workspace = true indexmap.workspace = true itertools.workspace = true lazy_static.workspace = true -once_cell.workspace = true papyrus_common.workspace = true papyrus_config.workspace = true papyrus_storage.workspace = true diff --git a/crates/papyrus_execution/src/lib.rs b/crates/papyrus_execution/src/lib.rs index cf33b85b2c..f08fadcebd 100644 --- a/crates/papyrus_execution/src/lib.rs +++ b/crates/papyrus_execution/src/lib.rs @@ -23,7 +23,7 @@ use std::cell::Cell; use std::collections::BTreeMap; use std::num::NonZeroU128; use std::path::Path; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use blockifier::blockifier::block::{pre_process_block, BlockInfo, BlockNumberHashPair, GasPrices}; use blockifier::bouncer::BouncerConfig; @@ -50,7 +50,6 @@ use cairo_vm::types::builtin_name::BuiltinName; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use execution_utils::{get_trace_constructor, induced_state_diff}; use objects::{PriceUnit, TransactionSimulationOutput}; -use once_cell::sync::Lazy; use papyrus_common::transaction_hash::get_transaction_hash; use papyrus_common::TransactionOptions; use papyrus_config::dumping::{ser_param, SerializeConfig}; @@ -99,16 +98,16 @@ const INITIAL_GAS_COST: u64 = 10000000000; /// Result type for execution functions. pub type ExecutionResult = Result; -static VERSIONED_CONSTANTS_13_0: Lazy = Lazy::new(|| { +static VERSIONED_CONSTANTS_13_0: LazyLock = LazyLock::new(|| { VersionedConstants::try_from(Path::new("./resources/versioned_constants_13_0.json")) .expect("Versioned constants JSON file is malformed") }); -static VERSIONED_CONSTANTS_13_1: Lazy = Lazy::new(|| { +static VERSIONED_CONSTANTS_13_1: LazyLock = LazyLock::new(|| { VersionedConstants::try_from(Path::new("./resources/versioned_constants_13_1.json")) .expect("Versioned constants JSON file is malformed") }); -static VERSIONED_CONSTANTS_13_2: Lazy = Lazy::new(|| { +static VERSIONED_CONSTANTS_13_2: LazyLock = LazyLock::new(|| { VersionedConstants::try_from(Path::new("./resources/versioned_constants_13_2.json")) .expect("Versioned constants JSON file is malformed") }); diff --git a/crates/papyrus_load_test/src/lib.rs b/crates/papyrus_load_test/src/lib.rs index bdc031a2a3..e8e259cef9 100644 --- a/crates/papyrus_load_test/src/lib.rs +++ b/crates/papyrus_load_test/src/lib.rs @@ -13,10 +13,11 @@ mod precision_test; pub mod scenarios; pub mod transactions; +use std::sync::LazyLock; use std::{env, fs}; use goose::goose::{GooseUser, TransactionError}; -use once_cell::sync::{Lazy, OnceCell}; +use once_cell::sync::OnceCell; use rand::Rng; use serde::Deserialize; use serde_json::{json, Value as jsonVal}; @@ -109,7 +110,7 @@ const TRACE_BLOCK_TRANSACTIONS_BY_HASH_WEIGHT: usize = 10; const TRACE_BLOCK_TRANSACTIONS_BY_NUMBER_WEIGHT: usize = 10; const TRACE_TRANSACTION_WEIGHT: usize = 10; -static RPC_VERSION_ID: Lazy = Lazy::new(|| match std::env::var("VERSION_ID") { +static RPC_VERSION_ID: LazyLock = LazyLock::new(|| match std::env::var("VERSION_ID") { Ok(version_id) => version_id, Err(_) => unreachable!("VERSION_ID environment variable is not set"), }); diff --git a/crates/starknet_api/Cargo.toml b/crates/starknet_api/Cargo.toml index cc04220d6c..52597dcf4d 100644 --- a/crates/starknet_api/Cargo.toml +++ b/crates/starknet_api/Cargo.toml @@ -16,7 +16,6 @@ derive_more = "0.99.17" hex = "0.4.3" indexmap = { version = "2.1.0", features = ["serde"] } itertools = "0.12.1" -once_cell = "1.17.1" primitive-types = { version = "0.12.1", features = ["serde"] } serde = { version = "1.0.130", features = ["derive", "rc"] } serde_json = "1.0.81" diff --git a/crates/starknet_api/src/block_hash/block_hash_calculator.rs b/crates/starknet_api/src/block_hash/block_hash_calculator.rs index ae36d164b7..a4dcdf3c40 100644 --- a/crates/starknet_api/src/block_hash/block_hash_calculator.rs +++ b/crates/starknet_api/src/block_hash/block_hash_calculator.rs @@ -1,4 +1,5 @@ -use once_cell::sync::Lazy; +use std::sync::LazyLock; + use serde::{Deserialize, Serialize}; use starknet_types_core::felt::Felt; use starknet_types_core::hash::Poseidon; @@ -27,7 +28,7 @@ use crate::transaction_hash::ascii_as_felt; #[path = "block_hash_calculator_test.rs"] mod block_hash_calculator_test; -static STARKNET_BLOCK_HASH0: Lazy = Lazy::new(|| { +static STARKNET_BLOCK_HASH0: LazyLock = LazyLock::new(|| { ascii_as_felt("STARKNET_BLOCK_HASH0").expect("ascii_as_felt failed for 'STARKNET_BLOCK_HASH0'") }); diff --git a/crates/starknet_api/src/block_hash/state_diff_hash.rs b/crates/starknet_api/src/block_hash/state_diff_hash.rs index d588992bfd..9713446d6f 100644 --- a/crates/starknet_api/src/block_hash/state_diff_hash.rs +++ b/crates/starknet_api/src/block_hash/state_diff_hash.rs @@ -1,5 +1,6 @@ +use std::sync::LazyLock; + use indexmap::IndexMap; -use once_cell::sync::Lazy; use starknet_types_core::felt::Felt; use crate::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce, StateDiffCommitment}; @@ -12,7 +13,7 @@ use crate::transaction_hash::ascii_as_felt; #[path = "state_diff_hash_test.rs"] mod state_diff_hash_test; -static STARKNET_STATE_DIFF0: Lazy = Lazy::new(|| { +static STARKNET_STATE_DIFF0: LazyLock = LazyLock::new(|| { ascii_as_felt("STARKNET_STATE_DIFF0").expect("ascii_as_felt failed for 'STARKNET_STATE_DIFF0'") }); diff --git a/crates/starknet_api/src/core.rs b/crates/starknet_api/src/core.rs index ab9f3754b7..03147360c6 100644 --- a/crates/starknet_api/src/core.rs +++ b/crates/starknet_api/src/core.rs @@ -4,9 +4,9 @@ mod core_test; use core::fmt::Display; use std::fmt::Debug; +use std::sync::LazyLock; use derive_more::Display; -use once_cell::sync::Lazy; use primitive_types::H160; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use starknet_types_core::felt::{Felt, NonZeroFelt}; @@ -117,7 +117,7 @@ pub const CONTRACT_ADDRESS_PREFIX: &str = "STARKNET_CONTRACT_ADDRESS"; /// The size of the contract address domain. pub const CONTRACT_ADDRESS_DOMAIN_SIZE: Felt = Felt::from_hex_unchecked(PATRICIA_KEY_UPPER_BOUND); /// The address upper bound; it is defined to be congruent with the storage var address upper bound. -pub static L2_ADDRESS_UPPER_BOUND: Lazy = Lazy::new(|| { +pub static L2_ADDRESS_UPPER_BOUND: LazyLock = LazyLock::new(|| { NonZeroFelt::try_from(CONTRACT_ADDRESS_DOMAIN_SIZE - Felt::from(MAX_STORAGE_ITEM_SIZE)).unwrap() }); diff --git a/crates/starknet_api/src/transaction_hash.rs b/crates/starknet_api/src/transaction_hash.rs index b7daf1fd97..b769d64072 100644 --- a/crates/starknet_api/src/transaction_hash.rs +++ b/crates/starknet_api/src/transaction_hash.rs @@ -1,4 +1,5 @@ -use once_cell::sync::Lazy; +use std::sync::LazyLock; + use starknet_types_core::felt::Felt; use crate::block::BlockNumber; @@ -35,17 +36,17 @@ const DATA_AVAILABILITY_MODE_BITS: usize = 32; const L1_GAS: &ResourceName = b"\0L1_GAS"; const L2_GAS: &ResourceName = b"\0L2_GAS"; -static DECLARE: Lazy = - Lazy::new(|| ascii_as_felt("declare").expect("ascii_as_felt failed for 'declare'")); -static DEPLOY: Lazy = - Lazy::new(|| ascii_as_felt("deploy").expect("ascii_as_felt failed for 'deploy'")); -static DEPLOY_ACCOUNT: Lazy = Lazy::new(|| { +static DECLARE: LazyLock = + LazyLock::new(|| ascii_as_felt("declare").expect("ascii_as_felt failed for 'declare'")); +static DEPLOY: LazyLock = + LazyLock::new(|| ascii_as_felt("deploy").expect("ascii_as_felt failed for 'deploy'")); +static DEPLOY_ACCOUNT: LazyLock = LazyLock::new(|| { ascii_as_felt("deploy_account").expect("ascii_as_felt failed for 'deploy_account'") }); -static INVOKE: Lazy = - Lazy::new(|| ascii_as_felt("invoke").expect("ascii_as_felt failed for 'invoke'")); -static L1_HANDLER: Lazy = - Lazy::new(|| ascii_as_felt("l1_handler").expect("ascii_as_felt failed for 'l1_handler'")); +static INVOKE: LazyLock = + LazyLock::new(|| ascii_as_felt("invoke").expect("ascii_as_felt failed for 'invoke'")); +static L1_HANDLER: LazyLock = + LazyLock::new(|| ascii_as_felt("l1_handler").expect("ascii_as_felt failed for 'l1_handler'")); const CONSTRUCTOR_ENTRY_POINT_SELECTOR: Felt = Felt::from_hex_unchecked("0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194");