Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
feat(native_blockifier): allow overriding max invoke steps (#2110)
Browse files Browse the repository at this point in the history
* feat(native_blockifier): allow overriding max invoke steps

Signed-off-by: Dori Medini <dori@starkware.co>

* fix: clippy errors

Signed-off-by: Dori Medini <dori@starkware.co>

---------

Signed-off-by: Dori Medini <dori@starkware.co>
  • Loading branch information
dorimedini-starkware authored Aug 12, 2024
1 parent 4fd7164 commit 3303b69
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ test-case = "2.2.2"
thiserror = "1.0.37"

[workspace.lints.rust]
warnings = "deny"
future-incompatible = "deny"
nonstandard-style = "deny"
rust-2018-idioms = "deny"
unused = "deny"
unused = { level = "deny", priority = -1 }
warnings = "deny"
2 changes: 1 addition & 1 deletion crates/blockifier/src/fee/actual_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<'a> ActualCostBuilder<'a> {
let bouncer_resources = actual_resources.clone();

// Add reverted steps to actual_resources' n_steps for correct fee charge.
*actual_resources.0.get_mut(&abi_constants::N_STEPS_RESOURCE.to_string()).unwrap() +=
*actual_resources.0.get_mut(abi_constants::N_STEPS_RESOURCE).unwrap() +=
self.n_reverted_steps;

let tx_info = &self.tx_context.tx_info;
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/state/cached_state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ fn global_contract_cache_is_used() {
let mut state = CachedState::new(DictStateReader::default(), global_cache.clone());

// Assert local cache is initialized empty even if global cache is not empty.
assert!(state.class_hash_to_class.get(&class_hash).is_none());
assert!(!state.class_hash_to_class.contains_key(&class_hash));

// Check state uses the global cache.
assert_eq!(state.get_compiled_contract_class(class_hash).unwrap(), contract_class);
Expand Down
24 changes: 7 additions & 17 deletions crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ use crate::transaction_executor::TransactionExecutor;
#[path = "py_block_executor_test.rs"]
mod py_block_executor_test;

const MAX_STEPS_PER_TX: u32 = 4_000_000;
const MAX_VALIDATE_STEPS_PER_TX: u32 = 1_000_000;

/// Stripped down `TransactionExecutionInfo` for Python serialization, containing only the required
/// fields.
#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -86,19 +83,23 @@ pub struct PyBlockExecutor {
#[pymethods]
impl PyBlockExecutor {
#[new]
#[pyo3(signature = (general_config, validate_max_n_steps, max_recursion_depth, global_contract_cache_size, target_storage_config))]
#[pyo3(signature = (general_config, validate_max_n_steps, invoke_max_n_steps, max_recursion_depth, global_contract_cache_size, target_storage_config))]
pub fn create(
general_config: PyGeneralConfig,
validate_max_n_steps: u32,
invoke_max_n_steps: u32,
max_recursion_depth: usize,
global_contract_cache_size: usize,
target_storage_config: StorageConfig,
) -> Self {
log::debug!("Initializing Block Executor...");
let storage =
PapyrusStorage::new(target_storage_config).expect("Failed to initialize storage");
let versioned_constants =
versioned_constants_with_overrides(validate_max_n_steps, max_recursion_depth);
let versioned_constants = versioned_constants_with_overrides(
validate_max_n_steps,
invoke_max_n_steps,
max_recursion_depth,
);
log::debug!("Initialized Block Executor.");

Self {
Expand Down Expand Up @@ -420,17 +421,6 @@ fn pre_process_block(
let old_block_number_and_hash = old_block_number_and_hash
.map(|(block_number, block_hash)| BlockNumberHashPair::new(block_number, block_hash.0));

// Input validation.
if versioned_constants.invoke_tx_max_n_steps > MAX_STEPS_PER_TX {
Err(NativeBlockifierInputError::MaxStepsPerTxOutOfRange(
versioned_constants.invoke_tx_max_n_steps,
))?;
} else if versioned_constants.validate_max_n_steps > MAX_VALIDATE_STEPS_PER_TX {
Err(NativeBlockifierInputError::MaxValidateStepsPerTxOutOfRange(
versioned_constants.validate_max_n_steps,
))?;
}

let (block_info, chain_info) = into_block_context_args(general_config, block_info)?;
let block_context = pre_process_block_blockifier(
state,
Expand Down
2 changes: 2 additions & 0 deletions crates/native_blockifier/src/py_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ where

pub fn versioned_constants_with_overrides(
validate_max_n_steps: u32,
invoke_max_n_steps: u32,
max_recursion_depth: usize,
) -> VersionedConstants {
let mut versioned_constants = VersionedConstants::latest_constants().clone();
versioned_constants.max_recursion_depth = max_recursion_depth;
versioned_constants.validate_max_n_steps = validate_max_n_steps;
versioned_constants.invoke_tx_max_n_steps = invoke_max_n_steps;
versioned_constants
}
11 changes: 8 additions & 3 deletions crates/native_blockifier/src/py_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,24 @@ pub struct PyValidator {

#[pymethods]
impl PyValidator {
#[allow(clippy::too_many_arguments)]
#[new]
#[pyo3(signature = (general_config, state_reader_proxy, next_block_info, validate_max_n_steps, max_recursion_depth, global_contract_cache_size, max_nonce_for_validation_skip))]
#[pyo3(signature = (general_config, state_reader_proxy, next_block_info, validate_max_n_steps, invoke_max_n_steps, max_recursion_depth, global_contract_cache_size, max_nonce_for_validation_skip))]
pub fn create(
general_config: PyGeneralConfig,
state_reader_proxy: &PyAny,
next_block_info: PyBlockInfo,
validate_max_n_steps: u32,
invoke_max_n_steps: u32,
max_recursion_depth: usize,
global_contract_cache_size: usize,
max_nonce_for_validation_skip: PyFelt,
) -> NativeBlockifierResult<Self> {
let versioned_constants =
versioned_constants_with_overrides(validate_max_n_steps, max_recursion_depth);
let versioned_constants = versioned_constants_with_overrides(
validate_max_n_steps,
invoke_max_n_steps,
max_recursion_depth,
);
let global_contract_cache = GlobalContractCache::new(global_contract_cache_size);
let state_reader = PyStateReader::new(state_reader_proxy);
let state = CachedState::new(state_reader, global_contract_cache);
Expand Down

0 comments on commit 3303b69

Please sign in to comment.