Skip to content

Commit

Permalink
Add ExecutionResources to transaction output
Browse files Browse the repository at this point in the history
  • Loading branch information
yair-starkware committed Nov 9, 2023
1 parent 9139ec4 commit 40b06d0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::serde_utils::{BytesAsHex, PrefixedBytesAsHex};
use crate::transaction::{Transaction, TransactionHash, TransactionOutput};

/// A block.
#[derive(Debug, Default, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
pub struct Block {
pub header: BlockHeader,
pub body: BlockBody,
Expand All @@ -34,7 +34,7 @@ pub struct BlockHeader {

/// The [transactions](`crate::transaction::Transaction`) and their
/// [outputs](`crate::transaction::TransactionOutput`) in a [block](`crate::block::Block`).
#[derive(Debug, Default, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
pub struct BlockBody {
pub transactions: Vec<Transaction>,
pub transaction_outputs: Vec<TransactionOutput>,
Expand Down
57 changes: 49 additions & 8 deletions src/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{BTreeMap, HashSet};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::fmt::Display;
use std::sync::Arc;

Expand Down Expand Up @@ -32,7 +32,7 @@ pub enum Transaction {
}

/// A transaction output.
#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
pub enum TransactionOutput {
/// A declare transaction output.
Declare(DeclareTransactionOutput),
Expand Down Expand Up @@ -66,6 +66,16 @@ impl TransactionOutput {
TransactionOutput::L1Handler(output) => &output.events,
}
}

pub fn execution_resources(&self) -> &ExecutionResources {
match self {
TransactionOutput::Declare(output) => &output.execution_resources,
TransactionOutput::Deploy(output) => &output.execution_resources,
TransactionOutput::DeployAccount(output) => &output.execution_resources,
TransactionOutput::Invoke(output) => &output.execution_resources,
TransactionOutput::L1Handler(output) => &output.execution_resources,
}
}
}

/// A declare V0 or V1 transaction (same schema but different version).
Expand Down Expand Up @@ -307,54 +317,59 @@ pub struct L1HandlerTransaction {
}

/// A declare transaction output.
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
#[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct DeclareTransactionOutput {
pub actual_fee: Fee,
pub messages_sent: Vec<MessageToL1>,
pub events: Vec<Event>,
pub execution_status: TransactionExecutionStatus,
pub execution_resources: ExecutionResources,
}

/// A deploy-account transaction output.
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
#[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct DeployAccountTransactionOutput {
pub actual_fee: Fee,
pub messages_sent: Vec<MessageToL1>,
pub events: Vec<Event>,
pub contract_address: ContractAddress,
pub execution_status: TransactionExecutionStatus,
pub execution_resources: ExecutionResources,
}

/// A deploy transaction output.
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
#[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct DeployTransactionOutput {
pub actual_fee: Fee,
pub messages_sent: Vec<MessageToL1>,
pub events: Vec<Event>,
pub contract_address: ContractAddress,
pub execution_status: TransactionExecutionStatus,
pub execution_resources: ExecutionResources,
}

/// An invoke transaction output.
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
#[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct InvokeTransactionOutput {
pub actual_fee: Fee,
pub messages_sent: Vec<MessageToL1>,
pub events: Vec<Event>,
pub execution_status: TransactionExecutionStatus,
pub execution_resources: ExecutionResources,
}

/// An L1 handler transaction output.
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
#[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct L1HandlerTransactionOutput {
pub actual_fee: Fee,
pub messages_sent: Vec<MessageToL1>,
pub events: Vec<Event>,
pub execution_status: TransactionExecutionStatus,
pub execution_resources: ExecutionResources,
}

/// A transaction receipt.
#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
pub struct TransactionReceipt {
pub transaction_hash: TransactionHash,
pub block_hash: BlockHash,
Expand Down Expand Up @@ -625,3 +640,29 @@ pub struct PaymasterData(pub Vec<StarkFelt>);
/// its class hash, address salt and constructor calldata.
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
pub struct AccountDeploymentData(pub Vec<StarkFelt>);

/// The execution resources used by a transaction.
#[derive(Debug, Default, Deserialize, Serialize, Clone, Eq, PartialEq)]
pub struct ExecutionResources {
pub n_steps: u64,
pub builtin_instance_counter: BuiltinInstanceCounter,
pub n_memory_holes: u64,
}

/// A mapping from builtin instance names to their usage count.
#[derive(Debug, Deserialize, Serialize, Clone, Eq, PartialEq)]
#[serde(untagged)]
pub enum BuiltinInstanceCounter {
NonEmpty(HashMap<String, u64>),
Empty(EmptyBuiltinInstanceCounter),
}

impl Default for BuiltinInstanceCounter {
fn default() -> Self {
BuiltinInstanceCounter::Empty(EmptyBuiltinInstanceCounter {})
}
}

/// An empty builtin instance counter.
#[derive(Debug, Default, Deserialize, Serialize, Clone, Eq, PartialEq)]
pub struct EmptyBuiltinInstanceCounter {}

0 comments on commit 40b06d0

Please sign in to comment.