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 17, 2024
1 parent 7affb82 commit 3df10e1
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 25 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(); //aviv: was true;
let validate_call_info = tx.validate_tx(
self.tx_executor.block_state.as_mut().expect(BLOCK_STATE_ACCESS_ERR),
&mut execution_resources,
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(); //aviv: was true
let result = entry_point_call
.execute_directly_given_tx_info(&mut state, tx_info, limit_steps_by_resources)
.unwrap();
Expand Down
3 changes: 2 additions & 1 deletion crates/blockifier/src/execution/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ 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 {
// aviv: was with '|| !tx_info.enforce_fee()'
return block_upper_bound;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ fn test_get_execution_info(
),
..trivial_external_entry_point_with_address(test_contract_address)
};

// let limit_steps_by_resources = tx_info.enforce_fee(); // aviv: new
let result = match execution_mode {
ExecutionMode::Validate => {
entry_point_call.execute_directly_given_tx_info_in_validate_mode(state, tx_info, false)
entry_point_call.execute_directly_given_tx_info_in_validate_mode(state, tx_info, false) //aviv: was ',false)': not needed?
}
ExecutionMode::Execute => {
entry_point_call.execute_directly_given_tx_info(state, tx_info, false)
entry_point_call.execute_directly_given_tx_info(state, tx_info, false) //aviv: was ',false)': not needed?
}
};

Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/test_utils/prices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn fee_transfer_resources(
&mut EntryPointExecutionContext::new(
Arc::new(block_context.to_tx_context(&account_invoke_tx(InvokeTxArgs::default()))),
ExecutionMode::Execute,
false,
false, // aviv: limit_steps_by_resources: can be enforce_fee() instead of false.?
),
)
.unwrap()
Expand Down
15 changes: 8 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(); // aviv: new
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(); // aviv: new
self.execute_directly_given_tx_info_in_validate_mode(
state,
TransactionInfo::Deprecated(DeprecatedTransactionInfo::default()),
true,
tx_info,
limit_steps_by_resources,
)
}

Expand All @@ -93,6 +93,7 @@ impl CallEntryPoint {
tx_info: TransactionInfo,
limit_steps_by_resources: bool,
) -> EntryPointExecutionResult<CallInfo> {
// aviv: let limit_steps = limit_steps_by_resources && tx_info.enforce_fee();
let tx_context =
TransactionContext { block_context: BlockContext::create_for_testing(), tx_info };
let mut context = EntryPointExecutionContext::new_validate(
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(); //aviv: new
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: 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; // aviv: new
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
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()); // aviv: new
let limit_steps_by_resources = tx_info.enforce_fee(); // aviv: new

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 3df10e1

Please sign in to comment.