Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: not typed transaction output object for block hash #260

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/block_hash/block_hash_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::data_availability::L1DataAvailabilityMode;
use crate::hash::{PoseidonHashCalculator, StarkFelt};
use crate::state::ThinStateDiff;
use crate::transaction::{
TransactionHash, TransactionOutput, TransactionSignature, TransactionVersion,
TransactionHash, TransactionOutputCommon, TransactionSignature, TransactionVersion,
};

#[cfg(test)]
Expand All @@ -17,7 +17,7 @@ mod block_hash_calculator_test;

pub struct TransactionHashingData {
pub transaction_signature: Option<TransactionSignature>,
pub transaction_output: TransactionOutput,
pub transaction_output: TransactionOutputCommon,
pub transaction_hash: TransactionHash,
pub transaction_version: TransactionVersion,
}
Expand Down Expand Up @@ -47,7 +47,7 @@ pub fn calculate_block_commitments(
let event_leaf_elements: Vec<EventLeafElement> = transactions_data
.iter()
.flat_map(|transaction_data| {
transaction_data.transaction_output.events().iter().map(|event| EventLeafElement {
transaction_data.transaction_output.events.iter().map(|event| EventLeafElement {
event: event.clone(),
transaction_hash: transaction_data.transaction_hash,
})
Expand Down
14 changes: 7 additions & 7 deletions src/block_hash/receipt_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::crypto::utils::HashChain;
use crate::hash::{starknet_keccak_hash, HashFunction, StarkFelt};
use crate::transaction::{
ExecutionResources, Fee, MessageToL1, TransactionExecutionStatus, TransactionHash,
TransactionOutput, TransactionVersion,
TransactionOutputCommon, TransactionVersion,
};

#[cfg(test)]
Expand All @@ -17,7 +17,7 @@ mod receipt_commitment_test;
#[derive(Clone)]
pub struct ReceiptElement {
pub transaction_hash: TransactionHash,
pub transaction_output: TransactionOutput,
pub transaction_output: TransactionOutputCommon,
pub transaction_version: TransactionVersion,
}

Expand Down Expand Up @@ -62,13 +62,13 @@ fn calculate_receipt_hash(
get_price_by_version(l1_data_gas_price_per_token, &receipt_element.transaction_version);
let hash_chain = HashChain::new()
.chain(&receipt_element.transaction_hash)
.chain(&receipt_element.transaction_output.actual_fee().0.into())
.chain(&calculate_messages_sent_hash(receipt_element.transaction_output.messages_sent()))
.chain(&get_revert_reason_hash(receipt_element.transaction_output.execution_status()));
.chain(&receipt_element.transaction_output.actual_fee.0.into())
.chain(&calculate_messages_sent_hash(&receipt_element.transaction_output.messages_sent))
.chain(&get_revert_reason_hash(&receipt_element.transaction_output.execution_status));
chain_execution_resources(
hash_chain,
receipt_element.transaction_output.execution_resources(),
receipt_element.transaction_output.actual_fee(),
&receipt_element.transaction_output.execution_resources,
receipt_element.transaction_output.actual_fee,
l1_data_gas_price,
l1_gas_price,
)
Expand Down
10 changes: 5 additions & 5 deletions src/block_hash/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use primitive_types::H160;
use crate::core::{ContractAddress, EthAddress};
use crate::hash::StarkFelt;
use crate::transaction::{
Builtin, ExecutionResources, Fee, InvokeTransactionOutput, L2ToL1Payload, MessageToL1,
RevertedTransactionExecutionStatus, TransactionExecutionStatus, TransactionOutput,
Builtin, ExecutionResources, Fee, L2ToL1Payload, MessageToL1,
RevertedTransactionExecutionStatus, TransactionExecutionStatus, TransactionOutputCommon,
};

pub(crate) fn get_transaction_output() -> TransactionOutput {
pub(crate) fn get_transaction_output() -> TransactionOutputCommon {
let execution_status =
TransactionExecutionStatus::Reverted(RevertedTransactionExecutionStatus {
revert_reason: "aborted".to_string(),
Expand All @@ -21,13 +21,13 @@ pub(crate) fn get_transaction_output() -> TransactionOutput {
da_l1_gas_consumed: 54,
da_l1_data_gas_consumed: 32,
};
TransactionOutput::Invoke(InvokeTransactionOutput {
TransactionOutputCommon {
actual_fee: Fee(99804),
messages_sent: vec![generate_message_to_l1(34), generate_message_to_l1(56)],
events: vec![],
execution_status,
execution_resources,
})
}
}

pub(crate) fn generate_message_to_l1(seed: u64) -> MessageToL1 {
Expand Down
22 changes: 22 additions & 0 deletions src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ impl TransactionOutput {
}
}

/// The common fields of transaction output types.
#[derive(Clone)]
pub struct TransactionOutputCommon {
pub actual_fee: Fee,
pub events: Vec<Event>,
pub execution_status: TransactionExecutionStatus,
pub execution_resources: ExecutionResources,
pub messages_sent: Vec<MessageToL1>,
}

impl From<TransactionOutput> for TransactionOutputCommon {
fn from(transaction_output: TransactionOutput) -> Self {
Self {
actual_fee: transaction_output.actual_fee(),
events: transaction_output.events().to_vec(),
execution_status: transaction_output.execution_status().to_owned(),
execution_resources: transaction_output.execution_resources().to_owned(),
messages_sent: transaction_output.messages_sent().to_owned(),
}
}
}

/// A declare V0 or V1 transaction (same schema but different version).
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
pub struct DeclareTransactionV0V1 {
Expand Down
Loading