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 17, 2024
1 parent d0a84e0 commit 055b750
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
5 changes: 5 additions & 0 deletions config/sequencer/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
"privacy": "Public",
"value": 0
},
"batcher_config.block_builder_config.execute_config.run_native": {
"description": "Flag to enable or disable the use of native execution.",
"privacy": "Public",
"value": true
},
"batcher_config.block_builder_config.sequencer_address": {
"description": "The address of the sequencer.",
"privacy": "Public",
Expand Down
27 changes: 24 additions & 3 deletions crates/blockifier/src/blockifier/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,41 @@ 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,
pub run_native: bool,
}
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),
run_native: true, // TODO(AvivG): Default value should be different?
}
}
}

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

impl SerializeConfig for TransactionExecutorConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
append_sub_config_name(self.concurrency_config.dump(), "concurrency_config")
let mut dump = append_sub_config_name(self.concurrency_config.dump(), "concurrency_config");
dump.append(&mut BTreeMap::from([ser_param(
"run_native",
&self.run_native,
"Flag to enable or disable the use of native execution.",
ParamPrivacyInput::Public,
)]));

dump
}
}

Expand Down
8 changes: 6 additions & 2 deletions crates/blockifier/src/test_utils/transfers_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct TransfersGeneratorConfig {
pub tx_version: TransactionVersion,
pub recipient_generator_type: RecipientGeneratorType,
pub concurrency_config: ConcurrencyConfig,
pub run_native: bool,
}

impl Default for TransfersGeneratorConfig {
Expand All @@ -51,6 +52,7 @@ impl Default for TransfersGeneratorConfig {
tx_version: TRANSACTION_VERSION,
recipient_generator_type: RECIPIENT_GENERATOR_TYPE,
concurrency_config: ConcurrencyConfig::create_for_testing(false),
run_native: true,
}
}
}
Expand Down Expand Up @@ -79,8 +81,10 @@ 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(),
run_native: true,
};
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
17 changes: 14 additions & 3 deletions crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ pub struct PyBlockExecutor {
#[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_native, os_config, global_contract_cache_size, target_storage_config, py_versioned_constants_overrides))]
pub fn create(
bouncer_config: PyBouncerConfig,
concurrency_config: PyConcurrencyConfig,
run_native: bool,
os_config: PyOsConfig,
global_contract_cache_size: usize,
target_storage_config: StorageConfig,
Expand All @@ -155,6 +156,7 @@ impl PyBlockExecutor {
bouncer_config: bouncer_config.try_into().expect("Failed to parse bouncer config."),
tx_executor_config: TransactionExecutorConfig {
concurrency_config: concurrency_config.into(),
run_native,
},
chain_info: os_config.into_chain_info(),
versioned_constants,
Expand Down Expand Up @@ -368,10 +370,11 @@ impl PyBlockExecutor {
}

#[cfg(any(feature = "testing", test))]
#[pyo3(signature = (concurrency_config, os_config, path, max_state_diff_size))]
#[pyo3(signature = (concurrency_config, run_native, os_config, path, max_state_diff_size))]
#[staticmethod]
fn create_for_testing(
concurrency_config: PyConcurrencyConfig,
run_native: bool,
os_config: PyOsConfig,
path: std::path::PathBuf,
max_state_diff_size: usize,
Expand All @@ -391,6 +394,7 @@ impl PyBlockExecutor {
},
tx_executor_config: TransactionExecutorConfig {
concurrency_config: concurrency_config.into(),
run_native,
},
storage: Box::new(PapyrusStorage::new_for_testing(path, &os_config.chain_id)),
chain_info: os_config.into_chain_info(),
Expand Down Expand Up @@ -433,11 +437,18 @@ impl PyBlockExecutor {
#[cfg(test)]
pub(crate) fn native_create_for_testing(
concurrency_config: PyConcurrencyConfig,
run_native: 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_native,
os_config,
path,
max_state_diff_size,
)
}
}

Expand Down
2 changes: 2 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,7 @@ fn global_contract_cache_update() {
let temp_storage_path = tempfile::tempdir().unwrap().into_path();
let mut block_executor = PyBlockExecutor::create_for_testing(
PyConcurrencyConfig::default(),
true, // TODO(AvivG): Default value should be different?
PyOsConfig::default(),
temp_storage_path,
4000,
Expand Down Expand Up @@ -119,6 +120,7 @@ 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(),
true, // TODO(Aviv): Default value should be different?
Default::default(),
temp_storage_path,
4000,
Expand Down

0 comments on commit 055b750

Please sign in to comment.