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 committed Aug 11, 2024
1 parent fb793a7 commit 12a029c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
16 changes: 8 additions & 8 deletions crates/blockifier/src/execution/call_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::iter::Sum;
use std::ops::Add;

use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use serde::Serialize;
use serde::{Deserialize, Serialize};
use starknet_api::core::{ClassHash, ContractAddress, EthAddress, PatriciaKey};
use starknet_api::state::StorageKey;
use starknet_api::transaction::{EventContent, L2ToL1Payload};
Expand All @@ -14,7 +14,7 @@ use crate::execution::entry_point::CallEntryPoint;
use crate::fee::gas_usage::get_message_segment_length;
use crate::state::cached_state::StorageEntry;

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

#[macro_export]
Expand All @@ -25,13 +25,13 @@ macro_rules! retdata {
}

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

#[derive(Debug, Default, Eq, PartialEq, Clone)]
#[derive(Debug, Default, Eq, PartialEq, Clone, Serialize, Deserialize)]
pub struct MessageL1CostInfo {
pub l2_to_l1_payload_lengths: Vec<usize>,
pub message_segment_length: usize,
Expand All @@ -55,14 +55,14 @@ impl MessageL1CostInfo {
}

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

#[cfg_attr(test, derive(Clone))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
#[derive(Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct OrderedL2ToL1Message {
pub order: usize,
pub message: MessageToL1,
Expand All @@ -74,7 +74,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))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
#[derive(Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct CallExecution {
pub retdata: Retdata,
pub events: Vec<OrderedEvent>,
Expand Down Expand Up @@ -162,7 +162,7 @@ impl TestExecutionSummary {
}

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

use cairo_vm::vm::runners::cairo_runner::{ExecutionResources, ResourceTracker, RunResources};
use num_traits::{Inv, Zero};
use serde::Serialize;
use serde::{Deserialize, Serialize};
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::transaction::{Calldata, TransactionVersion};
Expand Down Expand Up @@ -38,14 +38,14 @@ pub type EntryPointExecutionResult<T> = Result<T, EntryPointExecutionError>;
pub type ConstructorEntryPointExecutionResult<T> = Result<T, ConstructorEntryPointExecutionError>;

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

Expand Down Expand Up @@ -36,7 +37,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.
#[derive(Default, Debug, PartialEq)]
#[derive(Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct TransactionReceipt {
pub fee: Fee,
pub gas: GasVector,
Expand Down
3 changes: 2 additions & 1 deletion crates/blockifier/src/state/cached_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::{HashMap, HashSet};

use derive_more::IntoIterator;
use indexmap::IndexMap;
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,7 +722,7 @@ impl From<StateMaps> for StateChanges {
}

/// Holds the number of state changes.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct StateChangesCount {
pub n_storage_updates: usize,
pub n_class_hash_updates: usize,
Expand Down
19 changes: 14 additions & 5 deletions crates/blockifier/src/transaction/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use cairo_vm::types::builtin_name::BuiltinName;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use num_traits::Pow;
use serde::Serialize;
use serde::{Deserialize, Serialize};
use starknet_api::core::{ContractAddress, Nonce};
use starknet_api::data_availability::DataAvailabilityMode;
use starknet_api::transaction::{
Expand Down Expand Up @@ -150,7 +150,16 @@ pub struct DeprecatedTransactionInfo {
}

#[derive(
derive_more::Add, derive_more::Sum, Clone, Copy, Debug, Default, Eq, PartialEq, Serialize,
derive_more::Add,
derive_more::Sum,
Clone,
Copy,
Debug,
Default,
Eq,
PartialEq,
Serialize,
Deserialize,
)]
pub struct GasVector {
pub l1_gas: u128,
Expand Down Expand Up @@ -207,7 +216,7 @@ pub struct CommonAccountFields {
}

/// Contains the information gathered by the execution of a transaction.
#[derive(Debug, Default, PartialEq)]
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct TransactionExecutionInfo {
/// Transaction validation call info; [None] for `L1Handler`.
pub validate_call_info: Option<CallInfo>,
Expand Down Expand Up @@ -266,7 +275,7 @@ impl ResourcesMapping {
}

/// Containes all the L2 resources consumed by a transaction
#[derive(Clone, Debug, Default, PartialEq)]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct StarknetResources {
pub calldata_length: usize,
pub state_changes_for_fee: StateChangesCount,
Expand Down Expand Up @@ -432,7 +441,7 @@ impl StarknetResources {
}
}

#[derive(Default, Clone, Debug, PartialEq)]
#[derive(Default, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct TransactionResources {
pub starknet_resources: StarknetResources,
pub vm_resources: ExecutionResources,
Expand Down

0 comments on commit 12a029c

Please sign in to comment.