Skip to content

Commit

Permalink
chore(blockifier): have limit_steps_by_resources flag rep charge_fee …
Browse files Browse the repository at this point in the history
…flag and enforce_fee ret val
  • Loading branch information
avivg-starkware committed Sep 19, 2024
1 parent 7dd6541 commit cf3b295
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 32 deletions.
2 changes: 1 addition & 1 deletion crates/blockifier/src/blockifier/stateful_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<S: StateReader> StatefulValidator<S> {
let mut execution_resources = ExecutionResources::default();
let tx_context = Arc::new(self.tx_executor.block_context.to_tx_context(tx));

let limit_steps_by_resources = true;
let limit_steps_by_resources = tx.create_tx_info().enforce_fee();
let validate_call_info = tx.validate_tx(
self.tx_executor.block_state.as_mut().expect(BLOCK_STATE_ACCESS_ERR),
&mut execution_resources,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/concurrency/versioned_state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ fn test_run_parallel_txs(max_resource_bounds: ValidResourceBounds) {
});
s.spawn(move || {
let charge_fee_2 = account_tx_2.create_tx_info().enforce_fee();
account_tx_2.execute(&mut state_2, &block_context_2, charge_fee_2, true).unwrap();
account_tx_2.execute(&mut state_2, &block_context_2, charge_fee_2, true).unwrap();
// Check that the constructor wrote ctor_arg to the storage.
let storage_key = get_storage_var_address("ctor_arg", &[]);
let deployed_contract_address = calculate_contract_address(
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/concurrency/worker_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<'a, S: StateReader> WorkerExecutor<'a, S> {
fn execute_tx(&self, tx_index: TxIndex) {
let mut tx_versioned_state = self.state.pin_version(tx_index);
let tx = &self.chunk[tx_index];
let tx_charge_fee = tx.create_tx_info().enforce_fee();
let tx_charge_fee = tx.create_tx_info().enforce_fee();
let mut transactional_state =
TransactionalState::create_transactional(&mut tx_versioned_state);
let execution_flags =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ fn test_tx_info(#[values(false, true)] only_query: bool) {
},
max_fee,
});
let limit_steps_by_resources = true;
let limit_steps_by_resources = tx_info.enforce_fee();
let result = entry_point_call
.execute_directly_given_tx_info(&mut state, tx_info, limit_steps_by_resources)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/execution/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl EntryPointExecutionContext {
.expect("Failed to convert invoke_tx_max_n_steps (u32) to usize."),
};

if !limit_steps_by_resources || !tx_info.enforce_fee() {
if !limit_steps_by_resources {
return block_upper_bound;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/execution/stack_trace_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ Execution failed. Failure reason: 0x496e76616c6964207363656e6172696f ('Invalid s
let re = Regex::new(r"pc=0:[0-9]+").unwrap();
let cleaned_expected_error = &re.replace_all(&expected_error, "pc=0:*");
let charge_fee = account_tx.create_tx_info().enforce_fee();
let actual_error = account_tx.execute(state, block_context, charge_fee, true).unwrap_err();
let actual_error = account_tx.execute(state, block_context, charge_fee, true).unwrap_err();
let actual_error_str = actual_error.to_string();
let cleaned_actual_error = &re.replace_all(&actual_error_str, "pc=0:*");
// Compare actual trace to the expected trace (sans pc locations).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ fn test_get_execution_info(
),
..trivial_external_entry_point_with_address(test_contract_address)
};

let result = match execution_mode {
ExecutionMode::Validate => {
entry_point_call.execute_directly_given_tx_info_in_validate_mode(state, tx_info, false)
Expand Down
14 changes: 7 additions & 7 deletions crates/blockifier/src/test_utils/struct_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ impl CallEntryPoint {
/// Executes the call directly, without account context. Limits the number of steps by resource
/// bounds.
pub fn execute_directly(self, state: &mut dyn State) -> EntryPointExecutionResult<CallInfo> {
self.execute_directly_given_tx_info(
state,
TransactionInfo::Deprecated(DeprecatedTransactionInfo::default()),
true,
)
let tx_info = TransactionInfo::Deprecated(DeprecatedTransactionInfo::default());
let limit_steps_by_resources = tx_info.enforce_fee();
self.execute_directly_given_tx_info(state, tx_info, limit_steps_by_resources)
}

pub fn execute_directly_given_tx_info(
Expand All @@ -80,10 +78,12 @@ impl CallEntryPoint {
self,
state: &mut dyn State,
) -> EntryPointExecutionResult<CallInfo> {
let tx_info = TransactionInfo::Deprecated(DeprecatedTransactionInfo::default());
let limit_steps_by_resources = tx_info.enforce_fee();
self.execute_directly_given_tx_info_in_validate_mode(
state,
TransactionInfo::Deprecated(DeprecatedTransactionInfo::default()),
true,
tx_info,
limit_steps_by_resources,
)
}

Expand Down
5 changes: 3 additions & 2 deletions crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,9 @@ impl AccountTransaction {
// The fee-token contract is a Cairo 0 contract, hence the initial gas is irrelevant.
initial_gas: block_context.versioned_constants.os_constants.gas_costs.initial_gas_cost,
};

let mut context = EntryPointExecutionContext::new_invoke(tx_context, true);
let limit_steps_by_resources = tx_info.enforce_fee();
let mut context =
EntryPointExecutionContext::new_invoke(tx_context, limit_steps_by_resources);

Ok(fee_transfer_call
.execute(state, &mut ExecutionResources::default(), &mut context)
Expand Down
7 changes: 1 addition & 6 deletions crates/blockifier/src/transaction/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,7 @@ pub fn run_invoke_tx(
let tx_context = Arc::new(block_context.to_tx_context(&tx));
let charge_fee = tx_context.tx_info.enforce_fee();

account_invoke_tx(invoke_args).execute(
state,
block_context,
charge_fee,
true,
)
account_invoke_tx(invoke_args).execute(state, block_context, charge_fee, true)
}

/// Creates a `ResourceBoundsMapping` with the given `max_amount` and `max_price` for L1 gas limits.
Expand Down
7 changes: 4 additions & 3 deletions crates/blockifier/src/transaction/transaction_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ impl<U: UpdatableState> ExecutableTransaction<U> for L1HandlerTransaction {
&self,
state: &mut TransactionalState<'_, U>,
block_context: &BlockContext,
_execution_flags: ExecutionFlags,
execution_flags: ExecutionFlags,
) -> TransactionExecutionResult<TransactionExecutionInfo> {
let tx_context = Arc::new(block_context.to_tx_context(self));

let limit_steps_by_resources = execution_flags.charge_fee;
let mut execution_resources = ExecutionResources::default();
let mut context = EntryPointExecutionContext::new_invoke(tx_context.clone(), true);
let mut context =
EntryPointExecutionContext::new_invoke(tx_context.clone(), limit_steps_by_resources);
let mut remaining_gas = block_context.versioned_constants.tx_initial_gas();
let execute_call_info =
self.run_execute(state, &mut execution_resources, &mut context, &mut remaining_gas)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ fn test_validate_accounts_tx(
..default_args
},
);
let result = account_tx.execute(state, block_context, default_charge_fee, true);
let result = account_tx.execute(state, block_context, default_charge_fee, true);
assert!(result.is_ok(), "Execution failed: {:?}", result.unwrap_err());
}
}
Expand Down
11 changes: 5 additions & 6 deletions crates/papyrus_execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,13 @@ pub fn execute_call(
execution_config,
override_kzg_da_to_false,
)?;
// TODO(yair): fix when supporting v3 transactions
let tx_info = TransactionInfo::Deprecated(DeprecatedTransactionInfo::default());
let limit_steps_by_resources = tx_info.enforce_fee();

let mut context = EntryPointExecutionContext::new_invoke(
// TODO(yair): fix when supporting v3 transactions
Arc::new(TransactionContext {
block_context,
tx_info: TransactionInfo::Deprecated(DeprecatedTransactionInfo::default()),
}),
true, // limit_steps_by_resources
Arc::new(TransactionContext { block_context, tx_info }),
limit_steps_by_resources,
);

let res = call_entry_point
Expand Down

0 comments on commit cf3b295

Please sign in to comment.