Skip to content

Commit

Permalink
fix(native_blockifier): activate testing feature only in dev dependen…
Browse files Browse the repository at this point in the history
…cies (#2624)
  • Loading branch information
dorimedini-starkware authored Dec 16, 2024
1 parent 2602630 commit 135ea93
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
1 change: 1 addition & 0 deletions crates/blockifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/blockifier/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

Expand Down
11 changes: 7 additions & 4 deletions crates/native_blockifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 0 additions & 2 deletions crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 12 additions & 13 deletions crates/native_blockifier/src/py_state_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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.
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_native_blockifier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 135ea93

Please sign in to comment.