From 606a6e0c51d8255389720b7164d428a6d91961a1 Mon Sep 17 00:00:00 2001 From: Yair Bakalchuk Date: Mon, 11 Nov 2024 15:50:00 +0200 Subject: [PATCH] chore(gateway,batcher): use VersionedConstantsOverrides in both gw and batcher --- config/mempool/default_config.json | 16 ++++---- crates/batcher/src/block_builder.rs | 17 +++------ crates/blockifier/src/versioned_constants.rs | 18 --------- crates/gateway/src/config.rs | 38 +++++++------------ .../src/stateful_transaction_validator.rs | 5 +-- 5 files changed, 30 insertions(+), 64 deletions(-) diff --git a/config/mempool/default_config.json b/config/mempool/default_config.json index 00020152ed..6c4a8937e8 100644 --- a/config/mempool/default_config.json +++ b/config/mempool/default_config.json @@ -119,11 +119,6 @@ "privacy": "Public", "value": true }, - "batcher_config.block_builder_config.versioned_constants_overrides.#is_none": { - "description": "Flag for an optional field.", - "privacy": "TemporaryValue", - "value": true - }, "batcher_config.block_builder_config.versioned_constants_overrides.invoke_tx_max_n_steps": { "description": "Maximum number of steps the invoke function is allowed to run.", "privacy": "Public", @@ -704,13 +699,18 @@ "privacy": "Public", "value": "0x1" }, - "gateway_config.stateful_tx_validator_config.max_recursion_depth": { + "gateway_config.stateful_tx_validator_config.versioned_constants_overrides.invoke_tx_max_n_steps": { + "description": "Maximum number of steps the invoke function is allowed to run.", + "privacy": "Public", + "value": 10000000 + }, + "gateway_config.stateful_tx_validator_config.versioned_constants_overrides.max_recursion_depth": { "description": "Maximum recursion depth for nested calls during blockifier validation.", "privacy": "Public", "value": 50 }, - "gateway_config.stateful_tx_validator_config.validate_max_n_steps": { - "description": "Maximum number of steps the validation function is allowed to take.", + "gateway_config.stateful_tx_validator_config.versioned_constants_overrides.validate_max_n_steps": { + "description": "Maximum number of steps the validation function is allowed to run.", "privacy": "Public", "value": 1000000 }, diff --git a/crates/batcher/src/block_builder.rs b/crates/batcher/src/block_builder.rs index dc0590e21e..8ea0aeea34 100644 --- a/crates/batcher/src/block_builder.rs +++ b/crates/batcher/src/block_builder.rs @@ -21,12 +21,7 @@ use blockifier::versioned_constants::{VersionedConstants, VersionedConstantsOver use indexmap::IndexMap; #[cfg(test)] use mockall::automock; -use papyrus_config::dumping::{ - append_sub_config_name, - ser_optional_sub_config, - ser_param, - SerializeConfig, -}; +use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig}; use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; use papyrus_state_reader::papyrus_state::PapyrusReader; use papyrus_storage::StorageReader; @@ -212,7 +207,7 @@ pub struct BlockBuilderConfig { pub sequencer_address: ContractAddress, pub use_kzg_da: bool, pub tx_chunk_size: usize, - pub versioned_constants_overrides: Option, + pub versioned_constants_overrides: VersionedConstantsOverrides, } impl Default for BlockBuilderConfig { @@ -225,7 +220,7 @@ impl Default for BlockBuilderConfig { sequencer_address: ContractAddress::default(), use_kzg_da: true, tx_chunk_size: 100, - versioned_constants_overrides: None, + versioned_constants_overrides: VersionedConstantsOverrides::default(), } } } @@ -253,8 +248,8 @@ impl SerializeConfig for BlockBuilderConfig { "The size of the transaction chunk.", ParamPrivacyInput::Public, )])); - dump.append(&mut ser_optional_sub_config( - &self.versioned_constants_overrides, + dump.append(&mut append_sub_config_name( + self.versioned_constants_overrides.dump(), "versioned_constants_overrides", )); dump @@ -285,7 +280,7 @@ impl BlockBuilderFactory { }, use_kzg_da: block_builder_config.use_kzg_da, }; - let versioned_constants = VersionedConstants::latest_with_overrides( + let versioned_constants = VersionedConstants::get_versioned_constants( block_builder_config.versioned_constants_overrides, ); let block_context = BlockContext::new( diff --git a/crates/blockifier/src/versioned_constants.rs b/crates/blockifier/src/versioned_constants.rs index ae3ffe5c1d..d50c16275d 100644 --- a/crates/blockifier/src/versioned_constants.rs +++ b/crates/blockifier/src/versioned_constants.rs @@ -301,14 +301,6 @@ impl VersionedConstants { Self { vm_resource_fee_cost, archival_data_gas_costs, ..latest } } - // TODO(Arni): Share code with latest_with_overrides. - pub fn latest_constants_with_overrides( - validate_max_n_steps: u32, - max_recursion_depth: usize, - ) -> Self { - Self { validate_max_n_steps, max_recursion_depth, ..Self::latest_constants().clone() } - } - // TODO(Arni): Consider replacing each call to this function with `latest_with_overrides`, and // squashing the functions together. /// Returns the latest versioned constants, applying the given overrides. @@ -328,16 +320,6 @@ impl VersionedConstants { } } - /// Returns the latest versioned constants, applying the given overrides if provided. - pub fn latest_with_overrides( - versioned_constants_overrides: Option, - ) -> Self { - match versioned_constants_overrides { - Some(overrides) => Self::get_versioned_constants(overrides), - None => Self::latest_constants().clone(), - } - } - pub fn get_archival_data_gas_costs( &self, mode: &GasVectorComputationMode, diff --git a/crates/gateway/src/config.rs b/crates/gateway/src/config.rs index ae5d025bda..db2dd09b34 100644 --- a/crates/gateway/src/config.rs +++ b/crates/gateway/src/config.rs @@ -1,6 +1,7 @@ use std::collections::BTreeMap; use blockifier::context::ChainInfo; +use blockifier::versioned_constants::VersionedConstantsOverrides; use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig}; use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; use serde::{Deserialize, Serialize}; @@ -139,41 +140,30 @@ impl SerializeConfig for RpcStateReaderConfig { #[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)] pub struct StatefulTransactionValidatorConfig { pub max_nonce_for_validation_skip: Nonce, - pub validate_max_n_steps: u32, - pub max_recursion_depth: usize, + pub versioned_constants_overrides: VersionedConstantsOverrides, } impl Default for StatefulTransactionValidatorConfig { fn default() -> Self { StatefulTransactionValidatorConfig { max_nonce_for_validation_skip: Nonce(Felt::ONE), - validate_max_n_steps: 1_000_000, - max_recursion_depth: 50, + versioned_constants_overrides: VersionedConstantsOverrides::default(), } } } impl SerializeConfig for StatefulTransactionValidatorConfig { fn dump(&self) -> BTreeMap { - BTreeMap::from_iter([ - ser_param( - "max_nonce_for_validation_skip", - &self.max_nonce_for_validation_skip, - "Maximum nonce for which the validation is skipped.", - ParamPrivacyInput::Public, - ), - ser_param( - "validate_max_n_steps", - &self.validate_max_n_steps, - "Maximum number of steps the validation function is allowed to take.", - ParamPrivacyInput::Public, - ), - ser_param( - "max_recursion_depth", - &self.max_recursion_depth, - "Maximum recursion depth for nested calls during blockifier validation.", - ParamPrivacyInput::Public, - ), - ]) + let mut dump = BTreeMap::from_iter([ser_param( + "max_nonce_for_validation_skip", + &self.max_nonce_for_validation_skip, + "Maximum nonce for which the validation is skipped.", + ParamPrivacyInput::Public, + )]); + dump.append(&mut append_sub_config_name( + self.versioned_constants_overrides.dump(), + "versioned_constants_overrides", + )); + dump } } diff --git a/crates/gateway/src/stateful_transaction_validator.rs b/crates/gateway/src/stateful_transaction_validator.rs index 6384ab039d..1060d4b44f 100644 --- a/crates/gateway/src/stateful_transaction_validator.rs +++ b/crates/gateway/src/stateful_transaction_validator.rs @@ -95,9 +95,8 @@ impl StatefulTransactionValidator { let latest_block_info = get_latest_block_info(state_reader_factory)?; let state_reader = state_reader_factory.get_state_reader(latest_block_info.block_number); let state = CachedState::new(state_reader); - let versioned_constants = VersionedConstants::latest_constants_with_overrides( - self.config.validate_max_n_steps, - self.config.max_recursion_depth, + let versioned_constants = VersionedConstants::get_versioned_constants( + self.config.versioned_constants_overrides.clone(), ); let mut block_info = latest_block_info; block_info.block_number = block_info.block_number.unchecked_next();