diff --git a/crates/blockifier/src/blockifier/stateful_validator.rs b/crates/blockifier/src/blockifier/stateful_validator.rs index 25bbbe7f27..3d529ef11d 100644 --- a/crates/blockifier/src/blockifier/stateful_validator.rs +++ b/crates/blockifier/src/blockifier/stateful_validator.rs @@ -14,7 +14,7 @@ use crate::fee::actual_cost::TransactionReceipt; use crate::fee::fee_checks::PostValidationReport; use crate::state::cached_state::CachedState; use crate::state::errors::StateError; -use crate::state::state_api::StateReader; +use crate::state::state_api::{State, StateReader}; use crate::transaction::account_transaction::AccountTransaction; use crate::transaction::errors::{TransactionExecutionError, TransactionPreValidationError}; use crate::transaction::transaction_execution::Transaction; @@ -50,10 +50,26 @@ impl StatefulValidator { Self { tx_executor } } + /// Perform validations on an account transaction. + /// + /// # Arguments + /// + /// * `tx` - The account transaction to validate. + /// * `skip_validate` - If true, skip the account validation. + /// * `skip_fee_check` - If true, ignore any fee related checks on the transaction and account + /// balance. + /// + /// NOTE: + /// + /// We add a flag specifically for avoiding fee checks to allow the pool validator + /// in Katana to run in 'fee disabled' mode. Basically, to adapt StatefulValidator to Katana's + /// execution flag abstraction (Katana's config that allows running in fee-disabled or + /// no-validation mode). pub fn perform_validations( &mut self, tx: AccountTransaction, skip_validate: bool, + skip_fee_check: bool, ) -> StatefulValidatorResult<()> { // Deploy account transactions should be fully executed, since the constructor must run // before `__validate_deploy__`. The execution already includes all necessary validations, @@ -64,7 +80,7 @@ impl StatefulValidator { } let tx_context = self.tx_executor.block_context.to_tx_context(&tx); - self.perform_pre_validation_stage(&tx, &tx_context)?; + self.perform_pre_validation_stage(&tx, &tx_context, !skip_fee_check)?; if !skip_validate { // `__validate__` call. @@ -101,14 +117,14 @@ impl StatefulValidator { &mut self, tx: &AccountTransaction, tx_context: &TransactionContext, + fee_check: bool, ) -> StatefulValidatorResult<()> { let strict_nonce_check = false; // Run pre-validation in charge fee mode to perform fee and balance related checks. - let charge_fee = true; tx.perform_pre_validation_stage( self.tx_executor.block_state.as_mut().expect(BLOCK_STATE_ACCESS_ERR), tx_context, - charge_fee, + fee_check, strict_nonce_check, )?; diff --git a/crates/blockifier/src/blockifier/stateful_validator_test.rs b/crates/blockifier/src/blockifier/stateful_validator_test.rs index 0467ab49cc..27402aa593 100644 --- a/crates/blockifier/src/blockifier/stateful_validator_test.rs +++ b/crates/blockifier/src/blockifier/stateful_validator_test.rs @@ -66,7 +66,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, false); assert!(result.is_ok(), "Validation failed: {:?}", result.unwrap_err()); } @@ -89,6 +89,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, false); assert_matches!(result, Ok(())); }