Skip to content

Commit

Permalink
refactor(blockifier): delete transaction_utils (#899)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoni-Starkware committed Sep 19, 2024
1 parent 2ab9918 commit d095a9d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 48 deletions.
4 changes: 4 additions & 0 deletions crates/blockifier/src/execution/execution_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ pub fn execute_entry_point_call(
}
}

pub fn update_remaining_gas(remaining_gas: &mut u64, call_info: &CallInfo) {
*remaining_gas -= call_info.execution.gas_consumed;
}

pub fn read_execution_retdata(
runner: &CairoRunner,
retdata_size: MaybeRelocatable,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/execution/syscalls/hint_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::execution::execution_utils::{
felt_from_ptr,
felt_range_from_ptr,
max_fee_for_execution_info,
update_remaining_gas,
write_maybe_relocatable,
ReadOnlySegment,
ReadOnlySegments,
Expand Down Expand Up @@ -73,7 +74,6 @@ use crate::execution::syscalls::{
use crate::state::errors::StateError;
use crate::state::state_api::State;
use crate::transaction::objects::{CurrentTransactionInfo, TransactionInfo};
use crate::transaction::transaction_utils::update_remaining_gas;

pub type SyscallCounter = HashMap<SyscallSelector, usize>;

Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/execution/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ use crate::execution::entry_point::{CallEntryPoint, CallType, ConstructorContext
use crate::execution::execution_utils::{
execute_deployment,
felt_from_ptr,
update_remaining_gas,
write_felt,
write_maybe_relocatable,
ReadOnlySegment,
};
use crate::execution::syscalls::hint_processor::{INVALID_INPUT_LENGTH_ERROR, OUT_OF_GAS_ERROR};
use crate::transaction::transaction_utils::update_remaining_gas;
use crate::versioned_constants::{EventLimits, VersionedConstants};

pub mod hint_processor;
Expand Down
1 change: 0 additions & 1 deletion crates/blockifier/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ pub mod objects;
pub mod test_utils;
pub mod transaction_execution;
pub mod transaction_types;
pub mod transaction_utils;
pub mod transactions;
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::context::{BlockContext, TransactionContext};
use crate::execution::call_info::{CallInfo, Retdata};
use crate::execution::contract_class::ContractClass;
use crate::execution::entry_point::{CallEntryPoint, CallType, EntryPointExecutionContext};
use crate::execution::execution_utils::update_remaining_gas;
use crate::fee::fee_checks::{FeeCheckReportFields, PostExecutionReport};
use crate::fee::fee_utils::{
get_fee_by_gas_vector,
Expand Down Expand Up @@ -46,7 +47,6 @@ use crate::transaction::objects::{
TransactionPreValidationResult,
};
use crate::transaction::transaction_types::TransactionType;
use crate::transaction::transaction_utils::update_remaining_gas;
use crate::transaction::transactions::{
DeclareTransaction,
DeployAccountTransaction,
Expand Down
40 changes: 0 additions & 40 deletions crates/blockifier/src/transaction/transaction_utils.rs

This file was deleted.

25 changes: 21 additions & 4 deletions crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::execution::entry_point::{
ConstructorContext,
EntryPointExecutionContext,
};
use crate::execution::execution_utils::execute_deployment;
use crate::execution::execution_utils::{execute_deployment, update_remaining_gas};
use crate::state::cached_state::TransactionalState;
use crate::state::errors::StateError;
use crate::state::state_api::{State, UpdatableState};
Expand All @@ -41,8 +41,6 @@ use crate::transaction::objects::{
TransactionInfo,
TransactionInfoCreator,
};
use crate::transaction::transaction_utils::{update_remaining_gas, verify_contract_class_version};

#[cfg(test)]
#[path = "transactions_test.rs"]
mod test;
Expand Down Expand Up @@ -153,7 +151,26 @@ impl DeclareTransaction {
only_query: bool,
) -> TransactionExecutionResult<Self> {
let declare_version = declare_tx.version();
verify_contract_class_version(&class_info.contract_class(), declare_version)?;
// Verify contract class version.
match &class_info.contract_class() {
// TODO: Make TransactionVersion an enum and use match here.
ContractClass::V0(_) => {
if declare_version > TransactionVersion::ONE {
Err(TransactionExecutionError::ContractClassVersionMismatch {
declare_version,
cairo_version: 0,
})?
}
}
ContractClass::V1(_) => {
if declare_version <= TransactionVersion::ONE {
Err(TransactionExecutionError::ContractClassVersionMismatch {
declare_version,
cairo_version: 1,
})?
}
}
}
Ok(Self { tx: declare_tx, tx_hash, class_info, only_query })
}

Expand Down

0 comments on commit d095a9d

Please sign in to comment.