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 Oct 13, 2024
1 parent c62db67 commit d1996b7
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
3 changes: 2 additions & 1 deletion crates/blockifier/src/blockifier/stateful_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::state::errors::StateError;
use crate::state::state_api::StateReader;
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::errors::{TransactionExecutionError, TransactionPreValidationError};
use crate::transaction::objects::TransactionInfoCreator;
use crate::transaction::transaction_execution::Transaction;
use crate::transaction::transactions::ValidatableTransaction;

Expand Down Expand Up @@ -114,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
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ fn test_tx_info(#[values(false, true)] only_query: bool) {
},
max_fee,
});
let limit_steps_by_resources = true;
let limit_steps_by_resources = false; // Do not limit steps by resources as we use default reasources.
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 @@ -273,7 +273,7 @@ impl EntryPointExecutionContext {
usize::MAX
});

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,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
16 changes: 9 additions & 7 deletions crates/blockifier/src/test_utils/struct_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ 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 = false; // Do not limit steps by resources as we use default reasources.

self.execute_directly_given_tx_info(state, tx_info, limit_steps_by_resources)
}

pub fn execute_directly_given_tx_info(
Expand All @@ -74,10 +73,13 @@ impl CallEntryPoint {
self,
state: &mut dyn State,
) -> EntryPointExecutionResult<CallInfo> {
let tx_info = TransactionInfo::Deprecated(DeprecatedTransactionInfo::default());
let limit_steps_by_resources = false; // Do not limit steps by resources as we use default reasources.

self.execute_directly_given_tx_info_in_validate_mode(
state,
TransactionInfo::Deprecated(DeprecatedTransactionInfo::default()),
true,
tx_info,
limit_steps_by_resources,
)
}

Expand Down
1 change: 0 additions & 1 deletion crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ impl AccountTransaction {
.gas_costs
.default_initial_gas_cost,
};

let mut context = EntryPointExecutionContext::new_invoke(tx_context, true);

Ok(fee_transfer_call
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 @@ -135,12 +135,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_default_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 @@ -245,14 +245,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 = false; // Default resource bounds.

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 d1996b7

Please sign in to comment.