Skip to content

Commit

Permalink
chore(blockifier,starknet_api): move l1handler to executable tx
Browse files Browse the repository at this point in the history
  • Loading branch information
yair-starkware committed Nov 3, 2024
1 parent 1167e77 commit 46fb6bd
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use assert_matches::assert_matches;
use pretty_assertions::assert_eq;
use rstest::rstest;
use starknet_api::executable_transaction::L1HandlerTransaction;
use starknet_api::test_utils::NonceManager;
use starknet_api::transaction::{Fee, TransactionVersion};
use starknet_api::{declare_tx_args, deploy_account_tx_args, felt, invoke_tx_args, nonce};
Expand All @@ -20,6 +21,7 @@ use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::declare::declare_tx;
use crate::test_utils::deploy_account::deploy_account_tx;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::struct_impls::CreateForTesting;
use crate::test_utils::{
create_calldata,
maybe_dummy_block_hash_and_number,
Expand All @@ -38,7 +40,6 @@ use crate::transaction::test_utils::{
TestInitData,
};
use crate::transaction::transaction_execution::Transaction;
use crate::transaction::transactions::L1HandlerTransaction;
fn tx_executor_test_body<S: StateReader>(
state: CachedState<S>,
block_context: BlockContext,
Expand Down
10 changes: 7 additions & 3 deletions crates/blockifier/src/test_utils/struct_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use serde_json::Value;
use starknet_api::block::{BlockNumber, BlockTimestamp, NonzeroGasPrice};
use starknet_api::core::{ChainId, ClassHash, ContractAddress, Nonce};
use starknet_api::executable_transaction::L1HandlerTransaction;
use starknet_api::transaction::{Fee, TransactionHash, TransactionVersion};
use starknet_api::{calldata, contract_address};
use starknet_types_core::felt::Felt;
Expand Down Expand Up @@ -35,7 +36,6 @@ use crate::test_utils::{
TEST_SEQUENCER_ADDRESS,
};
use crate::transaction::objects::{DeprecatedTransactionInfo, TransactionInfo};
use crate::transaction::transactions::L1HandlerTransaction;
use crate::versioned_constants::{
GasCosts,
OsConstants,
Expand Down Expand Up @@ -224,8 +224,12 @@ impl ContractClassV1 {
}
}

impl L1HandlerTransaction {
pub fn create_for_testing(l1_fee: Fee, contract_address: ContractAddress) -> Self {
pub trait CreateForTesting {
fn create_for_testing(l1_fee: Fee, contract_address: ContractAddress) -> Self;
}

impl CreateForTesting for L1HandlerTransaction {
fn create_for_testing(l1_fee: Fee, contract_address: ContractAddress) -> Self {
let calldata = calldata![
Felt::from(0x123), // from_address.
Felt::from(0x876), // key.
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/transaction_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;

use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use starknet_api::core::{calculate_contract_address, ContractAddress, Nonce};
use starknet_api::executable_transaction::L1HandlerTransaction;
use starknet_api::transaction::{Fee, Transaction as StarknetApiTransaction, TransactionHash};

use crate::bouncer::verify_tx_weights_within_max_capacity;
Expand All @@ -27,7 +28,6 @@ use crate::transaction::transactions::{
ExecutableTransaction,
ExecutionFlags,
InvokeTransaction,
L1HandlerTransaction,
};

// TODO: Move into transaction.rs, makes more sense to be defined there.
Expand Down
15 changes: 1 addition & 14 deletions crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::sync::Arc;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::executable_transaction::L1HandlerTransaction;
use starknet_api::transaction::{
AccountDeploymentData,
Calldata,
Expand Down Expand Up @@ -557,20 +558,6 @@ impl TransactionInfoCreator for InvokeTransaction {
}
}

#[derive(Clone, Debug)]
pub struct L1HandlerTransaction {
pub tx: starknet_api::transaction::L1HandlerTransaction,
pub tx_hash: TransactionHash,
pub paid_fee_on_l1: Fee,
}

impl L1HandlerTransaction {
pub fn payload_size(&self) -> usize {
// The calldata includes the "from" field, which is not a part of the payload.
self.tx.calldata.0.len() - 1
}
}

impl HasRelatedFeeType for L1HandlerTransaction {
fn version(&self) -> TransactionVersion {
self.tx.version
Expand Down
1 change: 1 addition & 0 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ use crate::test_utils::dict_state_reader::DictStateReader;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::invoke::invoke_tx;
use crate::test_utils::prices::Prices;
use crate::test_utils::struct_impls::CreateForTesting;
use crate::test_utils::{
create_calldata,
create_trivial_calldata,
Expand Down
2 changes: 1 addition & 1 deletion crates/native_blockifier/src/py_l1_handler.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::sync::Arc;

use blockifier::abi::constants;
use blockifier::transaction::transactions::L1HandlerTransaction;
use pyo3::prelude::*;
use starknet_api::core::{ContractAddress, EntryPointSelector, Nonce};
use starknet_api::executable_transaction::L1HandlerTransaction;
use starknet_api::transaction::{Calldata, Fee, TransactionHash};

use crate::errors::{NativeBlockifierInputError, NativeBlockifierResult};
Expand Down
15 changes: 15 additions & 0 deletions crates/starknet_api/src/executable_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::transaction::{
AllResourceBounds,
Calldata,
ContractAddressSalt,
Fee,
PaymasterData,
Tip,
TransactionHash,
Expand Down Expand Up @@ -292,3 +293,17 @@ impl InvokeTransaction {
Self::create(invoke_tx, chain_id)
}
}

#[derive(Clone, Debug)]
pub struct L1HandlerTransaction {
pub tx: crate::transaction::L1HandlerTransaction,
pub tx_hash: TransactionHash,
pub paid_fee_on_l1: Fee,
}

impl L1HandlerTransaction {
pub fn payload_size(&self) -> usize {
// The calldata includes the "from" field, which is not a part of the payload.
self.tx.calldata.0.len() - 1
}
}

0 comments on commit 46fb6bd

Please sign in to comment.