Skip to content

Commit 8ad7b5a

Browse files
apollo_batcher: make versioned constants override optional
1 parent 84ecdb6 commit 8ad7b5a

File tree

6 files changed

+34
-26
lines changed

6 files changed

+34
-26
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
@@ -72,9 +72,9 @@ impl StatefulTransactionValidatorFactoryTrait for StatefulTransactionValidatorFa
7272
let latest_block_info = get_latest_block_info(&state_reader)?;
7373

7474
let state = CachedState::new(state_reader);
75-
let mut versioned_constants = VersionedConstants::get_versioned_constants(
75+
let mut versioned_constants = VersionedConstants::get_versioned_constants(Some(
7676
self.config.versioned_constants_overrides.clone(),
77-
);
77+
));
7878
// The validation of a transaction is not affected by the casm hash migration.
7979
versioned_constants.enable_casm_hash_migration = false;
8080

crates/blockifier/src/blockifier_versioned_constants.rs

Lines changed: 22 additions & 16 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;
448-
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
442+
match versioned_constants_overrides {
443+
None => Self::latest_constants().clone(),
444+
Some(VersionedConstantsOverrides {
445+
validate_max_n_steps,
446+
max_recursion_depth,
447+
invoke_tx_max_n_steps,
448+
max_n_events,
449+
}) => {
450+
let latest_constants = Self::latest_constants().clone();
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
@@ -101,8 +101,9 @@ impl PyBlockExecutor {
101101
log::debug!("Initializing Block Executor...");
102102
let storage =
103103
PapyrusStorage::new(target_storage_config).expect("Failed to initialize storage.");
104-
let versioned_constants =
105-
VersionedConstants::get_versioned_constants(py_versioned_constants_overrides.into());
104+
let versioned_constants = VersionedConstants::get_versioned_constants(Some(
105+
py_versioned_constants_overrides.into(),
106+
));
106107
log::debug!("Initialized Block Executor.");
107108

108109
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)