Skip to content

Commit

Permalink
chore(blockifier): remove struct ExecutionFlags and replace w concurr…
Browse files Browse the repository at this point in the history
…ency_mode bool
  • Loading branch information
avivg-starkware committed Dec 5, 2024
1 parent 7a4c3d1 commit ccdd83a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 31 deletions.
6 changes: 3 additions & 3 deletions crates/blockifier/src/blockifier/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::state::state_api::{StateReader, StateResult};
use crate::transaction::errors::TransactionExecutionError;
use crate::transaction::objects::TransactionExecutionInfo;
use crate::transaction::transaction_execution::Transaction;
use crate::transaction::transactions::{ExecutableTransaction, ExecutionFlags};
use crate::transaction::transactions::ExecutableTransaction;

#[cfg(test)]
#[path = "transaction_executor_test.rs"]
Expand Down Expand Up @@ -102,9 +102,9 @@ impl<S: StateReader> TransactionExecutor<S> {
);

// Executing a single transaction cannot be done in a concurrent mode.
let execution_flags = ExecutionFlags { concurrency_mode: false };
let concurrency_mode = false;
let tx_execution_result =
tx.execute_raw(&mut transactional_state, &self.block_context, execution_flags);
tx.execute_raw(&mut transactional_state, &self.block_context, concurrency_mode);
match tx_execution_result {
Ok(tx_execution_info) => {
let tx_state_changes_keys =
Expand Down
5 changes: 2 additions & 3 deletions crates/blockifier/src/concurrency/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::state::cached_state::{CachedState, TransactionalState};
use crate::state::state_api::StateReader;
use crate::test_utils::dict_state_reader::DictStateReader;
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::transactions::{ExecutableTransaction, ExecutionFlags};
use crate::transaction::transactions::ExecutableTransaction;

// Public Consts.

Expand Down Expand Up @@ -76,9 +76,8 @@ pub fn create_fee_transfer_call_info<S: StateReader>(
) -> CallInfo {
let block_context = BlockContext::create_for_account_testing();
let mut transactional_state = TransactionalState::create_transactional(state);
let execution_flags = ExecutionFlags { concurrency_mode };
let execution_info =
account_tx.execute_raw(&mut transactional_state, &block_context, execution_flags).unwrap();
account_tx.execute_raw(&mut transactional_state, &block_context, concurrency_mode).unwrap();

let execution_info = execution_info.fee_transfer_call_info.unwrap();
transactional_state.abort();
Expand Down
6 changes: 3 additions & 3 deletions crates/blockifier/src/concurrency/worker_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::state::cached_state::{ContractClassMapping, StateMaps, TransactionalS
use crate::state::state_api::{StateReader, UpdatableState};
use crate::transaction::objects::{TransactionExecutionInfo, TransactionExecutionResult};
use crate::transaction::transaction_execution::Transaction;
use crate::transaction::transactions::{ExecutableTransaction, ExecutionFlags};
use crate::transaction::transactions::ExecutableTransaction;

#[cfg(test)]
#[path = "worker_logic_test.rs"]
Expand Down Expand Up @@ -125,9 +125,9 @@ impl<'a, S: StateReader> WorkerExecutor<'a, S> {
let tx = &self.chunk[tx_index];
let mut transactional_state =
TransactionalState::create_transactional(&mut tx_versioned_state);
let execution_flags = ExecutionFlags { concurrency_mode: true };
let concurrency_mode = true;
let execution_result =
tx.execute_raw(&mut transactional_state, self.block_context, execution_flags);
tx.execute_raw(&mut transactional_state, self.block_context, concurrency_mode);

// Update the versioned state and store the transaction execution output.
let execution_output_inner = match execution_result {
Expand Down
5 changes: 2 additions & 3 deletions crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ use crate::transaction::transactions::{
enforce_fee,
Executable,
ExecutableTransaction,
ExecutionFlags as TransactionExecutionFlags,
ValidatableTransaction,
};

Expand Down Expand Up @@ -743,7 +742,7 @@ impl<U: UpdatableState> ExecutableTransaction<U> for AccountTransaction {
&self,
state: &mut TransactionalState<'_, U>,
block_context: &BlockContext,
execution_flags_: TransactionExecutionFlags,
concurrency_mode: bool,
) -> TransactionExecutionResult<TransactionExecutionInfo> {
let tx_context = Arc::new(block_context.to_tx_context(self));
self.verify_tx_version(tx_context.tx_info.version())?;
Expand Down Expand Up @@ -785,7 +784,7 @@ impl<U: UpdatableState> ExecutableTransaction<U> for AccountTransaction {
final_fee,
// TODO (AvivG): access execution_flags within func instead of passing them as args.
self.execution_flags.charge_fee,
execution_flags_.concurrency_mode,
concurrency_mode,
)?;

let tx_execution_info = TransactionExecutionInfo {
Expand Down
20 changes: 10 additions & 10 deletions crates/blockifier/src/transaction/account_transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ use crate::transaction::test_utils::{
INVALID,
};
use crate::transaction::transaction_types::TransactionType;
use crate::transaction::transactions::{ExecutableTransaction, ExecutionFlags};
use crate::transaction::transactions::ExecutableTransaction;
use crate::utils::u64_from_usize;

#[rstest]
Expand Down Expand Up @@ -1364,9 +1364,9 @@ fn test_count_actual_storage_changes(
nonce: nonce_manager.next(account_address),
};
let account_tx = account_invoke_tx(invoke_args.clone());
let execution_flags = ExecutionFlags { concurrency_mode: false };
let concurrency_mode = false;
let execution_info =
account_tx.execute_raw(&mut state, &block_context, execution_flags).unwrap();
account_tx.execute_raw(&mut state, &block_context, concurrency_mode).unwrap();

let fee_1 = execution_info.receipt.fee;
let state_changes_1 = state.get_actual_state_changes().unwrap();
Expand Down Expand Up @@ -1414,7 +1414,7 @@ fn test_count_actual_storage_changes(
..invoke_args.clone()
});
let execution_info =
account_tx.execute_raw(&mut state, &block_context, execution_flags).unwrap();
account_tx.execute_raw(&mut state, &block_context, concurrency_mode).unwrap();

let fee_2 = execution_info.receipt.fee;
let state_changes_2 = state.get_actual_state_changes().unwrap();
Expand Down Expand Up @@ -1455,7 +1455,7 @@ fn test_count_actual_storage_changes(
..invoke_args
});
let execution_info =
account_tx.execute_raw(&mut state, &block_context, execution_flags).unwrap();
account_tx.execute_raw(&mut state, &block_context, concurrency_mode).unwrap();

let fee_transfer = execution_info.receipt.fee;
let state_changes_transfer = state.get_actual_state_changes().unwrap();
Expand Down Expand Up @@ -1534,9 +1534,9 @@ fn test_concurrency_execute_fee_transfer(
// Case 1: The transaction did not read form/ write to the sequenser balance before executing
// fee transfer.
let mut transactional_state = TransactionalState::create_transactional(state);
let execution_flags = ExecutionFlags { concurrency_mode: true };
let concurrency_mode = true;
let result =
account_tx.execute_raw(&mut transactional_state, &block_context, execution_flags).unwrap();
account_tx.execute_raw(&mut transactional_state, &block_context, concurrency_mode).unwrap();
assert!(!result.is_reverted());
let transactional_cache = transactional_state.cache.borrow();
for storage in [
Expand Down Expand Up @@ -1575,7 +1575,7 @@ fn test_concurrency_execute_fee_transfer(
});

let execution_result =
account_tx.execute_raw(&mut transactional_state, &block_context, execution_flags);
account_tx.execute_raw(&mut transactional_state, &block_context, concurrency_mode);
let result = execution_result.unwrap();
assert!(!result.is_reverted());
// Check that the sequencer balance was not updated.
Expand Down Expand Up @@ -1629,9 +1629,9 @@ fn test_concurrent_fee_transfer_when_sender_is_sequencer(
let fee_token_address = block_context.chain_info.fee_token_address(fee_type);

let mut transactional_state = TransactionalState::create_transactional(state);
let execution_flags = ExecutionFlags { concurrency_mode: true };
let concurrency_mode = true;
let result =
account_tx.execute_raw(&mut transactional_state, &block_context, execution_flags).unwrap();
account_tx.execute_raw(&mut transactional_state, &block_context, concurrency_mode).unwrap();
assert!(!result.is_reverted());
// Check that the sequencer balance was updated (in this case, was not changed).
for (seq_key, seq_value) in
Expand Down
11 changes: 5 additions & 6 deletions crates/blockifier/src/transaction/transaction_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::transaction::objects::{
TransactionInfo,
TransactionInfoCreator,
};
use crate::transaction::transactions::{Executable, ExecutableTransaction, ExecutionFlags};
use crate::transaction::transactions::{Executable, ExecutableTransaction};

// TODO: Move into transaction.rs, makes more sense to be defined there.
#[derive(Clone, Debug, derive_more::From)]
Expand Down Expand Up @@ -140,7 +140,7 @@ impl<U: UpdatableState> ExecutableTransaction<U> for L1HandlerTransaction {
&self,
state: &mut TransactionalState<'_, U>,
block_context: &BlockContext,
_execution_flags: ExecutionFlags,
_concurrency_mode: bool,
) -> TransactionExecutionResult<TransactionExecutionInfo> {
let tx_context = Arc::new(block_context.to_tx_context(self));
let limit_steps_by_resources = false;
Expand Down Expand Up @@ -188,17 +188,16 @@ impl<U: UpdatableState> ExecutableTransaction<U> for Transaction {
&self,
state: &mut TransactionalState<'_, U>,
block_context: &BlockContext,
execution_flags: ExecutionFlags,
concurrency_mode: bool,
) -> TransactionExecutionResult<TransactionExecutionInfo> {
// TODO(Yoni, 1/8/2024): consider unimplementing the ExecutableTransaction trait for inner
// types, since now running Transaction::execute_raw is not identical to
// AccountTransaction::execute_raw.
let concurrency_mode = execution_flags.concurrency_mode;
let tx_execution_info = match self {
Self::Account(account_tx) => {
account_tx.execute_raw(state, block_context, execution_flags)?
account_tx.execute_raw(state, block_context, concurrency_mode)?
}
Self::L1Handler(tx) => tx.execute_raw(state, block_context, execution_flags)?,
Self::L1Handler(tx) => tx.execute_raw(state, block_context, concurrency_mode)?,
};

// Check if the transaction is too large to fit any block.
Expand Down
6 changes: 3 additions & 3 deletions crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ pub trait ExecutableTransaction<U: UpdatableState>: Sized {
) -> TransactionExecutionResult<TransactionExecutionInfo> {
log::debug!("Executing Transaction...");
let mut transactional_state = TransactionalState::create_transactional(state);
let execution_flags = ExecutionFlags { concurrency_mode: false };
let concurrency_mode = false;
let execution_result =
self.execute_raw(&mut transactional_state, block_context, execution_flags);
self.execute_raw(&mut transactional_state, block_context, concurrency_mode);

match execution_result {
Ok(value) => {
Expand All @@ -92,7 +92,7 @@ pub trait ExecutableTransaction<U: UpdatableState>: Sized {
&self,
state: &mut TransactionalState<'_, U>,
block_context: &BlockContext,
execution_flags: ExecutionFlags,
concurrency_mode: bool,
) -> TransactionExecutionResult<TransactionExecutionInfo>;
}

Expand Down

0 comments on commit ccdd83a

Please sign in to comment.