From 135ea9346be9e112c85b1745726de6ec2262ebac Mon Sep 17 00:00:00 2001 From: dorimedini-starkware Date: Mon, 16 Dec 2024 16:04:11 +0200 Subject: [PATCH] fix(native_blockifier): activate testing feature only in dev dependencies (#2624) --- crates/blockifier/Cargo.toml | 1 + crates/blockifier/src/blockifier/config.rs | 2 +- crates/blockifier/src/test_utils.rs | 4 +-- crates/native_blockifier/Cargo.toml | 11 +++++--- .../src/py_block_executor.rs | 2 -- crates/native_blockifier/src/py_state_diff.rs | 25 +++++++++---------- scripts/build_native_blockifier.sh | 2 +- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/crates/blockifier/Cargo.toml b/crates/blockifier/Cargo.toml index 7e2d1926c7..8ee89d0e33 100644 --- a/crates/blockifier/Cargo.toml +++ b/crates/blockifier/Cargo.toml @@ -12,6 +12,7 @@ workspace = true [features] cairo_native = ["dep:cairo-native", "dep:stacker", "starknet_sierra_compile/cairo_native"] jemalloc = ["dep:tikv-jemallocator"] +native_blockifier = [] reexecution = ["transaction_serde"] testing = ["rand", "rstest", "starknet_api/testing"] transaction_serde = [] diff --git a/crates/blockifier/src/blockifier/config.rs b/crates/blockifier/src/blockifier/config.rs index bc8b5628ce..aca073f1b4 100644 --- a/crates/blockifier/src/blockifier/config.rs +++ b/crates/blockifier/src/blockifier/config.rs @@ -11,7 +11,7 @@ pub struct TransactionExecutorConfig { pub concurrency_config: ConcurrencyConfig, } impl TransactionExecutorConfig { - #[cfg(any(test, feature = "testing"))] + #[cfg(any(test, feature = "testing", feature = "native_blockifier"))] pub fn create_for_testing(concurrency_enabled: bool) -> Self { Self { concurrency_config: ConcurrencyConfig::create_for_testing(concurrency_enabled) } } diff --git a/crates/blockifier/src/test_utils.rs b/crates/blockifier/src/test_utils.rs index 9d2741cf2b..2677bfd4c6 100644 --- a/crates/blockifier/src/test_utils.rs +++ b/crates/blockifier/src/test_utils.rs @@ -149,11 +149,11 @@ pub const MAX_L1_DATA_GAS_PRICE: NonzeroGasPrice = DEFAULT_STRK_L1_DATA_GAS_PRIC pub const DEFAULT_ETH_L1_GAS_PRICE: NonzeroGasPrice = NonzeroGasPrice::new_unchecked(GasPrice(100 * u128::pow(10, 9))); // Given in units of Wei. pub const DEFAULT_STRK_L1_GAS_PRICE: NonzeroGasPrice = - NonzeroGasPrice::new_unchecked(GasPrice(100 * u128::pow(10, 9))); // Given in units of STRK. + NonzeroGasPrice::new_unchecked(GasPrice(100 * u128::pow(10, 9))); // Given in units of Fri. pub const DEFAULT_ETH_L1_DATA_GAS_PRICE: NonzeroGasPrice = NonzeroGasPrice::new_unchecked(GasPrice(u128::pow(10, 6))); // Given in units of Wei. pub const DEFAULT_STRK_L1_DATA_GAS_PRICE: NonzeroGasPrice = - NonzeroGasPrice::new_unchecked(GasPrice(u128::pow(10, 9))); // Given in units of STRK. + NonzeroGasPrice::new_unchecked(GasPrice(u128::pow(10, 9))); // Given in units of Fri. pub const DEFAULT_STRK_L2_GAS_PRICE: NonzeroGasPrice = NonzeroGasPrice::new_unchecked(GasPrice(u128::pow(10, 9))); diff --git a/crates/native_blockifier/Cargo.toml b/crates/native_blockifier/Cargo.toml index f89b39baf0..7a04c090bc 100644 --- a/crates/native_blockifier/Cargo.toml +++ b/crates/native_blockifier/Cargo.toml @@ -11,7 +11,7 @@ description = "A Bridge between the Rust blockifier crate and Python." # On Python, make sure to compile this with the extension-module feature enabled. # https://pyo3.rs/v0.19.1/faq#i-cant-run-cargo-test-or-i-cant-build-in-a-cargo-workspace-im-having-linker-issues-like-symbol-not-found-or-undefined-reference-to-_pyexc_systemerror extension-module = ["pyo3/extension-module"] -testing = [] +testing = ["blockifier/testing", "papyrus_storage/testing", "starknet_api/testing"] [lints] workspace = true @@ -27,23 +27,26 @@ crate-type = ["cdylib"] [dependencies] # TODO(Dori, 1/1/2025): Add the "jemalloc" feature to the blockifier crate when possible. -blockifier = { workspace = true, features = ["cairo_native", "testing"] } +blockifier = { workspace = true, features = ["cairo_native", "native_blockifier"] } cairo-lang-starknet-classes.workspace = true cairo-vm.workspace = true indexmap.workspace = true log.workspace = true num-bigint.workspace = true papyrus_state_reader.workspace = true -papyrus_storage = { workspace = true, features = ["testing"] } +papyrus_storage.workspace = true pyo3 = { workspace = true, features = ["hashbrown", "num-bigint"] } pyo3-log.workspace = true serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, features = ["arbitrary_precision"] } starknet-types-core.workspace = true -starknet_api = { workspace = true, features = ["testing"] } +starknet_api.workspace = true thiserror.workspace = true [dev-dependencies] +blockifier = { workspace = true, features = ["cairo_native", "native_blockifier", "testing"] } cached.workspace = true +papyrus_storage = { workspace = true, features = ["testing"] } pretty_assertions.workspace = true +starknet_api = { workspace = true, features = ["testing"] } tempfile.workspace = true diff --git a/crates/native_blockifier/src/py_block_executor.rs b/crates/native_blockifier/src/py_block_executor.rs index af89ed8a5d..57a92a16d1 100644 --- a/crates/native_blockifier/src/py_block_executor.rs +++ b/crates/native_blockifier/src/py_block_executor.rs @@ -379,7 +379,6 @@ impl PyBlockExecutor { self.storage.close(); } - #[cfg(any(feature = "testing", test))] #[pyo3(signature = (concurrency_config, contract_class_manager_config, os_config, path, max_state_diff_size))] #[staticmethod] fn create_for_testing( @@ -431,7 +430,6 @@ impl PyBlockExecutor { ) } - #[cfg(any(feature = "testing", test))] pub fn create_for_testing_with_storage(storage: impl Storage + Send + 'static) -> Self { use blockifier::state::global_cache::GLOBAL_CONTRACT_CACHE_SIZE_FOR_TEST; Self { diff --git a/crates/native_blockifier/src/py_state_diff.rs b/crates/native_blockifier/src/py_state_diff.rs index 76a6063cbe..b6e6647ff1 100644 --- a/crates/native_blockifier/src/py_state_diff.rs +++ b/crates/native_blockifier/src/py_state_diff.rs @@ -3,17 +3,11 @@ use std::convert::TryFrom; use blockifier::blockifier::block::validated_gas_prices; use blockifier::state::cached_state::CommitmentStateDiff; -use blockifier::test_utils::{ - DEFAULT_ETH_L1_DATA_GAS_PRICE, - DEFAULT_ETH_L1_GAS_PRICE, - DEFAULT_STRK_L1_DATA_GAS_PRICE, - DEFAULT_STRK_L1_GAS_PRICE, -}; use blockifier::versioned_constants::VersionedConstants; use indexmap::IndexMap; use pyo3::prelude::*; use pyo3::FromPyObject; -use starknet_api::block::{BlockInfo, BlockNumber, BlockTimestamp, NonzeroGasPrice}; +use starknet_api::block::{BlockInfo, BlockNumber, BlockTimestamp, GasPrice, NonzeroGasPrice}; use starknet_api::core::{ClassHash, ContractAddress, Nonce}; use starknet_api::state::{StateDiff, StorageKey}; @@ -25,6 +19,11 @@ use crate::errors::{ }; use crate::py_utils::PyFelt; +const DEFAULT_ETH_L1_GAS_PRICE: GasPrice = GasPrice(100 * u128::pow(10, 9)); +const DEFAULT_STRK_L1_GAS_PRICE: GasPrice = GasPrice(100 * u128::pow(10, 9)); +const DEFAULT_ETH_L1_DATA_GAS_PRICE: GasPrice = GasPrice(u128::pow(10, 6)); +const DEFAULT_STRK_L1_DATA_GAS_PRICE: GasPrice = GasPrice(u128::pow(10, 9)); + #[pyclass] #[derive(Default, FromPyObject)] // TODO: Add support for returning the `declared_classes` to python. @@ -153,19 +152,19 @@ impl Default for PyBlockInfo { block_number: u64::default(), block_timestamp: u64::default(), l1_gas_price: PyResourcePrice { - price_in_wei: DEFAULT_ETH_L1_GAS_PRICE.get().0, - price_in_fri: DEFAULT_STRK_L1_GAS_PRICE.get().0, + price_in_wei: DEFAULT_ETH_L1_GAS_PRICE.0, + price_in_fri: DEFAULT_STRK_L1_GAS_PRICE.0, }, l1_data_gas_price: PyResourcePrice { - price_in_wei: DEFAULT_ETH_L1_DATA_GAS_PRICE.get().0, - price_in_fri: DEFAULT_STRK_L1_DATA_GAS_PRICE.get().0, + price_in_wei: DEFAULT_ETH_L1_DATA_GAS_PRICE.0, + price_in_fri: DEFAULT_STRK_L1_DATA_GAS_PRICE.0, }, l2_gas_price: PyResourcePrice { price_in_wei: VersionedConstants::latest_constants() - .convert_l1_to_l2_gas_price_round_up(DEFAULT_ETH_L1_GAS_PRICE.into()) + .convert_l1_to_l2_gas_price_round_up(DEFAULT_ETH_L1_GAS_PRICE) .0, price_in_fri: VersionedConstants::latest_constants() - .convert_l1_to_l2_gas_price_round_up(DEFAULT_STRK_L1_GAS_PRICE.into()) + .convert_l1_to_l2_gas_price_round_up(DEFAULT_STRK_L1_GAS_PRICE) .0, }, sequencer_address: PyFelt::default(), diff --git a/scripts/build_native_blockifier.sh b/scripts/build_native_blockifier.sh index dc6b4646d3..e972bc8574 100755 --- a/scripts/build_native_blockifier.sh +++ b/scripts/build_native_blockifier.sh @@ -16,7 +16,7 @@ function build() { echo "Building..." pypy3.9 -m venv /tmp/venv source /tmp/venv/bin/activate - cargo build --release -p native_blockifier --features "testing" || clean + cargo build --release -p native_blockifier || clean clean }