Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- TO DELETE chore(blockifier): ues account_transaction::ExecutionFlags instead of transaction::ExecutionFlags #2413

6 changes: 2 additions & 4 deletions crates/blockifier/src/blockifier/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::state::cached_state::{CachedState, CommitmentStateDiff, Transactional
use crate::state::errors::StateError;
use crate::state::state_api::{StateReader, StateResult};
use crate::transaction::errors::TransactionExecutionError;
use crate::transaction::objects::{TransactionExecutionInfo, TransactionInfoCreator};
use crate::transaction::objects::TransactionExecutionInfo;
use crate::transaction::transaction_execution::Transaction;
use crate::transaction::transactions::{ExecutableTransaction, ExecutionFlags};

Expand Down Expand Up @@ -100,11 +100,9 @@ impl<S: StateReader> TransactionExecutor<S> {
let mut transactional_state = TransactionalState::create_transactional(
self.block_state.as_mut().expect(BLOCK_STATE_ACCESS_ERR),
);
let tx_charge_fee = tx.create_tx_info().enforce_fee();

// Executing a single transaction cannot be done in a concurrent mode.
let execution_flags =
ExecutionFlags { charge_fee: tx_charge_fee, validate: true, concurrency_mode: false };
let execution_flags = ExecutionFlags { concurrency_mode: false };
let tx_execution_result =
tx.execute_raw(&mut transactional_state, &self.block_context, execution_flags);
match tx_execution_result {
Expand Down
34 changes: 23 additions & 11 deletions crates/blockifier/src/blockifier/transaction_executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::declare::declare_tx;
use crate::test_utils::deploy_account::deploy_account_tx;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::invoke::invoke_tx;
use crate::test_utils::l1_handler::l1handler_tx;
use crate::test_utils::{
create_calldata,
Expand All @@ -29,9 +30,9 @@ use crate::test_utils::{
BALANCE,
DEFAULT_STRK_L1_GAS_PRICE,
};
use crate::transaction::account_transaction::{AccountTransaction, ExecutionFlags};
use crate::transaction::errors::TransactionExecutionError;
use crate::transaction::test_utils::{
account_invoke_tx,
block_context,
calculate_class_info_for_testing,
create_test_init_data,
Expand All @@ -40,6 +41,7 @@ use crate::transaction::test_utils::{
TestInitData,
};
use crate::transaction::transaction_execution::Transaction;
use crate::transaction::transactions::enforce_fee;
fn tx_executor_test_body<S: StateReader>(
state: CachedState<S>,
block_context: BlockContext,
Expand Down Expand Up @@ -120,7 +122,7 @@ fn test_declare(
let declared_contract = FeatureContract::Empty(cairo_version);
let state = test_state(&block_context.chain_info, BALANCE, &[(account_contract, 1)]);

let tx = declare_tx(
let declare_tx = declare_tx(
declare_tx_args! {
sender_address: account_contract.get_instance_address(0),
class_hash: declared_contract.get_class_hash(),
Expand All @@ -129,8 +131,11 @@ fn test_declare(
resource_bounds: l1_resource_bounds(0_u8.into(), DEFAULT_STRK_L1_GAS_PRICE.into()),
},
calculate_class_info_for_testing(declared_contract.get_class()),
)
.into();
);
let only_query = false;
let charge_fee = enforce_fee(&declare_tx, only_query);
let execution_flags = ExecutionFlags { only_query, charge_fee, ..ExecutionFlags::default() };
let tx = AccountTransaction { tx: declare_tx, execution_flags }.into();
tx_executor_test_body(state, block_context, tx, expected_bouncer_weights);
}

Expand All @@ -143,21 +148,25 @@ fn test_deploy_account(
let account_contract = FeatureContract::AccountWithoutValidations(cairo_version);
let state = test_state(&block_context.chain_info, BALANCE, &[(account_contract, 0)]);

let tx = deploy_account_tx(
let deploy_tx = deploy_account_tx(
deploy_account_tx_args! {
class_hash: account_contract.get_class_hash(),
resource_bounds: l1_resource_bounds(0_u8.into(), DEFAULT_STRK_L1_GAS_PRICE.into()),
version,
},
&mut NonceManager::default(),
)
.into();
);
let only_query = false;
let charge_fee = enforce_fee(&deploy_tx, only_query);
let execution_flags = ExecutionFlags { only_query, charge_fee, ..ExecutionFlags::default() };
let tx = AccountTransaction { tx: deploy_tx, execution_flags }.into();
let expected_bouncer_weights = BouncerWeights {
state_diff_size: 3,
message_segment_length: 0,
n_events: 0,
..BouncerWeights::empty()
};
}
.into();
tx_executor_test_body(state, block_context, tx, expected_bouncer_weights);
}

Expand Down Expand Up @@ -217,12 +226,15 @@ fn test_invoke(

let calldata =
create_calldata(test_contract.get_instance_address(0), entry_point_name, &entry_point_args);
let tx = account_invoke_tx(invoke_tx_args! {
let invoke_tx = invoke_tx(invoke_tx_args! {
sender_address: account_contract.get_instance_address(0),
calldata,
version,
})
.into();
});
let only_query = false;
let charge_fee = enforce_fee(&invoke_tx, only_query);
let execution_flags = ExecutionFlags { only_query, charge_fee, ..ExecutionFlags::default() };
let tx = AccountTransaction { tx: invoke_tx, execution_flags }.into();
tx_executor_test_body(state, block_context, tx, expected_bouncer_weights);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/concurrency/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ 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 { charge_fee: true, validate: true, concurrency_mode };
let execution_flags = ExecutionFlags { concurrency_mode };
let execution_info =
account_tx.execute_raw(&mut transactional_state, &block_context, execution_flags).unwrap();

Expand Down
15 changes: 11 additions & 4 deletions crates/blockifier/src/concurrency/versioned_state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ use crate::test_utils::deploy_account::deploy_account_tx;
use crate::test_utils::dict_state_reader::DictStateReader;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{CairoVersion, BALANCE, DEFAULT_STRK_L1_GAS_PRICE};
use crate::transaction::account_transaction::{AccountTransaction, ExecutionFlags};
use crate::transaction::objects::HasRelatedFeeType;
use crate::transaction::test_utils::{default_all_resource_bounds, l1_resource_bounds};
use crate::transaction::transactions::ExecutableTransaction;
use crate::transaction::transactions::{enforce_fee, ExecutableTransaction};

#[fixture]
pub fn safe_versioned_state(
Expand Down Expand Up @@ -225,7 +226,7 @@ fn test_run_parallel_txs(default_all_resource_bounds: ValidResourceBounds) {
let mut state_2 = TransactionalState::create_transactional(&mut versioned_state_proxy_2);

// Prepare transactions
let deploy_account_tx_1 = deploy_account_tx(
let tx = deploy_account_tx(
deploy_account_tx_args! {
class_hash: account_without_validation.get_class_hash(),
resource_bounds: l1_resource_bounds(
Expand All @@ -235,7 +236,9 @@ fn test_run_parallel_txs(default_all_resource_bounds: ValidResourceBounds) {
},
&mut NonceManager::default(),
);
let enforce_fee = deploy_account_tx_1.enforce_fee();
let enforce_fee = enforce_fee(&tx, false);
let execution_flags = ExecutionFlags { charge_fee: enforce_fee, ..ExecutionFlags::default() };
let deploy_account_tx_1 = AccountTransaction { tx, execution_flags: execution_flags.clone() };

let class_hash = grindy_account.get_class_hash();
let ctor_storage_arg = felt!(1_u8);
Expand All @@ -247,7 +250,11 @@ fn test_run_parallel_txs(default_all_resource_bounds: ValidResourceBounds) {
constructor_calldata: constructor_calldata.clone(),
};
let nonce_manager = &mut NonceManager::default();
let delpoy_account_tx_2 = deploy_account_tx(deploy_tx_args, nonce_manager);
let delpoy_account_tx_2 = AccountTransaction {
tx: deploy_account_tx(deploy_tx_args, nonce_manager),
execution_flags,
};

let account_address = delpoy_account_tx_2.sender_address();
let tx_context = block_context.to_tx_context(&delpoy_account_tx_2);
let fee_type = tx_context.tx_info.fee_type();
Expand Down
10 changes: 2 additions & 8 deletions crates/blockifier/src/concurrency/worker_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ use crate::concurrency::TxIndex;
use crate::context::BlockContext;
use crate::state::cached_state::{ContractClassMapping, StateMaps, TransactionalState};
use crate::state::state_api::{StateReader, UpdatableState};
use crate::transaction::objects::{
TransactionExecutionInfo,
TransactionExecutionResult,
TransactionInfoCreator,
};
use crate::transaction::objects::{TransactionExecutionInfo, TransactionExecutionResult};
use crate::transaction::transaction_execution::Transaction;
use crate::transaction::transactions::{ExecutableTransaction, ExecutionFlags};

Expand Down Expand Up @@ -127,11 +123,9 @@ 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 mut transactional_state =
TransactionalState::create_transactional(&mut tx_versioned_state);
let execution_flags =
ExecutionFlags { charge_fee: tx_charge_fee, validate: true, concurrency_mode: true };
let execution_flags = ExecutionFlags { concurrency_mode: true };
let execution_result =
tx.execute_raw(&mut transactional_state, self.block_context, execution_flags);

Expand Down
10 changes: 7 additions & 3 deletions crates/blockifier/src/concurrency/worker_logic_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::test_utils::{
BALANCE,
TEST_ERC20_CONTRACT_ADDRESS2,
};
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::account_transaction::{AccountTransaction, ExecutionFlags};
use crate::transaction::objects::HasRelatedFeeType;
use crate::transaction::test_utils::{
account_invoke_tx,
Expand Down Expand Up @@ -561,6 +561,8 @@ fn test_deploy_before_declare(
},
test_class_info.clone(),
);
let execution_flags = ExecutionFlags::default();
let declare_account_tx = AccountTransaction { tx: declare_tx, execution_flags };

// Deploy test contract.
let invoke_tx = account_invoke_tx(invoke_tx_args! {
Expand All @@ -580,8 +582,10 @@ fn test_deploy_before_declare(
nonce: nonce!(0_u8)
});

let txs =
[declare_tx, invoke_tx].into_iter().map(Transaction::Account).collect::<Vec<Transaction>>();
let txs = [declare_account_tx, invoke_tx]
.into_iter()
.map(Transaction::Account)
.collect::<Vec<Transaction>>();

let mut bouncer = Bouncer::new(block_context.bouncer_config.clone());
let worker_executor =
Expand Down
6 changes: 6 additions & 0 deletions crates/blockifier/src/execution/stack_trace_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use crate::execution::syscalls::hint_processor::ENTRYPOINT_FAILED_ERROR;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::{fund_account, test_state};
use crate::test_utils::{create_calldata, CairoVersion, BALANCE};
use crate::transaction::account_transaction::{AccountTransaction, ExecutionFlags};
use crate::transaction::test_utils::{
account_invoke_tx,
block_context,
Expand Down Expand Up @@ -608,6 +609,11 @@ fn test_validate_trace(
}
}

// TODO(AvivG): Change this fixup to not create account_tx twice w wrong charge_fee.
let execution_flags =
ExecutionFlags { charge_fee: account_tx.enforce_fee(), ..ExecutionFlags::default() };
let account_tx = AccountTransaction { tx: account_tx.tx, execution_flags };

let contract_address = *sender_address.0.key();

let expected_error = match cairo_version {
Expand Down
5 changes: 2 additions & 3 deletions crates/blockifier/src/test_utils/declare.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use starknet_api::contract_class::ClassInfo;
use starknet_api::executable_transaction::AccountTransaction;
use starknet_api::test_utils::declare::{executable_declare_tx, DeclareTxArgs};

use crate::transaction::account_transaction::AccountTransaction;

pub fn declare_tx(declare_tx_args: DeclareTxArgs, class_info: ClassInfo) -> AccountTransaction {
let declare_tx = executable_declare_tx(declare_tx_args, class_info);

declare_tx.into()
AccountTransaction::Declare(declare_tx)
}
5 changes: 2 additions & 3 deletions crates/blockifier/src/test_utils/deploy_account.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use starknet_api::executable_transaction::AccountTransaction;
use starknet_api::test_utils::deploy_account::{executable_deploy_account_tx, DeployAccountTxArgs};
use starknet_api::test_utils::NonceManager;

use crate::transaction::account_transaction::AccountTransaction;

pub fn deploy_account_tx(
deploy_tx_args: DeployAccountTxArgs,
nonce_manager: &mut NonceManager,
) -> AccountTransaction {
let deploy_account_tx = executable_deploy_account_tx(deploy_tx_args, nonce_manager);

deploy_account_tx.into()
AccountTransaction::DeployAccount(deploy_account_tx)
}
12 changes: 2 additions & 10 deletions crates/blockifier/src/test_utils/invoke.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
use starknet_api::executable_transaction::AccountTransaction as ExecutableTransaction;
use starknet_api::executable_transaction::AccountTransaction;
use starknet_api::test_utils::invoke::{executable_invoke_tx, InvokeTxArgs};

use crate::transaction::account_transaction::AccountTransaction;

pub fn invoke_tx(invoke_args: InvokeTxArgs) -> AccountTransaction {
let only_query = invoke_args.only_query;
let invoke_tx = ExecutableTransaction::Invoke(executable_invoke_tx(invoke_args));

match only_query {
true => AccountTransaction::new_for_query(invoke_tx),
false => AccountTransaction::new(invoke_tx),
}
AccountTransaction::Invoke(executable_invoke_tx(invoke_args))
}
16 changes: 12 additions & 4 deletions crates/blockifier/src/test_utils/transfers_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use starknet_api::abi::abi_utils::selector_from_name;
use starknet_api::core::ContractAddress;
use starknet_api::executable_transaction::AccountTransaction as ApiExecutableTransaction;
use starknet_api::test_utils::NonceManager;
use starknet_api::transaction::constants::TRANSFER_ENTRY_POINT_NAME;
use starknet_api::transaction::fields::Fee;
Expand All @@ -17,9 +18,9 @@ use crate::test_utils::dict_state_reader::DictStateReader;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::invoke::invoke_tx;
use crate::test_utils::{CairoVersion, BALANCE, MAX_FEE};
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::account_transaction::{AccountTransaction, ExecutionFlags};
use crate::transaction::transaction_execution::Transaction;

use crate::transaction::transactions::enforce_fee;
const N_ACCOUNTS: u16 = 10000;
const N_TXS: usize = 1000;
const RANDOMIZATION_SEED: u64 = 0;
Expand Down Expand Up @@ -143,7 +144,14 @@ impl TransfersGenerator {
let recipient_address = self.get_next_recipient();
self.sender_index = (self.sender_index + 1) % self.account_addresses.len();

let account_tx = self.generate_transfer(sender_address, recipient_address);
let tx = self.generate_transfer(sender_address, recipient_address);
let only_query = false;
let execution_flags = ExecutionFlags {
charge_fee: enforce_fee(&tx, only_query),
only_query,
..ExecutionFlags::default()
};
let account_tx = AccountTransaction { tx, execution_flags };
txs.push(Transaction::Account(account_tx));
}
let results = self.executor.execute_txs(&txs);
Expand All @@ -159,7 +167,7 @@ impl TransfersGenerator {
&mut self,
sender_address: ContractAddress,
recipient_address: ContractAddress,
) -> AccountTransaction {
) -> ApiExecutableTransaction {
let nonce = self.nonce_manager.next(sender_address);

let entry_point_selector = selector_from_name(TRANSFER_ENTRY_POINT_NAME);
Expand Down
Loading
Loading