Skip to content

Commit

Permalink
chore:(native_blockifier): convert general config to os config
Browse files Browse the repository at this point in the history
  • Loading branch information
amosStarkware committed Aug 22, 2024
1 parent df672bc commit 3c2a46d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
28 changes: 9 additions & 19 deletions crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ pub struct PyBlockExecutor {
#[pymethods]
impl PyBlockExecutor {
#[new]
#[pyo3(signature = (bouncer_config, concurrency_config, general_config, global_contract_cache_size, target_storage_config, py_versioned_constants_overrides))]
#[pyo3(signature = (bouncer_config, concurrency_config, os_config, global_contract_cache_size, target_storage_config, py_versioned_constants_overrides))]
pub fn create(
bouncer_config: PyBouncerConfig,
concurrency_config: PyConcurrencyConfig,
general_config: PyGeneralConfig,
os_config: PyOsConfig,
global_contract_cache_size: usize,
target_storage_config: StorageConfig,
py_versioned_constants_overrides: PyVersionedConstantsOverrides,
Expand All @@ -112,7 +112,7 @@ impl PyBlockExecutor {
tx_executor_config: TransactionExecutorConfig {
concurrency_config: concurrency_config.into(),
},
chain_info: general_config.starknet_os_config.into_chain_info(),
chain_info: os_config.into_chain_info(),
versioned_constants,
tx_executor: None,
storage: Box::new(storage),
Expand Down Expand Up @@ -333,11 +333,11 @@ impl PyBlockExecutor {
}

#[cfg(any(feature = "testing", test))]
#[pyo3(signature = (concurrency_config, general_config, path, max_state_diff_size))]
#[pyo3(signature = (concurrency_config, os_config, path, max_state_diff_size))]
#[staticmethod]
fn create_for_testing(
concurrency_config: PyConcurrencyConfig,
general_config: PyGeneralConfig,
os_config: PyOsConfig,
path: std::path::PathBuf,
max_state_diff_size: usize,
) -> Self {
Expand All @@ -357,11 +357,8 @@ impl PyBlockExecutor {
tx_executor_config: TransactionExecutorConfig {
concurrency_config: concurrency_config.into(),
},
storage: Box::new(PapyrusStorage::new_for_testing(
path,
&general_config.starknet_os_config.chain_id,
)),
chain_info: general_config.starknet_os_config.into_chain_info(),
storage: Box::new(PapyrusStorage::new_for_testing(path, &os_config.chain_id)),
chain_info: os_config.into_chain_info(),
versioned_constants,
tx_executor: None,
global_contract_cache: GlobalContractCache::new(GLOBAL_CONTRACT_CACHE_SIZE_FOR_TEST),
Expand Down Expand Up @@ -401,21 +398,14 @@ impl PyBlockExecutor {
#[cfg(test)]
pub(crate) fn native_create_for_testing(
concurrency_config: PyConcurrencyConfig,
general_config: PyGeneralConfig,
os_config: PyOsConfig,
path: std::path::PathBuf,
max_state_diff_size: usize,
) -> Self {
Self::create_for_testing(concurrency_config, general_config, path, max_state_diff_size)
Self::create_for_testing(concurrency_config, os_config, path, max_state_diff_size)
}
}

#[derive(Default, FromPyObject)]
pub struct PyGeneralConfig {
pub starknet_os_config: PyOsConfig,
pub invoke_tx_max_n_steps: u32,
pub validate_max_n_steps: u32,
}

#[derive(Clone, FromPyObject)]
pub struct PyOsConfig {
#[pyo3(from_py_with = "int_to_chain_id")]
Expand Down
4 changes: 2 additions & 2 deletions crates/native_blockifier/src/py_block_executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use starknet_api::core::ClassHash;
use starknet_api::{class_hash, felt};
use starknet_types_core::felt::Felt;

use crate::py_block_executor::{PyBlockExecutor, PyGeneralConfig};
use crate::py_block_executor::{PyBlockExecutor, PyOsConfig};
use crate::py_objects::PyConcurrencyConfig;
use crate::py_state_diff::{PyBlockInfo, PyStateDiff};
use crate::py_utils::PyFelt;
Expand All @@ -26,7 +26,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(),
PyGeneralConfig::default(),
PyOsConfig::default(),
temp_storage_path,
4000,
);
Expand Down
8 changes: 4 additions & 4 deletions crates/native_blockifier/src/py_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use starknet_api::transaction::TransactionHash;
use starknet_types_core::felt::Felt;

use crate::errors::NativeBlockifierResult;
use crate::py_block_executor::PyGeneralConfig;
use crate::py_block_executor::PyOsConfig;
use crate::py_objects::PyVersionedConstantsOverrides;
use crate::py_state_diff::PyBlockInfo;
use crate::py_transaction::{py_account_tx, PyClassInfo, PY_TX_PARSING_ERR};
Expand All @@ -28,9 +28,9 @@ pub struct PyValidator {
#[pymethods]
impl PyValidator {
#[new]
#[pyo3(signature = (general_config, state_reader_proxy, next_block_info, max_nonce_for_validation_skip, py_versioned_constants_overrides))]
#[pyo3(signature = (os_config, state_reader_proxy, next_block_info, max_nonce_for_validation_skip, py_versioned_constants_overrides))]
pub fn create(
general_config: PyGeneralConfig,
os_config: PyOsConfig,
state_reader_proxy: &PyAny,
next_block_info: PyBlockInfo,
max_nonce_for_validation_skip: PyFelt,
Expand All @@ -45,7 +45,7 @@ impl PyValidator {
VersionedConstants::get_versioned_constants(py_versioned_constants_overrides.into());
let block_context = BlockContext::new(
next_block_info.try_into().expect("Failed to convert block info."),
general_config.starknet_os_config.into_chain_info(),
os_config.into_chain_info(),
versioned_constants,
BouncerConfig::max(),
);
Expand Down

0 comments on commit 3c2a46d

Please sign in to comment.