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
ArniStarkware committed Nov 5, 2024
1 parent fcc6b10 commit a1c02ec
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
5 changes: 5 additions & 0 deletions config/mempool/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 14 additions & 9 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 @@ -101,7 +106,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 @@ -129,8 +134,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 @@ -229,8 +234,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 All @@ -257,12 +261,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,
);

Expand Down
13 changes: 12 additions & 1 deletion crates/blockifier/src/versioned_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,15 @@ 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() }
}

/// Returns the latest versioned constants after applying the given overrides.
/// Returns the latest versioned constants, applying the given overrides.
pub fn get_versioned_constants(
versioned_constants_overrides: VersionedConstantsOverrides,
) -> Self {
Expand All @@ -323,6 +324,16 @@ 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

0 comments on commit a1c02ec

Please sign in to comment.