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

chore(gateway,batcher): use VersionedConstantsOverrides in both gw and batcher #1946

Merged
merged 1 commit into from
Nov 12, 2024
Merged
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
16 changes: 8 additions & 8 deletions config/mempool/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
},
Expand Down
17 changes: 6 additions & 11 deletions crates/batcher/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<VersionedConstantsOverrides>,
pub versioned_constants_overrides: VersionedConstantsOverrides,
}

impl Default for BlockBuilderConfig {
Expand All @@ -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(),
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
18 changes: 0 additions & 18 deletions crates/blockifier/src/versioned_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<VersionedConstantsOverrides>,
) -> 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,
Expand Down
38 changes: 14 additions & 24 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,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<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 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
}
}
5 changes: 2 additions & 3 deletions crates/gateway/src/stateful_transaction_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading