Skip to content

Commit

Permalink
chore(blockifier): derive serde for transaction_execution_info
Browse files Browse the repository at this point in the history
  • Loading branch information
aner-starkware authored and TzahiTaub committed Aug 21, 2024
1 parent fb793a7 commit 67b490b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 31 deletions.
1 change: 1 addition & 0 deletions crates/blockifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ workspace = true
[features]
concurrency = []
jemalloc = ["dep:tikv-jemallocator"]
transaction_serde = []
testing = ["rand", "rstest"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
10 changes: 9 additions & 1 deletion crates/blockifier/src/execution/call_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::iter::Sum;
use std::ops::Add;

use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
#[cfg(feature = "transaction_serde")]
use serde::Deserialize;
use serde::Serialize;
use starknet_api::core::{ClassHash, ContractAddress, EthAddress, PatriciaKey};
use starknet_api::state::StorageKey;
Expand All @@ -14,6 +16,7 @@ use crate::execution::entry_point::CallEntryPoint;
use crate::fee::gas_usage::get_message_segment_length;
use crate::state::cached_state::StorageEntry;

#[cfg_attr(feature = "transaction_serde", derive(Deserialize))]
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
pub struct Retdata(pub Vec<Felt>);

Expand All @@ -25,12 +28,13 @@ macro_rules! retdata {
}

#[cfg_attr(test, derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
pub struct OrderedEvent {
pub order: usize,
pub event: EventContent,
}

#[cfg_attr(feature = "transaction_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Clone)]
pub struct MessageL1CostInfo {
pub l2_to_l1_payload_lengths: Vec<usize>,
Expand All @@ -55,13 +59,15 @@ impl MessageL1CostInfo {
}

#[cfg_attr(test, derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
pub struct MessageToL1 {
pub to_address: EthAddress,
pub payload: L2ToL1Payload,
}

#[cfg_attr(test, derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
pub struct OrderedL2ToL1Message {
pub order: usize,
Expand All @@ -74,6 +80,7 @@ pub fn get_payload_lengths(l2_to_l1_messages: &[OrderedL2ToL1Message]) -> Vec<us

/// Represents the effects of executing a single entry point.
#[cfg_attr(test, derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
pub struct CallExecution {
pub retdata: Retdata,
Expand Down Expand Up @@ -162,6 +169,7 @@ impl TestExecutionSummary {
}

/// Represents the full effects of executing an entry point, including the inner calls it invoked.
#[cfg_attr(feature = "transaction_serde", derive(Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
pub struct CallInfo {
pub call: CallEntryPoint,
Expand Down
8 changes: 5 additions & 3 deletions crates/blockifier/src/execution/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::sync::Arc;

use cairo_vm::vm::runners::cairo_runner::{ExecutionResources, ResourceTracker, RunResources};
use num_traits::{Inv, Zero};
#[cfg(feature = "transaction_serde")]
use serde::Deserialize;
use serde::Serialize;
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector};
use starknet_api::deprecated_contract_class::EntryPointType;
Expand All @@ -16,9 +18,7 @@ use crate::context::{BlockContext, TransactionContext};
use crate::execution::call_info::CallInfo;
use crate::execution::common_hints::ExecutionMode;
use crate::execution::errors::{
ConstructorEntryPointExecutionError,
EntryPointExecutionError,
PreExecutionError,
ConstructorEntryPointExecutionError, EntryPointExecutionError, PreExecutionError,
};
use crate::execution::execution_utils::execute_entry_point_call;
use crate::state::state_api::State;
Expand All @@ -38,13 +38,15 @@ pub type EntryPointExecutionResult<T> = Result<T, EntryPointExecutionError>;
pub type ConstructorEntryPointExecutionResult<T> = Result<T, ConstructorEntryPointExecutionError>;

/// Represents a the type of the call (used for debugging).
#[cfg_attr(feature = "transaction_serde", derive(Deserialize))]
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq, Serialize)]
pub enum CallType {
#[default]
Call = 0,
Delegate = 1,
}
/// Represents a call to an entry point of a Starknet contract.
#[cfg_attr(feature = "transaction_serde", derive(Deserialize))]
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
pub struct CallEntryPoint {
// The class hash is not given if it can be deduced from the storage address.
Expand Down
8 changes: 4 additions & 4 deletions crates/blockifier/src/fee/actual_cost.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
#[cfg(feature = "transaction_serde")]
use serde::{Deserialize, Serialize};
use starknet_api::core::ContractAddress;
use starknet_api::transaction::Fee;

Expand All @@ -7,10 +9,7 @@ use crate::execution::call_info::CallInfo;
use crate::state::cached_state::StateChanges;
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::objects::{
GasVector,
HasRelatedFeeType,
StarknetResources,
TransactionExecutionResult,
GasVector, HasRelatedFeeType, StarknetResources, TransactionExecutionResult,
TransactionResources,
};
use crate::transaction::transaction_types::TransactionType;
Expand All @@ -36,6 +35,7 @@ struct TransactionReceiptParameters<'a, T: Iterator<Item = &'a CallInfo> + Clone

// TODO(Gilad): Use everywhere instead of passing the `actual_{fee,resources}` tuple, which often
// get passed around together.
#[cfg_attr(feature = "transaction_serde", derive(Serialize, Deserialize))]
#[derive(Default, Debug, PartialEq)]
pub struct TransactionReceipt {
pub fee: Fee,
Expand Down
3 changes: 3 additions & 0 deletions crates/blockifier/src/state/cached_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::collections::{HashMap, HashSet};

use derive_more::IntoIterator;
use indexmap::IndexMap;
#[cfg(feature = "transaction_serde")]
use serde::{Deserialize, Serialize};
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::state::StorageKey;
use starknet_types_core::felt::Felt;
Expand Down Expand Up @@ -721,6 +723,7 @@ impl From<StateMaps> for StateChanges {
}

/// Holds the number of state changes.
#[cfg_attr(feature = "transaction_serde", derive(Serialize, Deserialize))]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct StateChangesCount {
pub n_storage_updates: usize,
Expand Down
30 changes: 12 additions & 18 deletions crates/blockifier/src/transaction/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@ use std::collections::HashMap;
use cairo_vm::types::builtin_name::BuiltinName;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use num_traits::Pow;
#[cfg(feature = "transaction_serde")]
use serde::Deserialize;
use serde::Serialize;
use starknet_api::core::{ContractAddress, Nonce};
use starknet_api::data_availability::DataAvailabilityMode;
use starknet_api::transaction::{
AccountDeploymentData,
Fee,
PaymasterData,
Resource,
ResourceBounds,
ResourceBoundsMapping,
Tip,
TransactionHash,
TransactionSignature,
TransactionVersion,
AccountDeploymentData, Fee, PaymasterData, Resource, ResourceBounds, ResourceBoundsMapping,
Tip, TransactionHash, TransactionSignature, TransactionVersion,
};
use starknet_types_core::felt::Felt;
use strum_macros::EnumIter;
Expand All @@ -28,17 +22,13 @@ use crate::fee::actual_cost::TransactionReceipt;
use crate::fee::eth_gas_constants;
use crate::fee::fee_utils::{calculate_l1_gas_by_vm_usage, get_fee_by_gas_vector};
use crate::fee::gas_usage::{
get_consumed_message_to_l2_emissions_cost,
get_da_gas_cost,
get_log_message_to_l1_emissions_cost,
get_onchain_data_segment_length,
get_consumed_message_to_l2_emissions_cost, get_da_gas_cost,
get_log_message_to_l1_emissions_cost, get_onchain_data_segment_length,
};
use crate::state::cached_state::StateChangesCount;
use crate::transaction::constants;
use crate::transaction::errors::{
TransactionExecutionError,
TransactionFeeError,
TransactionPreValidationError,
TransactionExecutionError, TransactionFeeError, TransactionPreValidationError,
};
use crate::utils::{u128_from_usize, usize_from_u128};
use crate::versioned_constants::VersionedConstants;
Expand Down Expand Up @@ -149,6 +139,7 @@ pub struct DeprecatedTransactionInfo {
pub max_fee: Fee,
}

#[cfg_attr(feature = "transaction_serde", derive(Deserialize))]
#[derive(
derive_more::Add, derive_more::Sum, Clone, Copy, Debug, Default, Eq, PartialEq, Serialize,
)]
Expand Down Expand Up @@ -207,6 +198,7 @@ pub struct CommonAccountFields {
}

/// Contains the information gathered by the execution of a transaction.
#[cfg_attr(feature = "transaction_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Default, PartialEq)]
pub struct TransactionExecutionInfo {
/// Transaction validation call info; [None] for `L1Handler`.
Expand Down Expand Up @@ -265,7 +257,8 @@ impl ResourcesMapping {
}
}

/// Containes all the L2 resources consumed by a transaction
/// Contains all the L2 resources consumed by a transaction
#[cfg_attr(feature = "transaction_serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct StarknetResources {
pub calldata_length: usize,
Expand Down Expand Up @@ -432,6 +425,7 @@ impl StarknetResources {
}
}

#[cfg_attr(feature = "transaction_serde", derive(Serialize, Deserialize))]
#[derive(Default, Clone, Debug, PartialEq)]
pub struct TransactionResources {
pub starknet_resources: StarknetResources,
Expand Down
6 changes: 1 addition & 5 deletions crates/blockifier/src/transaction/objects_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ use starknet_api::core::ClassHash;
use starknet_api::{class_hash, felt};

use crate::execution::call_info::{
CallExecution,
CallInfo,
ExecutionSummary,
OrderedEvent,
TestExecutionSummary,
CallExecution, CallInfo, ExecutionSummary, OrderedEvent, TestExecutionSummary,
};
use crate::execution::entry_point::CallEntryPoint;
use crate::transaction::objects::TransactionExecutionInfo;
Expand Down

0 comments on commit 67b490b

Please sign in to comment.