From 5c2652a361c82138c14c2bd76fe2b0decdcbc3a9 Mon Sep 17 00:00:00 2001 From: Aner Ben Efraim Date: Sun, 11 Aug 2024 09:43:36 +0300 Subject: [PATCH] chore(blockifier): derive serde for transaction_execution_info --- crates/blockifier/Cargo.toml | 1 + crates/blockifier/src/execution/call_info.rs | 9 +++++++++ crates/blockifier/src/execution/entry_point.rs | 4 ++++ crates/blockifier/src/fee/actual_cost.rs | 3 +++ crates/blockifier/src/state/cached_state.rs | 3 +++ crates/blockifier/src/transaction/objects.rs | 8 +++++++- 6 files changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/blockifier/Cargo.toml b/crates/blockifier/Cargo.toml index 7536f0e449..b40722954f 100644 --- a/crates/blockifier/Cargo.toml +++ b/crates/blockifier/Cargo.toml @@ -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 diff --git a/crates/blockifier/src/execution/call_info.rs b/crates/blockifier/src/execution/call_info.rs index 1efef68115..25bca09631 100644 --- a/crates/blockifier/src/execution/call_info.rs +++ b/crates/blockifier/src/execution/call_info.rs @@ -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; @@ -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); @@ -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, @@ -55,6 +60,7 @@ 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, @@ -62,6 +68,7 @@ pub struct MessageToL1 { } #[cfg_attr(test, derive(Clone))] +#[cfg_attr(feature = "transaction_serde", derive(Deserialize))] #[derive(Debug, Default, Eq, PartialEq, Serialize)] pub struct OrderedL2ToL1Message { pub order: usize, @@ -74,6 +81,7 @@ pub fn get_payload_lengths(l2_to_l1_messages: &[OrderedL2ToL1Message]) -> Vec = Result; pub type ConstructorEntryPointExecutionResult = Result; /// 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] @@ -45,6 +48,7 @@ pub enum CallType { 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. diff --git a/crates/blockifier/src/fee/actual_cost.rs b/crates/blockifier/src/fee/actual_cost.rs index 36967058b8..26f0ae1947 100644 --- a/crates/blockifier/src/fee/actual_cost.rs +++ b/crates/blockifier/src/fee/actual_cost.rs @@ -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; @@ -36,6 +38,7 @@ struct TransactionReceiptParameters<'a, T: Iterator + 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, diff --git a/crates/blockifier/src/state/cached_state.rs b/crates/blockifier/src/state/cached_state.rs index 93201f3456..a3c0e57a3f 100644 --- a/crates/blockifier/src/state/cached_state.rs +++ b/crates/blockifier/src/state/cached_state.rs @@ -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; @@ -721,6 +723,7 @@ impl From 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, diff --git a/crates/blockifier/src/transaction/objects.rs b/crates/blockifier/src/transaction/objects.rs index db844eb075..274fd1a406 100644 --- a/crates/blockifier/src/transaction/objects.rs +++ b/crates/blockifier/src/transaction/objects.rs @@ -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; @@ -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, )] @@ -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`. @@ -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, @@ -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,