Skip to content

Commit

Permalink
chore(blockifier): derive serde for transaction_execution_info (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
aner-starkware authored Aug 29, 2024
1 parent 18ac072 commit 6f89ece
Show file tree
Hide file tree
Showing 6 changed files with 17 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
7 changes: 7 additions & 0 deletions crates/blockifier/src/execution/call_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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(serde::Deserialize))]
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
pub struct Retdata(pub Vec<Felt>);

Expand All @@ -25,12 +26,14 @@ macro_rules! retdata {
}

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

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

#[cfg_attr(test, derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::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(serde::Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
pub struct OrderedL2ToL1Message {
pub order: usize,
Expand All @@ -74,6 +79,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(serde::Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
pub struct CallExecution {
pub retdata: Retdata,
Expand Down Expand Up @@ -162,6 +168,7 @@ impl TestExecutionSummary {
}

/// Represents the full effects of executing an entry point, including the inner calls it invoked.
#[cfg_attr(feature = "transaction_serde", derive(serde::Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
pub struct CallInfo {
pub call: CallEntryPoint,
Expand Down
2 changes: 2 additions & 0 deletions crates/blockifier/src/execution/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(serde::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(serde::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
1 change: 1 addition & 0 deletions crates/blockifier/src/fee/actual_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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(serde::Serialize, serde::Deserialize))]
#[derive(Default, Debug, PartialEq)]
pub struct TransactionReceipt {
pub fee: Fee,
Expand Down
1 change: 1 addition & 0 deletions crates/blockifier/src/state/cached_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ impl From<StateMaps> for StateChanges {
}

/// Holds the number of state changes.
#[cfg_attr(feature = "transaction_serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct StateChangesCount {
pub n_storage_updates: usize,
Expand Down
6 changes: 5 additions & 1 deletion crates/blockifier/src/transaction/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub struct DeprecatedTransactionInfo {
pub max_fee: Fee,
}

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

/// Contains the information gathered by the execution of a transaction.
#[cfg_attr(feature = "transaction_serde", derive(Serialize, serde::Deserialize))]
#[derive(Debug, Default, PartialEq)]
pub struct TransactionExecutionInfo {
/// Transaction validation call info; [None] for `L1Handler`.
Expand Down Expand Up @@ -269,7 +271,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, serde::Deserialize))]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct StarknetResources {
pub calldata_length: usize,
Expand Down Expand Up @@ -436,6 +439,7 @@ impl StarknetResources {
}
}

#[cfg_attr(feature = "transaction_serde", derive(Serialize, serde::Deserialize))]
#[derive(Default, Clone, Debug, PartialEq)]
pub struct TransactionResources {
pub starknet_resources: StarknetResources,
Expand Down

0 comments on commit 6f89ece

Please sign in to comment.