From 4c4753846f1cffc2937fac72a092fd89672caf07 Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Mon, 11 Nov 2024 20:51:38 +0200 Subject: [PATCH] chore: add overrides to statful tx validator config --- config/mempool/default_config.json | 11 +++-- crates/blockifier/src/versioned_constants.rs | 2 +- crates/gateway/src/config.rs | 46 +++++++++---------- .../src/stateful_transaction_validator.rs | 10 +--- 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/config/mempool/default_config.json b/config/mempool/default_config.json index 00020152ed..6bfb29c790 100644 --- a/config/mempool/default_config.json +++ b/config/mempool/default_config.json @@ -704,13 +704,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/blockifier/src/versioned_constants.rs b/crates/blockifier/src/versioned_constants.rs index 5fb29cd573..1dcbcb1de8 100644 --- a/crates/blockifier/src/versioned_constants.rs +++ b/crates/blockifier/src/versioned_constants.rs @@ -831,7 +831,7 @@ pub struct ResourcesByVersion { pub deprecated_resources: ResourcesParams, } -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)] pub struct VersionedConstantsOverrides { pub validate_max_n_steps: u32, pub max_recursion_depth: usize, diff --git a/crates/gateway/src/config.rs b/crates/gateway/src/config.rs index ae5d025bda..b2580a457c 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,40 @@ 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 { + validate_max_n_steps: 1_000_000, + max_recursion_depth: 50, + ..Default::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 members = 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, + )]); + + [ + members, + append_sub_config_name( + self.versioned_constants_overrides.dump(), + "versioned_constants_overrides", ), - ]) + ] + .into_iter() + .flatten() + .collect() } } diff --git a/crates/gateway/src/stateful_transaction_validator.rs b/crates/gateway/src/stateful_transaction_validator.rs index f882b92b80..de2fd1cf5e 100644 --- a/crates/gateway/src/stateful_transaction_validator.rs +++ b/crates/gateway/src/stateful_transaction_validator.rs @@ -7,7 +7,7 @@ use blockifier::bouncer::BouncerConfig; use blockifier::context::{BlockContext, ChainInfo}; use blockifier::state::cached_state::CachedState; use blockifier::transaction::account_transaction::AccountTransaction; -use blockifier::versioned_constants::{VersionedConstants, VersionedConstantsOverrides}; +use blockifier::versioned_constants::VersionedConstants; #[cfg(test)] use mockall::automock; use starknet_api::core::{ContractAddress, Nonce}; @@ -95,14 +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); - // TODO(Arni): Set versioned constants overrieds as part of the validate config. - let versioned_constants_overrides = VersionedConstantsOverrides { - validate_max_n_steps: self.config.validate_max_n_steps, - max_recursion_depth: self.config.max_recursion_depth, - ..Default::default() - }; let versioned_constants = - VersionedConstants::get_versioned_constants(versioned_constants_overrides); + VersionedConstants::get_versioned_constants(self.config.versioned_constants_overrides); let mut block_info = latest_block_info; block_info.block_number = block_info.block_number.unchecked_next(); // TODO(yael 21/4/24): create the block context using pre_process_block once we will be