Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main-v0.13.2 into main #628

Merged
4 changes: 2 additions & 2 deletions .github/actions/install_rust/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Installs rust toolchain. In order to set/fix the version, edit DEFAULT_TOOLCHAIN env variable.
# Installs rust toolchain with the version defined in .github/actions/install_rust/rust_version.txt.
inputs:
components:
description: "An optional parameter that will be sent to dtolnay/rust-toolchain."
Expand All @@ -9,7 +9,7 @@ runs:
using: "composite"
steps:
- name: Define toolchain
run: echo "DEFAULT_TOOLCHAIN=stable" >> $GITHUB_ENV
run: echo "DEFAULT_TOOLCHAIN=$(cat .github/actions/install_rust/rust_version.txt)" >> $GITHUB_ENV
shell: bash
- name: install rust toolchain with given components
if: "${{ inputs.components != '' }}"
Expand Down
1 change: 1 addition & 0 deletions .github/actions/install_rust/rust_version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stable
2 changes: 1 addition & 1 deletion .github/workflows/blockifier_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ on:
# On PR events, cancel existing CI runs on this same PR for this workflow.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event.name == 'pull_request' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
featureless-build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/blockifier_compiled_cairo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ on:
# On PR events, cancel existing CI runs on this same PR for this workflow.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event.name == 'pull_request' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
verify_cairo_file_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/committer_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ on:
# On PR events, cancel existing CI runs on this same PR for this workflow.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event.name == 'pull_request' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
run-regression-tests:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ on:
# On PR events, cancel existing CI runs on this same PR for this workflow.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event.name == 'pull_request' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
commitlint:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/merge_paths_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- v[0-9].**
paths:
- '.github/workflows/merge_paths_ci.yml'
- 'scripts/merge_branches.json'
- 'scripts/merge_branches.py'
- 'scripts/merge_paths.json'
- 'scripts/merge_paths_test.py'
- 'scripts/merge_status.py'
Expand All @@ -23,15 +23,15 @@ on:
- edited
paths:
- '.github/workflows/merge_paths_ci.yml'
- 'scripts/merge_branches.json'
- 'scripts/merge_branches.py'
- 'scripts/merge_paths.json'
- 'scripts/merge_paths_test.py'
- 'scripts/merge_status.py'

# On PR events, cancel existing CI runs on this same PR for this workflow.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event.name == 'pull_request' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
merge-paths-test:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/papyrus_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ on:
# On PR events, cancel existing CI runs on this same PR for this workflow.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event.name == 'pull_request' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
PROTOC_VERSION: v25.1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/papyrus_docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
# On PR events, cancel existing CI runs on this same PR for this workflow.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event.name == 'pull_request' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
REGISTRY: ghcr.io
Expand Down
29 changes: 9 additions & 20 deletions crates/blockifier/src/versioned_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,32 +232,21 @@ impl VersionedConstants {
Self { validate_max_n_steps, max_recursion_depth, ..Self::latest_constants().clone() }
}

// TODO(Amos, 1/8/2024): Remove the explicit `validate_max_n_steps` & `max_recursion_depth`,
// they should be part of the general override.
/// `versioned_constants_base_overrides` are used if they are provided, otherwise the latest
/// versioned constants are used. `validate_max_n_steps` & `max_recursion_depth` override both.
/// Returns the latest versioned constants after applying the given overrides.
pub fn get_versioned_constants(
versioned_constants_overrides: VersionedConstantsOverrides,
) -> Self {
let VersionedConstantsOverrides {
validate_max_n_steps,
max_recursion_depth,
versioned_constants_base_overrides,
invoke_tx_max_n_steps,
} = versioned_constants_overrides;
let base_overrides = match versioned_constants_base_overrides {
Some(versioned_constants_base_overrides) => {
log::debug!(
"Using provided `versioned_constants_base_overrides` (with additional \
overrides)."
);
versioned_constants_base_overrides
}
None => {
log::debug!("Using latest versioned constants (with additional overrides).");
Self::latest_constants().clone()
}
};
Self { validate_max_n_steps, max_recursion_depth, ..base_overrides }
Self {
validate_max_n_steps,
max_recursion_depth,
invoke_tx_max_n_steps,
..Self::latest_constants().clone()
}
}
}

Expand Down Expand Up @@ -756,5 +745,5 @@ pub struct ResourcesByVersion {
pub struct VersionedConstantsOverrides {
pub validate_max_n_steps: u32,
pub max_recursion_depth: usize,
pub versioned_constants_base_overrides: Option<VersionedConstants>,
pub invoke_tx_max_n_steps: u32,
}
27 changes: 14 additions & 13 deletions crates/blockifier/src/versioned_constants_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,25 @@ fn get_json_value_without_defaults() -> serde_json::Value {
json_value_without_defaults
}

/// Assert `versioned_constants_base_overrides` are used when provided.
/// Assert versioned constants overrides are used when provided.
#[test]
fn test_versioned_constants_base_overrides() {
// Create a versioned constants copy with a modified value for `invoke_tx_max_n_steps`.
let mut versioned_constants_base_overrides = VERSIONED_CONSTANTS_LATEST.clone();
versioned_constants_base_overrides.invoke_tx_max_n_steps += 1;
fn test_versioned_constants_overrides() {
let versioned_constants = VERSIONED_CONSTANTS_LATEST.clone();
let updated_invoke_tx_max_n_steps = versioned_constants.invoke_tx_max_n_steps + 1;
let updated_validate_max_n_steps = versioned_constants.validate_max_n_steps + 1;
let updated_max_recursion_depth = versioned_constants.max_recursion_depth + 1;

// Create a versioned constants copy with overriden values.
let result = VersionedConstants::get_versioned_constants(VersionedConstantsOverrides {
validate_max_n_steps: versioned_constants_base_overrides.validate_max_n_steps,
max_recursion_depth: versioned_constants_base_overrides.max_recursion_depth,
versioned_constants_base_overrides: Some(versioned_constants_base_overrides.clone()),
validate_max_n_steps: updated_validate_max_n_steps,
max_recursion_depth: updated_max_recursion_depth,
invoke_tx_max_n_steps: updated_invoke_tx_max_n_steps,
});

// Assert the new value is used.
assert_eq!(
result.invoke_tx_max_n_steps,
versioned_constants_base_overrides.invoke_tx_max_n_steps
);
// Assert the new values are used.
assert_eq!(result.invoke_tx_max_n_steps, updated_invoke_tx_max_n_steps);
assert_eq!(result.validate_max_n_steps, updated_validate_max_n_steps);
assert_eq!(result.max_recursion_depth, updated_max_recursion_depth);
}

#[test]
Expand Down
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
35 changes: 7 additions & 28 deletions crates/native_blockifier/src/py_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use std::collections::HashMap;
use blockifier::abi::constants;
use blockifier::blockifier::config::ConcurrencyConfig;
use blockifier::bouncer::{BouncerConfig, BouncerWeights, BuiltinCount, HashMapWrapper};
use blockifier::versioned_constants::{VersionedConstants, VersionedConstantsOverrides};
use blockifier::versioned_constants::VersionedConstantsOverrides;
use cairo_vm::types::builtin_name::BuiltinName;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;

use crate::errors::{
Expand Down Expand Up @@ -50,30 +49,19 @@ impl From<ExecutionResources> for PyExecutionResources {
pub struct PyVersionedConstantsOverrides {
pub validate_max_n_steps: u32,
pub max_recursion_depth: usize,
pub versioned_constants_base_overrides: Option<String>,
pub invoke_tx_max_n_steps: u32,
}

#[pymethods]
impl PyVersionedConstantsOverrides {
#[new]
#[pyo3(signature = (validate_max_n_steps, max_recursion_depth, versioned_constants_base_overrides))]
#[pyo3(signature = (validate_max_n_steps, max_recursion_depth, invoke_tx_max_n_steps))]
pub fn create(
validate_max_n_steps: u32,
max_recursion_depth: usize,
versioned_constants_base_overrides: Option<String>,
invoke_tx_max_n_steps: u32,
) -> Self {
Self { validate_max_n_steps, max_recursion_depth, versioned_constants_base_overrides }
}

#[staticmethod]
pub fn assert_versioned_consts_load_successfully(
versioned_constants_str: &str,
) -> PyResult<()> {
if serde_json::from_str::<VersionedConstants>(versioned_constants_str).is_ok() {
Ok(())
} else {
Err(PyValueError::new_err("Failed to parse `versioned_constants_str`."))
}
Self { validate_max_n_steps, max_recursion_depth, invoke_tx_max_n_steps }
}
}

Expand All @@ -82,18 +70,9 @@ impl From<PyVersionedConstantsOverrides> for VersionedConstantsOverrides {
let PyVersionedConstantsOverrides {
validate_max_n_steps,
max_recursion_depth,
versioned_constants_base_overrides,
invoke_tx_max_n_steps,
} = py_versioned_constants_overrides;
let base_overrides =
versioned_constants_base_overrides.map(|versioned_constants_base_overrides| {
serde_json::from_str(&versioned_constants_base_overrides)
.expect("Versioned constants JSON file is malformed.")
});
Self {
validate_max_n_steps,
max_recursion_depth,
versioned_constants_base_overrides: base_overrides,
}
Self { validate_max_n_steps, max_recursion_depth, invoke_tx_max_n_steps }
}
}

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
Loading
Loading