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 5c2652a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/blockifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ workspace = true
concurrency = []
jemalloc = ["dep:tikv-jemallocator"]
testing = ["rand", "rstest"]
transaction_serde = []

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
9 changes: 9 additions & 0 deletions 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,14 @@ 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 +60,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 +81,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 +170,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
4 changes: 4 additions & 0 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 Down Expand Up @@ -38,13 +40,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
3 changes: 3 additions & 0 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 Down Expand Up @@ -36,6 +38,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
8 changes: 7 additions & 1 deletion crates/blockifier/src/transaction/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ 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;
Expand Down Expand Up @@ -149,6 +151,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 +210,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 +269,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 +437,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

0 comments on commit 5c2652a

Please sign in to comment.