Skip to content

Commit

Permalink
refactor(batcher): make versioned_constants_overrides field optional …
Browse files Browse the repository at this point in the history
…in BlockBuilderConfig
  • Loading branch information
ayeletstarkware committed Oct 21, 2024
1 parent 6b8ae3a commit 8c27843
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
16 changes: 10 additions & 6 deletions crates/batcher/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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};
Expand Down Expand Up @@ -103,7 +108,7 @@ impl Default for BlockBuilderConfig {
sequencer_address: ContractAddress::default(),
use_kzg_da: true,
tx_chunk_size: 100,
versioned_constants_overrides: VersionedConstantsOverrides::default(),
versioned_constants_overrides: None,
}
}
}
Expand Down Expand Up @@ -131,8 +136,8 @@ impl SerializeConfig for BlockBuilderConfig {
"The size of the transaction chunk.",
ParamPrivacyInput::Public,
)]));
dump.append(&mut append_sub_config_name(
self.versioned_constants_overrides.dump(),
dump.append(&mut ser_optional_sub_config(
&self.versioned_constants_overrides,
"versioned_constants_overrides",
));
dump
Expand Down Expand Up @@ -235,8 +240,7 @@ 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<VersionedConstantsOverrides>,
}

pub struct BlockBuilderFactory {
Expand Down
40 changes: 17 additions & 23 deletions crates/blockifier/src/versioned_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,22 @@ impl VersionedConstants {

/// Returns the latest versioned constants after applying the given overrides.
pub fn get_versioned_constants(
versioned_constants_overrides: VersionedConstantsOverrides,
versioned_constants_overrides: Option<VersionedConstantsOverrides>,
) -> Self {
let VersionedConstantsOverrides {
validate_max_n_steps,
max_recursion_depth,
invoke_tx_max_n_steps,
} = versioned_constants_overrides;
Self {
validate_max_n_steps,
max_recursion_depth,
invoke_tx_max_n_steps,
..Self::latest_constants().clone()
if let Some(overrides) = versioned_constants_overrides {
let VersionedConstantsOverrides {
validate_max_n_steps,
max_recursion_depth,
invoke_tx_max_n_steps,
} = overrides;
Self {
validate_max_n_steps,
max_recursion_depth,
invoke_tx_max_n_steps,
..Self::latest_constants().clone()
}
} else {
Self::latest_constants().clone()
}
}

Expand Down Expand Up @@ -824,24 +828,14 @@ pub struct ResourcesByVersion {
pub deprecated_resources: ResourcesParams,
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
// TODO(Ayelet): Make fields optional.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct VersionedConstantsOverrides {
pub validate_max_n_steps: u32,
pub max_recursion_depth: usize,
pub invoke_tx_max_n_steps: u32,
}

impl Default for VersionedConstantsOverrides {
// TODO: update the default values once the actual values are known.
fn default() -> Self {
Self {
validate_max_n_steps: 1000000,
max_recursion_depth: 50,
invoke_tx_max_n_steps: 10000000,
}
}
}

impl SerializeConfig for VersionedConstantsOverrides {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
BTreeMap::from_iter([
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/versioned_constants_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ fn test_versioned_constants_overrides() {
let updated_max_recursion_depth = versioned_constants.max_recursion_depth + 1;

// Create a versioned constants copy with overriden values.
let result = VersionedConstants::get_versioned_constants(VersionedConstantsOverrides {
let result = VersionedConstants::get_versioned_constants(Some(VersionedConstantsOverrides {
validate_max_n_steps: updated_validate_max_n_steps,
max_recursion_depth: updated_max_recursion_depth,
invoke_tx_max_n_steps: updated_invoke_tx_max_n_steps,
});
}));

// Assert the new values are used.
assert_eq!(result.invoke_tx_max_n_steps, updated_invoke_tx_max_n_steps);
Expand Down
5 changes: 3 additions & 2 deletions crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ impl PyBlockExecutor {
log::debug!("Initializing Block Executor...");
let storage =
PapyrusStorage::new(target_storage_config).expect("Failed to initialize storage.");
let versioned_constants =
VersionedConstants::get_versioned_constants(py_versioned_constants_overrides.into());
let versioned_constants = VersionedConstants::get_versioned_constants(Some(
py_versioned_constants_overrides.into(),
));
log::debug!("Initialized Block Executor.");

Self {
Expand Down
5 changes: 3 additions & 2 deletions crates/native_blockifier/src/py_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ impl PyValidator {
let state = CachedState::new(state_reader);

// Create the block context.
let versioned_constants =
VersionedConstants::get_versioned_constants(py_versioned_constants_overrides.into());
let versioned_constants = VersionedConstants::get_versioned_constants(Some(
py_versioned_constants_overrides.into(),
));
let block_context = BlockContext::new(
next_block_info.try_into().expect("Failed to convert block info."),
os_config.into_chain_info(),
Expand Down

0 comments on commit 8c27843

Please sign in to comment.