Skip to content

Commit

Permalink
chore(blockifier): add flag run_native
Browse files Browse the repository at this point in the history
  • Loading branch information
avivg-starkware committed Nov 19, 2024
1 parent a74e125 commit 39fb4fa
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
16 changes: 13 additions & 3 deletions crates/blockifier/src/blockifier/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@ use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct TransactionExecutorConfig {
pub concurrency_config: ConcurrencyConfig,
}
impl TransactionExecutorConfig {
#[cfg(any(test, feature = "testing"))]
pub fn create_for_testing(concurrency_enabled: bool) -> Self {
Self { concurrency_config: ConcurrencyConfig::create_for_testing(concurrency_enabled) }
Self {
concurrency_config: ConcurrencyConfig::create_for_testing(concurrency_enabled),
}
}
}

impl Default for TransactionExecutorConfig {
fn default() -> Self {
TransactionExecutorConfig {
concurrency_config: ConcurrencyConfig::default(),
}
}
}

impl SerializeConfig for TransactionExecutorConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
append_sub_config_name(self.concurrency_config.dump(), "concurrency_config")
Self { concurrency_config: ConcurrencyConfig::create_for_testing(concurrency_enabled) }
}
}

Expand Down
5 changes: 3 additions & 2 deletions crates/blockifier/src/test_utils/transfers_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ impl TransfersGenerator {
let chain_info = block_context.chain_info().clone();
let state =
test_state(&chain_info, config.balance, &[(account_contract, config.n_accounts)]);
let executor_config =
TransactionExecutorConfig { concurrency_config: config.concurrency_config.clone() };
let executor_config = TransactionExecutorConfig {
concurrency_config: config.concurrency_config.clone(),
};
let executor = TransactionExecutor::new(state, block_context, executor_config);
let account_addresses = (0..config.n_accounts)
.map(|instance_id| account_contract.get_instance_address(instance_id))
Expand Down
41 changes: 38 additions & 3 deletions crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ impl ThinTransactionExecutionInfo {
}
}

pub struct MeshiAviConfig {
pub run_cairo_native: bool,
pub block_compilation: bool,
pub global_contract_cache_size: usize,
}

#[pyclass]
pub struct PyBlockExecutor {
pub bouncer_config: BouncerConfig,
Expand All @@ -130,15 +136,18 @@ pub struct PyBlockExecutor {
/// `Send` trait is required for `pyclass` compatibility as Python objects must be threadsafe.
pub storage: Box<dyn Storage + Send>,
pub global_contract_cache: GlobalContractCache,
pub meshi_avi_config: MeshiAviConfig,
}

#[pymethods]
impl PyBlockExecutor {
#[new]
#[pyo3(signature = (bouncer_config, concurrency_config, os_config, global_contract_cache_size, target_storage_config, py_versioned_constants_overrides))]
#[pyo3(signature = (bouncer_config, concurrency_config, run_cairo_native, block_compilation, os_config, global_contract_cache_size, target_storage_config, py_versioned_constants_overrides))]
pub fn create(
bouncer_config: PyBouncerConfig,
concurrency_config: PyConcurrencyConfig,
run_cairo_native: bool,
block_compilation: bool,
os_config: PyOsConfig,
global_contract_cache_size: usize,
target_storage_config: StorageConfig,
Expand All @@ -161,6 +170,11 @@ impl PyBlockExecutor {
tx_executor: None,
storage: Box::new(storage),
global_contract_cache: GlobalContractCache::new(global_contract_cache_size),
meshi_avi_config: MeshiAviConfig {
run_cairo_native,
block_compilation: false,
global_contract_cache_size,
},
}
}

Expand Down Expand Up @@ -368,10 +382,12 @@ impl PyBlockExecutor {
}

#[cfg(any(feature = "testing", test))]
#[pyo3(signature = (concurrency_config, os_config, path, max_state_diff_size))]
#[pyo3(signature = (concurrency_config, run_cairo_native, block_compilation, os_config, path, max_state_diff_size))]
#[staticmethod]
fn create_for_testing(
concurrency_config: PyConcurrencyConfig,
run_cairo_native: bool,
block_compilation: bool,
os_config: PyOsConfig,
path: std::path::PathBuf,
max_state_diff_size: usize,
Expand All @@ -397,6 +413,11 @@ impl PyBlockExecutor {
versioned_constants,
tx_executor: None,
global_contract_cache: GlobalContractCache::new(GLOBAL_CONTRACT_CACHE_SIZE_FOR_TEST),
meshi_avi_config: MeshiAviConfig {
run_cairo_native,
block_compilation,
global_contract_cache_size: GLOBAL_CONTRACT_CACHE_SIZE_FOR_TEST,
},
}
}
}
Expand Down Expand Up @@ -427,17 +448,31 @@ impl PyBlockExecutor {
versioned_constants: VersionedConstants::latest_constants().clone(),
tx_executor: None,
global_contract_cache: GlobalContractCache::new(GLOBAL_CONTRACT_CACHE_SIZE_FOR_TEST),
meshi_avi_config: MeshiAviConfig {
run_cairo_native: false,
block_compilation: false,
global_contract_cache_size: GLOBAL_CONTRACT_CACHE_SIZE_FOR_TEST,
},
}
}

#[cfg(test)]
pub(crate) fn native_create_for_testing(
concurrency_config: PyConcurrencyConfig,
run_cairo_native: bool,
block_compilation: bool,
os_config: PyOsConfig,
path: std::path::PathBuf,
max_state_diff_size: usize,
) -> Self {
Self::create_for_testing(concurrency_config, os_config, path, max_state_diff_size)
Self::create_for_testing(
concurrency_config,
run_cairo_native,
block_compilation,
os_config,
path,
max_state_diff_size,
)
}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/native_blockifier/src/py_block_executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ fn global_contract_cache_update() {
let temp_storage_path = tempfile::tempdir().unwrap().into_path();
let mut block_executor = PyBlockExecutor::create_for_testing(
PyConcurrencyConfig::default(),
false,
false,
PyOsConfig::default(),
temp_storage_path,
4000,
Expand Down Expand Up @@ -119,6 +121,8 @@ fn global_contract_cache_update_large_contract() {
let temp_storage_path = tempfile::tempdir().unwrap().into_path();
let mut block_executor = PyBlockExecutor::native_create_for_testing(
Default::default(),
false,
false,
Default::default(),
temp_storage_path,
4000,
Expand Down

0 comments on commit 39fb4fa

Please sign in to comment.