diff --git a/config/mempool/default_config.json b/config/mempool/default_config.json index 9b05cc32c2..a382bcd06a 100644 --- a/config/mempool/default_config.json +++ b/config/mempool/default_config.json @@ -119,6 +119,11 @@ "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", diff --git a/crates/batcher/src/block_builder.rs b/crates/batcher/src/block_builder.rs index fe827b6e2f..e7463d8b7d 100644 --- a/crates/batcher/src/block_builder.rs +++ b/crates/batcher/src/block_builder.rs @@ -21,7 +21,12 @@ use blockifier::versioned_constants::{VersionedConstants, VersionedConstantsOver use indexmap::IndexMap; #[cfg(test)] use mockall::automock; -use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig}; +use papyrus_config::dumping::{ + append_sub_config_name, + ser_optional_sub_config, + ser_param, + SerializeConfig, +}; use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; use papyrus_storage::StorageReader; use serde::{Deserialize, Serialize}; @@ -90,52 +95,6 @@ impl BlockBuilder { } } -impl Default for BlockBuilderConfig { - fn default() -> Self { - Self { - // TODO: update the default values once the actual values are known. - chain_info: ChainInfo::default(), - execute_config: TransactionExecutorConfig::default(), - bouncer_config: BouncerConfig::default(), - sequencer_address: ContractAddress::default(), - use_kzg_da: true, - tx_chunk_size: 100, - versioned_constants_overrides: VersionedConstantsOverrides::default(), - } - } -} - -impl SerializeConfig for BlockBuilderConfig { - fn dump(&self) -> BTreeMap { - let mut dump = append_sub_config_name(self.chain_info.dump(), "chain_info"); - dump.append(&mut append_sub_config_name(self.execute_config.dump(), "execute_config")); - dump.append(&mut append_sub_config_name(self.bouncer_config.dump(), "bouncer_config")); - dump.append(&mut BTreeMap::from([ser_param( - "sequencer_address", - &self.sequencer_address, - "The address of the sequencer.", - ParamPrivacyInput::Public, - )])); - dump.append(&mut BTreeMap::from([ser_param( - "use_kzg_da", - &self.use_kzg_da, - "Indicates whether the kzg mechanism is used for data availability.", - ParamPrivacyInput::Public, - )])); - dump.append(&mut BTreeMap::from([ser_param( - "tx_chunk_size", - &self.tx_chunk_size, - "The size of the transaction chunk.", - ParamPrivacyInput::Public, - )])); - dump.append(&mut append_sub_config_name( - self.versioned_constants_overrides.dump(), - "versioned_constants_overrides", - )); - dump - } -} - #[async_trait] impl BlockBuilderTrait for BlockBuilder { async fn build_block( @@ -232,8 +191,53 @@ pub struct BlockBuilderConfig { pub sequencer_address: ContractAddress, pub use_kzg_da: bool, pub tx_chunk_size: usize, - // TODO(Ayelet): Make this field optional. - pub versioned_constants_overrides: VersionedConstantsOverrides, + pub versioned_constants_overrides: Option, +} + +impl Default for BlockBuilderConfig { + fn default() -> Self { + Self { + // TODO: update the default values once the actual values are known. + chain_info: ChainInfo::default(), + execute_config: TransactionExecutorConfig::default(), + bouncer_config: BouncerConfig::default(), + sequencer_address: ContractAddress::default(), + use_kzg_da: true, + tx_chunk_size: 100, + versioned_constants_overrides: None, + } + } +} + +impl SerializeConfig for BlockBuilderConfig { + fn dump(&self) -> BTreeMap { + let mut dump = append_sub_config_name(self.chain_info.dump(), "chain_info"); + dump.append(&mut append_sub_config_name(self.execute_config.dump(), "execute_config")); + dump.append(&mut append_sub_config_name(self.bouncer_config.dump(), "bouncer_config")); + dump.append(&mut BTreeMap::from([ser_param( + "sequencer_address", + &self.sequencer_address, + "The address of the sequencer.", + ParamPrivacyInput::Public, + )])); + dump.append(&mut BTreeMap::from([ser_param( + "use_kzg_da", + &self.use_kzg_da, + "Indicates whether the kzg mechanism is used for data availability.", + ParamPrivacyInput::Public, + )])); + dump.append(&mut BTreeMap::from([ser_param( + "tx_chunk_size", + &self.tx_chunk_size, + "The size of the transaction chunk.", + ParamPrivacyInput::Public, + )])); + dump.append(&mut ser_optional_sub_config( + &self.versioned_constants_overrides, + "versioned_constants_overrides", + )); + dump + } } pub struct BlockBuilderFactory { @@ -260,12 +264,13 @@ impl BlockBuilderFactory { }, use_kzg_da: block_builder_config.use_kzg_da, }; + let versioned_constants = VersionedConstants::latest_with_overrides( + block_builder_config.versioned_constants_overrides, + ); let block_context = BlockContext::new( next_block_info, block_builder_config.chain_info, - VersionedConstants::get_versioned_constants( - block_builder_config.versioned_constants_overrides, - ), + versioned_constants, block_builder_config.bouncer_config, ); diff --git a/crates/blockifier/src/versioned_constants.rs b/crates/blockifier/src/versioned_constants.rs index 2036369235..a50a696f78 100644 --- a/crates/blockifier/src/versioned_constants.rs +++ b/crates/blockifier/src/versioned_constants.rs @@ -301,6 +301,7 @@ 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, @@ -308,7 +309,9 @@ impl VersionedConstants { Self { validate_max_n_steps, max_recursion_depth, ..Self::latest_constants().clone() } } - /// Returns the latest versioned constants after applying the given overrides. + // 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. pub fn get_versioned_constants( versioned_constants_overrides: VersionedConstantsOverrides, ) -> Self { @@ -325,6 +328,16 @@ 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,