Skip to content

Commit

Permalink
chore: add overrides to statful tx validator config
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Nov 11, 2024
1 parent b85499f commit ea49a1f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
11 changes: 8 additions & 3 deletions config/mempool/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/versioned_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
46 changes: 23 additions & 23 deletions crates/gateway/src/config.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<ParamPath, SerializedParam> {
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()
}
}
10 changes: 2 additions & 8 deletions crates/gateway/src/stateful_transaction_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ea49a1f

Please sign in to comment.