From d83a3aa39519ff9896e70172a6cce835115a6829 Mon Sep 17 00:00:00 2001 From: amos rothberg Date: Wed, 21 Aug 2024 16:09:42 +0300 Subject: [PATCH] chore(blockifier, native_blockifier): update versioned constants --- crates/blockifier/src/versioned_constants.rs | 36 +++++++++---------- .../src/versioned_constants_test.rs | 21 +++++------ crates/native_blockifier/src/py_objects.rs | 35 ++++-------------- 3 files changed, 32 insertions(+), 60 deletions(-) diff --git a/crates/blockifier/src/versioned_constants.rs b/crates/blockifier/src/versioned_constants.rs index a975ab0e98c..8287fd461c6 100644 --- a/crates/blockifier/src/versioned_constants.rs +++ b/crates/blockifier/src/versioned_constants.rs @@ -224,32 +224,28 @@ 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 } + match invoke_tx_max_n_steps { + Some(invoke_tx_max_n_steps) => Self { + validate_max_n_steps, + max_recursion_depth, + invoke_tx_max_n_steps, + ..Self::latest_constants().clone() + }, + None => Self { + validate_max_n_steps, + max_recursion_depth, + ..Self::latest_constants().clone() + }, + } } } @@ -746,5 +742,5 @@ pub struct ResourcesByVersion { pub struct VersionedConstantsOverrides { pub validate_max_n_steps: u32, pub max_recursion_depth: usize, - pub versioned_constants_base_overrides: Option, + pub invoke_tx_max_n_steps: Option, } diff --git a/crates/blockifier/src/versioned_constants_test.rs b/crates/blockifier/src/versioned_constants_test.rs index ff6dd2d4d25..8937695520e 100644 --- a/crates/blockifier/src/versioned_constants_test.rs +++ b/crates/blockifier/src/versioned_constants_test.rs @@ -92,24 +92,21 @@ 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; + // Create a versioned constants copy with a modified value for `invoke_tx_max_n_steps`. 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: versioned_constants.validate_max_n_steps, + max_recursion_depth: versioned_constants.max_recursion_depth, + invoke_tx_max_n_steps: Some(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_eq!(result.invoke_tx_max_n_steps, updated_invoke_tx_max_n_steps); } #[test] diff --git a/crates/native_blockifier/src/py_objects.rs b/crates/native_blockifier/src/py_objects.rs index 4cb67160158..056cdf29f9c 100644 --- a/crates/native_blockifier/src/py_objects.rs +++ b/crates/native_blockifier/src/py_objects.rs @@ -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::{ @@ -50,30 +49,19 @@ impl From for PyExecutionResources { pub struct PyVersionedConstantsOverrides { pub validate_max_n_steps: u32, pub max_recursion_depth: usize, - pub versioned_constants_base_overrides: Option, + pub invoke_tx_max_n_steps: Option, } #[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, + invoke_tx_max_n_steps: Option, ) -> 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::(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 } } } @@ -82,18 +70,9 @@ impl From 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 } } }