Skip to content

Commit

Permalink
chore: replace lazy_static with once_lock and remove lazy static (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware authored Jul 3, 2024
1 parent 1d8b65f commit e2a3b42
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 19 deletions.
2 changes: 0 additions & 2 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 @@ -50,7 +50,6 @@ futures = "0.3.30"
hyper = { version = "0.14", features = ["client", "http1", "http2"] }
indexmap = "2.1.0"
itertools = "0.13.0"
lazy_static = "1.4.0"
num-bigint = { version = "0.4.5", default-features = false }
# TODO(YaelD, 28/5/2024): The special Papyrus version is needed in order to be aligned with the
# starknet-api version. This should be removed once we have a mono-repo.
Expand Down
3 changes: 1 addition & 2 deletions crates/gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ blockifier= { workspace = true , features = ["testing"] }
cairo-lang-starknet-classes.workspace = true
cairo-vm.workspace = true
hyper.workspace = true
lazy_static.workspace = true
papyrus_config.workspace = true
papyrus_rpc.workspace = true
reqwest.workspace = true
Expand All @@ -37,4 +36,4 @@ validator.workspace = true
assert_matches.workspace = true
pretty_assertions.workspace = true
rstest.workspace = true
starknet_mempool = { path = "../mempool", version = "0.0" }
starknet_mempool = { path = "../mempool", version = "0.0" }
14 changes: 7 additions & 7 deletions crates/gateway/src/gateway.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::clone::Clone;
use std::net::SocketAddr;
use std::panic;
use std::sync::Arc;
use std::sync::{Arc, OnceLock};

use async_trait::async_trait;
use axum::extract::State;
Expand All @@ -12,7 +12,6 @@ use blockifier::execution::execution_utils::felt_to_stark_felt;
use cairo_lang_starknet_classes::casm_contract_class::{
CasmContractClass, CasmContractEntryPoints,
};
use lazy_static::lazy_static;
use starknet_api::core::CompiledClassHash;
use starknet_api::rpc_transaction::{RPCDeclareTransaction, RPCTransaction};
use starknet_api::transaction::TransactionHash;
Expand Down Expand Up @@ -208,13 +207,14 @@ impl ComponentRunner for Gateway {
// TODO(Arni): Add to a config.
// TODO(Arni): Use the Builtin enum from Starknet-api, and explicitly tag each builtin as supported
// or unsupported so that the compiler would alert us on new builtins.
lazy_static! {
static ref SUPPORTED_BUILTINS: Vec<String> = {
fn supported_builtins() -> &'static Vec<String> {
static SUPPORTED_BUILTINS: OnceLock<Vec<String>> = OnceLock::new();
SUPPORTED_BUILTINS.get_or_init(|| {
// The OS expects this order for the builtins.
const SUPPORTED_BUILTIN_NAMES: [&str; 7] =
["pedersen", "range_check", "ecdsa", "bitwise", "ec_op", "poseidon", "segment_arena"];
SUPPORTED_BUILTIN_NAMES.iter().map(|builtin| builtin.to_string()).collect::<Vec<String>>()
};
})
}

// TODO(Arni): Add test.
Expand All @@ -225,10 +225,10 @@ fn validate_casm_class(contract_class: &CasmContractClass) -> Result<(), Gateway

for entry_point in entry_points_iterator {
let builtins = &entry_point.builtins;
if !is_subsequence(builtins, &SUPPORTED_BUILTINS) {
if !is_subsequence(builtins, supported_builtins()) {
return Err(GatewayError::UnsupportedBuiltins {
builtins: builtins.clone(),
supported_builtins: SUPPORTED_BUILTINS.to_vec(),
supported_builtins: supported_builtins().to_vec(),
});
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/tests-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ axum.workspace = true
blockifier.workspace = true
cairo-lang-starknet-classes.workspace = true
indexmap.workspace = true
lazy_static.workspace = true
papyrus_common.workspace = true
papyrus_rpc.workspace = true
papyrus_storage.workspace = true
Expand Down
12 changes: 6 additions & 6 deletions crates/tests-integration/src/state_reader.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::net::SocketAddr;
use std::sync::Arc;
use std::sync::{Arc, OnceLock};

use blockifier::abi::abi_utils::get_fee_token_var_address;
use blockifier::context::{BlockContext, ChainInfo};
Expand All @@ -11,7 +11,6 @@ use blockifier::test_utils::{
use blockifier::transaction::objects::FeeType;
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use indexmap::{indexmap, IndexMap};
use lazy_static::lazy_static;
use papyrus_common::pending_classes::PendingClasses;
use papyrus_common::BlockHashAndNumber;
use papyrus_rpc::{run_server, RpcConfig};
Expand Down Expand Up @@ -40,11 +39,12 @@ use tokio::sync::RwLock;
type ContractClassesMap =
(Vec<(ClassHash, DeprecatedContractClass)>, Vec<(ClassHash, CasmContractClass)>);

lazy_static! {
static ref DEPLOY_ACCCOUNT_TX_CONTRACT_ADDRESS: ContractAddress = {
fn deploy_account_tx_contract_address() -> &'static ContractAddress {
static DEPLOY_ACCOUNT_TX_CONTRACT_ADDRESS: OnceLock<ContractAddress> = OnceLock::new();
DEPLOY_ACCOUNT_TX_CONTRACT_ADDRESS.get_or_init(|| {
let deploy_tx = deploy_account_tx();
deployed_account_contract_address(&deploy_tx)
};
})
}

/// StateReader for integration tests.
Expand All @@ -62,7 +62,7 @@ pub async fn rpc_test_state_reader_factory(
let account_contract_cairo1 = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1);
let test_contract_cairo1 = FeatureContract::TestContract(CairoVersion::Cairo1);
let erc20 = FeatureContract::ERC20;
let fund_accounts = vec![*DEPLOY_ACCCOUNT_TX_CONTRACT_ADDRESS];
let fund_accounts = vec![*deploy_account_tx_contract_address()];

let storage_reader = initialize_papyrus_test_state(
block_context.chain_info(),
Expand Down

0 comments on commit e2a3b42

Please sign in to comment.