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 #623

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 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,7 +23,7 @@ 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'
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
20 changes: 20 additions & 0 deletions scripts/merge_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,31 @@ def dstdiff(source_branch: str, destination_branch: Optional[str], files: List[s
)


def verify_gh_client_status():
try:
run_command("gh --version")
except subprocess.CalledProcessError:
print(
"GitHub CLI not found. Please install it from "
"https://github.com/cli/cli/blob/trunk/docs/install_linux.md#installing-gh-on-linux-and-bsd"
)
exit(1)
try:
run_command("gh auth status")
except subprocess.CalledProcessError:
print(
"GitHub CLI not authenticated. Please authenticate using `gh auth login` "
"and follow the instructions."
)
exit(1)


def merge_branches(src_branch: str, dst_branch: Optional[str]):
"""
Merge source branch into destination branch.
If no destination branch is passed, the destination branch is taken from state on repo.
"""
verify_gh_client_status()
user = os.environ["USER"]
dst_branch = get_dst_branch(src_branch=src_branch, dst_branch_override=dst_branch)

Expand Down
Loading