Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
fix(transaction): remove charge fee flag from the transaction executo…
Browse files Browse the repository at this point in the history
…r execute
  • Loading branch information
meship-starkware committed Jun 10, 2024
1 parent 952373d commit 61e4974
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 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 @@ -97,7 +97,7 @@ impl<S: StateReader> StatefulValidator<S> {
}

fn execute(&mut self, tx: AccountTransaction) -> StatefulValidatorResult<()> {
self.tx_executor.execute(&Transaction::AccountTransaction(tx), true)?;
self.tx_executor.execute(&Transaction::AccountTransaction(tx))?;
Ok(())
}

Expand Down
11 changes: 4 additions & 7 deletions crates/blockifier/src/blockifier/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ impl<S: StateReader> TransactionExecutor<S> {
pub fn execute(
&mut self,
tx: &Transaction,
charge_fee: bool,
) -> TransactionExecutorResult<TransactionExecutionInfo> {
let mut transactional_state = TransactionalState::create_transactional(
self.block_state.as_mut().expect(BLOCK_STATE_ACCESS_ERR),
);
let validate = true;
let charge_fee = true;

let tx_execution_result =
tx.execute_raw(&mut transactional_state, &self.block_context, charge_fee, validate);
Expand Down Expand Up @@ -110,14 +110,13 @@ impl<S: StateReader> TransactionExecutor<S> {
pub fn execute_txs(
&mut self,
txs: &[Transaction],
charge_fee: bool,
) -> Vec<TransactionExecutorResult<TransactionExecutionInfo>> {
if !self.config.concurrency_config.enabled {
self.execute_txs_sequentially(txs, charge_fee)
self.execute_txs_sequentially(txs)
} else {
txs.chunks(self.config.concurrency_config.chunk_size)
.fold_while(Vec::new(), |mut results, chunk| {
let chunk_results = self.execute_chunk(chunk, charge_fee);
let chunk_results = self.execute_chunk(chunk);
if chunk_results.len() < chunk.len() {
// Block is full.
results.extend(chunk_results);
Expand All @@ -134,19 +133,17 @@ impl<S: StateReader> TransactionExecutor<S> {
pub fn execute_chunk(
&mut self,
_chunk: &[Transaction],
_charge_fee: bool,
) -> Vec<TransactionExecutorResult<TransactionExecutionInfo>> {
todo!()
}

pub fn execute_txs_sequentially(
&mut self,
txs: &[Transaction],
charge_fee: bool,
) -> Vec<TransactionExecutorResult<TransactionExecutionInfo>> {
let mut results = Vec::new();
for tx in txs {
match self.execute(tx, charge_fee) {
match self.execute(tx) {
Ok(tx_execution_info) => results.push(Ok(tx_execution_info)),
Err(TransactionExecutorError::BlockFull) => break,
Err(error) => results.push(Err(error)),
Expand Down
31 changes: 12 additions & 19 deletions crates/blockifier/src/blockifier/transaction_executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ fn tx_executor_test_body<S: StateReader>(
state: CachedState<S>,
block_context: BlockContext,
tx: Transaction,
charge_fee: bool,
expected_bouncer_weights: BouncerWeights,
) {
let mut tx_executor =
TransactionExecutor::new(state, block_context, TransactionExecutorConfig::default());
// TODO(Arni, 30/03/2024): Consider adding a test for the transaction execution info. If A test
// should not be added, rename the test to `test_bouncer_info`.
// TODO(Arni, 30/03/2024): Test all bouncer weights.
let _tx_execution_info = tx_executor.execute(&tx, charge_fee).unwrap();
let _tx_execution_info = tx_executor.execute(&tx).unwrap();
let bouncer_weights = tx_executor.bouncer.get_accumulated_weights();
assert_eq!(bouncer_weights.state_diff_size, expected_bouncer_weights.state_diff_size);
assert_eq!(
Expand Down Expand Up @@ -95,7 +94,6 @@ fn tx_executor_test_body<S: StateReader>(
)]
fn test_declare(
block_context: BlockContext,
#[values(true, false)] charge_fee: bool,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] account_cairo_version: CairoVersion,
#[case] transaction_version: TransactionVersion,
#[case] cairo_version: CairoVersion,
Expand All @@ -115,15 +113,14 @@ fn test_declare(
},
calculate_class_info_for_testing(declared_contract.get_class()),
));
tx_executor_test_body(state, block_context, tx, charge_fee, expected_bouncer_weights);
tx_executor_test_body(state, block_context, tx, expected_bouncer_weights);
}

#[rstest]
fn test_deploy_account(
block_context: BlockContext,
#[values(TransactionVersion::ONE, TransactionVersion::THREE)] version: TransactionVersion,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion,
#[values(true, false)] charge_fee: bool,
) {
let account_contract = FeatureContract::AccountWithoutValidations(cairo_version);
let state = test_state(&block_context.chain_info, BALANCE, &[(account_contract, 0)]);
Expand All @@ -142,7 +139,7 @@ fn test_deploy_account(
n_events: 0,
..Default::default()
};
tx_executor_test_body(state, block_context, tx, charge_fee, expected_bouncer_weights);
tx_executor_test_body(state, block_context, tx, expected_bouncer_weights);
}

#[rstest]
Expand Down Expand Up @@ -185,7 +182,6 @@ fn test_deploy_account(
)]
fn test_invoke(
block_context: BlockContext,
#[values(true, false)] charge_fee: bool,
#[values(TransactionVersion::ONE, TransactionVersion::THREE)] version: TransactionVersion,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion,
#[case] entry_point_name: &str,
Expand All @@ -207,11 +203,11 @@ fn test_invoke(
calldata,
version,
}));
tx_executor_test_body(state, block_context, tx, charge_fee, expected_bouncer_weights);
tx_executor_test_body(state, block_context, tx, expected_bouncer_weights);
}

#[rstest]
fn test_l1_handler(block_context: BlockContext, #[values(true, false)] charge_fee: bool) {
fn test_l1_handler(block_context: BlockContext) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1);
let state = test_state(&block_context.chain_info, BALANCE, &[(test_contract, 1)]);

Expand All @@ -225,7 +221,7 @@ fn test_l1_handler(block_context: BlockContext, #[values(true, false)] charge_fe
n_events: 0,
..Default::default()
};
tx_executor_test_body(state, block_context, tx, charge_fee, expected_bouncer_weights);
tx_executor_test_body(state, block_context, tx, expected_bouncer_weights);
}

#[rstest]
Expand Down Expand Up @@ -256,15 +252,12 @@ fn test_bouncing(#[case] initial_bouncer_weights: BouncerWeights, #[case] n_even
tx_executor.bouncer.set_accumulated_weights(initial_bouncer_weights);

tx_executor
.execute(
&Transaction::AccountTransaction(emit_n_events_tx(
n_events,
account_address,
contract_address,
nonce_manager.next(account_address),
)),
true,
)
.execute(&Transaction::AccountTransaction(emit_n_events_tx(
n_events,
account_address,
contract_address,
nonce_manager.next(account_address),
)))
.map_err(|error| panic!("{error:?}: {error}"))
.unwrap();
}
Expand Down
3 changes: 1 addition & 2 deletions crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,9 @@ impl PyBlockExecutor {
tx: &PyAny,
optional_py_class_info: Option<PyClassInfo>,
) -> NativeBlockifierResult<Py<PyBytes>> {
let charge_fee = true;
let tx_type: String = get_py_tx_type(tx).expect(PY_TX_PARSING_ERR).to_string();
let tx: Transaction = py_tx(tx, optional_py_class_info).expect(PY_TX_PARSING_ERR);
let tx_execution_info = self.tx_executor().execute(&tx, charge_fee)?;
let tx_execution_info = self.tx_executor().execute(&tx)?;
let typed_tx_execution_info = TypedTransactionExecutionInfo::from_tx_execution_info(
&self.tx_executor().block_context,
tx_execution_info,
Expand Down

0 comments on commit 61e4974

Please sign in to comment.