Skip to content

Commit

Permalink
katana: add flag to skip fee check in stateful validator
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Aug 26, 2024
1 parent a8f6619 commit 6860955
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
24 changes: 20 additions & 4 deletions crates/blockifier/src/blockifier/stateful_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,10 +50,26 @@ impl<S: StateReader> StatefulValidator<S> {
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,
Expand All @@ -64,7 +80,7 @@ impl<S: StateReader> StatefulValidator<S> {
}

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.
Expand Down Expand Up @@ -101,14 +117,14 @@ impl<S: StateReader> StatefulValidator<S> {
&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,
)?;

Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/blockifier/stateful_validator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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(()));
}

0 comments on commit 6860955

Please sign in to comment.