Skip to content

Commit 03bd26a

Browse files
apollo_batcher: make versioned constants override optional
1 parent c94635e commit 03bd26a

File tree

6 files changed

+33
-25
lines changed

6 files changed

+33
-25
lines changed

crates/apollo_batcher/src/block_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,9 @@ impl BlockBuilderFactory {
712712
);
713713
let height = block_metadata.block_info.block_number;
714714
let block_builder_config = self.block_builder_config.clone();
715-
let versioned_constants = VersionedConstants::get_versioned_constants(
715+
let versioned_constants = VersionedConstants::get_versioned_constants(Some(
716716
block_builder_config.versioned_constants_overrides,
717-
);
717+
));
718718
let block_context = BlockContext::new(
719719
block_metadata.block_info,
720720
block_builder_config.chain_info,

crates/apollo_gateway/src/stateful_transaction_validator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ impl StatefulTransactionValidatorFactoryTrait for StatefulTransactionValidatorFa
8787
};
8888

8989
let state = CachedState::new(state_reader_and_contract_manager);
90-
let mut versioned_constants = VersionedConstants::get_versioned_constants(
90+
let mut versioned_constants = VersionedConstants::get_versioned_constants(Some(
9191
self.config.versioned_constants_overrides.clone(),
92-
);
92+
));
9393
// The validation of a transaction is not affected by the casm hash migration.
9494
versioned_constants.enable_casm_hash_migration = false;
9595

crates/blockifier/src/blockifier_versioned_constants.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -437,23 +437,29 @@ impl VersionedConstants {
437437
// squashing the functions together.
438438
/// Returns the latest versioned constants, applying the given overrides.
439439
pub fn get_versioned_constants(
440-
versioned_constants_overrides: VersionedConstantsOverrides,
440+
versioned_constants_overrides: Option<VersionedConstantsOverrides>,
441441
) -> Self {
442-
let VersionedConstantsOverrides {
443-
validate_max_n_steps,
444-
max_recursion_depth,
445-
invoke_tx_max_n_steps,
446-
max_n_events,
447-
} = versioned_constants_overrides;
448442
let latest_constants = Self::latest_constants().clone();
449-
let tx_event_limits =
450-
EventLimits { max_n_emitted_events: max_n_events, ..latest_constants.tx_event_limits };
451-
Self {
452-
validate_max_n_steps,
453-
max_recursion_depth,
454-
invoke_tx_max_n_steps,
455-
tx_event_limits,
456-
..latest_constants
443+
match versioned_constants_overrides {
444+
None => latest_constants,
445+
Some(VersionedConstantsOverrides {
446+
validate_max_n_steps,
447+
max_recursion_depth,
448+
invoke_tx_max_n_steps,
449+
max_n_events,
450+
}) => {
451+
let tx_event_limits = EventLimits {
452+
max_n_emitted_events: max_n_events,
453+
..latest_constants.tx_event_limits
454+
};
455+
Self {
456+
validate_max_n_steps,
457+
max_recursion_depth,
458+
invoke_tx_max_n_steps,
459+
tx_event_limits,
460+
..latest_constants
461+
}
462+
}
457463
}
458464
}
459465

crates/blockifier/src/versioned_constants_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ fn test_versioned_constants_overrides() {
2929
let updated_max_n_events = versioned_constants.tx_event_limits.max_n_emitted_events + 1;
3030

3131
// Create a versioned constants copy with overriden values.
32-
let result = VersionedConstants::get_versioned_constants(VersionedConstantsOverrides {
32+
let result = VersionedConstants::get_versioned_constants(Some(VersionedConstantsOverrides {
3333
validate_max_n_steps: updated_validate_max_n_steps,
3434
max_recursion_depth: updated_max_recursion_depth,
3535
invoke_tx_max_n_steps: updated_invoke_tx_max_n_steps,
3636
max_n_events: updated_max_n_events,
37-
});
37+
}));
3838

3939
// Assert the new values are used.
4040
assert_eq!(result.invoke_tx_max_n_steps, updated_invoke_tx_max_n_steps);

crates/native_blockifier/src/py_block_executor.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ impl PyBlockExecutor {
120120
log::debug!("Initializing Block Executor...");
121121
let storage =
122122
PapyrusStorage::new(target_storage_config).expect("Failed to initialize storage.");
123-
let versioned_constants =
124-
VersionedConstants::get_versioned_constants(py_versioned_constants_overrides.into());
123+
let versioned_constants = VersionedConstants::get_versioned_constants(Some(
124+
py_versioned_constants_overrides.into(),
125+
));
125126
log::debug!("Initialized Block Executor.");
126127

127128
Self {

crates/native_blockifier/src/py_validator.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ impl PyValidator {
4343
let state = CachedState::new(state_reader);
4444

4545
// Create the block context.
46-
let mut versioned_constants =
47-
VersionedConstants::get_versioned_constants(py_versioned_constants_overrides.into());
46+
let mut versioned_constants = VersionedConstants::get_versioned_constants(Some(
47+
py_versioned_constants_overrides.into(),
48+
));
4849
// The validation of a transaction is not affected by the casm hash migration.
4950
versioned_constants.enable_casm_hash_migration = false;
5051
let block_context = BlockContext::new(

0 commit comments

Comments
 (0)