diff --git a/crates/blockifier/src/blockifier/stateful_validator.rs b/crates/blockifier/src/blockifier/stateful_validator.rs index 3c6a8606dd3..1353e26e0a3 100644 --- a/crates/blockifier/src/blockifier/stateful_validator.rs +++ b/crates/blockifier/src/blockifier/stateful_validator.rs @@ -56,12 +56,13 @@ impl StatefulValidator { &mut self, tx: AccountTransaction, skip_validate: bool, + charge_fee: bool, ) -> StatefulValidatorResult<()> { // Deploy account transactions should be fully executed, since the constructor must run // before `__validate_deploy__`. The execution already includes all necessary validations, // so they are skipped here. if let AccountTransaction::DeployAccount(_) = tx { - self.execute(tx)?; + self.execute(tx, charge_fee)?; return Ok(()); } @@ -83,8 +84,8 @@ impl StatefulValidator { Ok(()) } - fn execute(&mut self, tx: AccountTransaction) -> StatefulValidatorResult<()> { - self.tx_executor.execute(&Transaction::AccountTransaction(tx))?; + fn execute(&mut self, tx: AccountTransaction, charge_fee: bool) -> StatefulValidatorResult<()> { + self.tx_executor.execute(&Transaction::AccountTransaction(tx), charge_fee)?; Ok(()) } diff --git a/crates/blockifier/src/blockifier/stateful_validator_test.rs b/crates/blockifier/src/blockifier/stateful_validator_test.rs index dc1fd08cc38..6d0bd7d57ae 100644 --- a/crates/blockifier/src/blockifier/stateful_validator_test.rs +++ b/crates/blockifier/src/blockifier/stateful_validator_test.rs @@ -69,7 +69,7 @@ fn test_transaction_validator( // Test the stateful validator. let mut stateful_validator = StatefulValidator::create(state, block_context); - let result = stateful_validator.perform_validations(tx, false); + let result = stateful_validator.perform_validations(tx, false, true); assert!(result.is_ok(), "Validation failed: {:?}", result.unwrap_err()); } @@ -92,6 +92,6 @@ fn test_transaction_validator_skip_validate() { let mut stateful_validator = StatefulValidator::create(state, block_context); // The transaction validations should be skipped and the function should return Ok. - let result = stateful_validator.perform_validations(tx, true); + let result = stateful_validator.perform_validations(tx, true, true); assert_matches!(result, Ok(())); } diff --git a/crates/blockifier/src/blockifier/transaction_executor.rs b/crates/blockifier/src/blockifier/transaction_executor.rs index 14c13ed9324..8d6d54e0420 100644 --- a/crates/blockifier/src/blockifier/transaction_executor.rs +++ b/crates/blockifier/src/blockifier/transaction_executor.rs @@ -86,13 +86,14 @@ impl TransactionExecutor { pub fn execute( &mut self, tx: &Transaction, + charge_fee: bool, ) -> TransactionExecutorResult { let mut transactional_state = TransactionalState::create_transactional( self.block_state.as_mut().expect(BLOCK_STATE_ACCESS_ERR), ); // Executing a single transaction cannot be done in a concurrent mode. let execution_flags = - ExecutionFlags { charge_fee: true, validate: true, concurrency_mode: false }; + ExecutionFlags { charge_fee, validate: true, concurrency_mode: false }; let tx_execution_result = tx.execute_raw(&mut transactional_state, &self.block_context, execution_flags); match tx_execution_result { @@ -118,10 +119,11 @@ impl TransactionExecutor { pub fn execute_txs_sequentially( &mut self, txs: &[Transaction], + charge_fee: bool, ) -> Vec> { let mut results = Vec::new(); for tx in txs { - match self.execute(tx) { + match self.execute(tx, charge_fee) { Ok(tx_execution_info) => results.push(Ok(tx_execution_info)), Err(TransactionExecutorError::BlockFull) => break, Err(error) => results.push(Err(error)), @@ -179,10 +181,11 @@ impl TransactionExecutor { pub fn execute_txs( &mut self, txs: &[Transaction], + charge_fee: bool, ) -> Vec> { if !self.config.concurrency_config.enabled { log::debug!("Executing transactions sequentially."); - self.execute_txs_sequentially(txs) + self.execute_txs_sequentially(txs, charge_fee) } else { log::debug!("Executing transactions concurrently."); let chunk_size = self.config.concurrency_config.chunk_size; diff --git a/crates/blockifier/src/blockifier/transaction_executor_test.rs b/crates/blockifier/src/blockifier/transaction_executor_test.rs index b3f649d5c4f..e87855278ea 100644 --- a/crates/blockifier/src/blockifier/transaction_executor_test.rs +++ b/crates/blockifier/src/blockifier/transaction_executor_test.rs @@ -52,7 +52,7 @@ fn tx_executor_test_body( // 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).unwrap(); + let _tx_execution_info = tx_executor.execute(&tx, true).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!( @@ -269,7 +269,7 @@ fn test_bouncing(#[case] initial_bouncer_weights: BouncerWeights, #[case] n_even account_address, contract_address, nonce_manager.next(account_address), - ))) + )), true) .map_err(|error| panic!("{error:?}: {error}")) .unwrap(); } @@ -305,7 +305,7 @@ fn test_execute_txs_bouncing() { .collect(); // Run. - let results = tx_executor.execute_txs(&txs); + let results = tx_executor.execute_txs(&txs, true); // Check execution results. let expected_offset = 3; @@ -333,12 +333,12 @@ fn test_execute_txs_bouncing() { // Check idempotency: excess transactions should not be added. let remaining_txs = &txs[expected_offset..]; - let remaining_tx_results = tx_executor.execute_txs(remaining_txs); + let remaining_tx_results = tx_executor.execute_txs(remaining_txs, true); assert_eq!(remaining_tx_results.len(), 0); // Reset the bouncer and add the remaining transactions. tx_executor.bouncer = Bouncer::new(tx_executor.block_context.bouncer_config.clone()); - let remaining_tx_results = tx_executor.execute_txs(remaining_txs); + let remaining_tx_results = tx_executor.execute_txs(remaining_txs, true); assert_eq!(remaining_tx_results.len(), 2); assert!(remaining_tx_results[0].is_ok()); diff --git a/crates/blockifier/src/test_utils/transfers_generator.rs b/crates/blockifier/src/test_utils/transfers_generator.rs index 3d3a6a911d3..2f638ab17a0 100644 --- a/crates/blockifier/src/test_utils/transfers_generator.rs +++ b/crates/blockifier/src/test_utils/transfers_generator.rs @@ -155,7 +155,7 @@ impl TransfersGenerator { let account_tx = self.generate_transfer(sender_address, recipient_address); txs.push(Transaction::AccountTransaction(account_tx)); } - let results = self.executor.execute_txs(&txs); + let results = self.executor.execute_txs(&txs, true); assert_eq!(results.len(), self.config.n_txs); for result in results { assert!(!result.unwrap().is_reverted()); diff --git a/crates/gateway/src/stateful_transaction_validator.rs b/crates/gateway/src/stateful_transaction_validator.rs index 6e140f1cf52..4468aa92503 100644 --- a/crates/gateway/src/stateful_transaction_validator.rs +++ b/crates/gateway/src/stateful_transaction_validator.rs @@ -52,7 +52,7 @@ impl StatefulTransactionValidatorTrait for BlockifierStatefulValidator { account_tx: AccountTransaction, skip_validate: bool, ) -> BlockifierStatefulValidatorResult<()> { - self.perform_validations(account_tx, skip_validate) + self.perform_validations(account_tx, skip_validate, true) } fn get_nonce( diff --git a/crates/native_blockifier/src/py_block_executor.rs b/crates/native_blockifier/src/py_block_executor.rs index f1f953d8b9d..5a29d72c09c 100644 --- a/crates/native_blockifier/src/py_block_executor.rs +++ b/crates/native_blockifier/src/py_block_executor.rs @@ -159,14 +159,15 @@ impl PyBlockExecutor { self.tx_executor = None; } - #[pyo3(signature = (tx, optional_py_class_info))] + #[pyo3(signature = (tx, charge_fee, optional_py_class_info))] pub fn execute( &mut self, tx: &PyAny, + charge_fee: bool, optional_py_class_info: Option, ) -> NativeBlockifierResult> { let tx: Transaction = py_tx(tx, optional_py_class_info).expect(PY_TX_PARSING_ERR); - let tx_execution_info = self.tx_executor().execute(&tx)?; + let tx_execution_info = self.tx_executor().execute(&tx, charge_fee)?; let thin_tx_execution_info = ThinTransactionExecutionInfo::from_tx_execution_info( &self.tx_executor().block_context, tx_execution_info, @@ -180,10 +181,11 @@ impl PyBlockExecutor { /// Executes the given transactions on the Blockifier state. /// Stops if and when there is no more room in the block, and returns the executed transactions' /// results as a PyList of (success (bool), serialized result (bytes)) tuples. - #[pyo3(signature = (txs_with_class_infos))] + #[pyo3(signature = (txs_with_class_infos, charge_fee))] pub fn execute_txs( &mut self, txs_with_class_infos: Vec<(&PyAny, Option)>, + charge_fee: bool, ) -> Py { // Parse Py transactions. let txs: Vec = txs_with_class_infos @@ -195,7 +197,7 @@ impl PyBlockExecutor { // Run. let results = - Python::with_gil(|py| py.allow_threads(|| self.tx_executor().execute_txs(&txs))); + Python::with_gil(|py| py.allow_threads(|| self.tx_executor().execute_txs(&txs, charge_fee))); // Process results. // TODO(Yoni, 15/5/2024): serialize concurrently. diff --git a/crates/native_blockifier/src/py_validator.rs b/crates/native_blockifier/src/py_validator.rs index 8398e48c1a5..4031186a10c 100644 --- a/crates/native_blockifier/src/py_validator.rs +++ b/crates/native_blockifier/src/py_validator.rs @@ -73,7 +73,7 @@ impl PyValidator { // processed. let skip_validate = self .skip_validate_due_to_unprocessed_deploy_account(&account_tx, deploy_account_tx_hash)?; - self.stateful_validator.perform_validations(account_tx, skip_validate)?; + self.stateful_validator.perform_validations(account_tx, skip_validate, true)?; Ok(()) } diff --git a/crates/sequencing/papyrus_consensus/src/simulation_network_receiver.rs b/crates/sequencing/papyrus_consensus/src/simulation_network_receiver.rs index bf784103da1..c8e62cf0365 100644 --- a/crates/sequencing/papyrus_consensus/src/simulation_network_receiver.rs +++ b/crates/sequencing/papyrus_consensus/src/simulation_network_receiver.rs @@ -43,6 +43,8 @@ impl NetworkReceiver where ReceiverT: Stream, ReportSender)>, { + // TODO(Meshi): remove this before merging this pr. + #[allow(dead_code)] pub fn new( receiver: ReceiverT, cache_size: usize,