diff --git a/crates/gateway/src/gateway.rs b/crates/gateway/src/gateway.rs index ffd752bfb60..e09a85a05ef 100644 --- a/crates/gateway/src/gateway.rs +++ b/crates/gateway/src/gateway.rs @@ -141,9 +141,9 @@ fn process_tx( // TODO(Arni): Add the Sierra and the Casm to the mempool input. Ok(MempoolInput { - tx: external_tx_to_thin_tx(&tx, validate_info.tx_hash, validate_info.sender_address), + tx: external_tx_to_thin_tx(&tx, executable_tx.tx_hash(), executable_tx.contract_address()), account: Account { - sender_address: validate_info.sender_address, + sender_address: executable_tx.contract_address(), state: AccountState { nonce: validate_info.account_nonce }, }, }) diff --git a/crates/gateway/src/stateful_transaction_validator.rs b/crates/gateway/src/stateful_transaction_validator.rs index 72e69fdc12a..a5dc800898d 100644 --- a/crates/gateway/src/stateful_transaction_validator.rs +++ b/crates/gateway/src/stateful_transaction_validator.rs @@ -15,14 +15,13 @@ use starknet_api::executable_transaction::{ InvokeTransaction as ExecutableInvokeTransaction, Transaction as ExecutableTransaction, }; -use starknet_api::transaction::TransactionHash; use starknet_types_core::felt::Felt; use tracing::error; use crate::config::StatefulTransactionValidatorConfig; use crate::errors::{GatewaySpecError, StatefulTransactionValidatorResult}; use crate::state_reader::{MempoolStateReader, StateReaderFactory}; -use crate::utils::{executable_transaction_to_account_tx, get_sender_address}; +use crate::utils::executable_transaction_to_account_tx; #[cfg(test)] #[path = "stateful_transaction_validator_test.rs"] @@ -72,18 +71,17 @@ impl StatefulTransactionValidator { executable_tx: &ExecutableTransaction, mut validator: V, ) -> StatefulTransactionValidatorResult { - let account_tx = executable_transaction_to_account_tx(executable_tx)?; - let tx_hash = account_tx.tx_hash(); - let sender_address = get_sender_address(&account_tx); + let sender_address = executable_tx.contract_address(); let account_nonce = validator.get_nonce(sender_address).map_err(|e| { error!("Failed to get nonce for sender address {}: {}", sender_address, e); GatewaySpecError::UnexpectedError { data: "Internal server error.".to_owned() } })?; let skip_validate = skip_stateful_validations(executable_tx, account_nonce); + let account_tx = executable_transaction_to_account_tx(executable_tx)?; validator .validate(account_tx, skip_validate) .map_err(|err| GatewaySpecError::ValidationFailure { data: err.to_string() })?; - Ok(ValidateInfo { tx_hash, sender_address, account_nonce }) + Ok(ValidateInfo { account_nonce }) } pub fn instantiate_validator( @@ -143,7 +141,5 @@ pub fn get_latest_block_info( /// [`MempoolInput`](starknet_mempool_types::mempool_types::MempoolInput). #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct ValidateInfo { - pub tx_hash: TransactionHash, - pub sender_address: ContractAddress, pub account_nonce: Nonce, } diff --git a/crates/gateway/src/stateful_transaction_validator_test.rs b/crates/gateway/src/stateful_transaction_validator_test.rs index 07918ed1d6c..9cb2c6a3401 100644 --- a/crates/gateway/src/stateful_transaction_validator_test.rs +++ b/crates/gateway/src/stateful_transaction_validator_test.rs @@ -18,10 +18,8 @@ use mockall::predicate::eq; use num_bigint::BigUint; use pretty_assertions::assert_eq; use rstest::{fixture, rstest}; -use starknet_api::core::{ContractAddress, Nonce, PatriciaKey}; +use starknet_api::core::{ContractAddress, Nonce}; use starknet_api::rpc_transaction::RpcTransaction; -use starknet_api::transaction::TransactionHash; -use starknet_api::{contract_address, felt, patricia_key}; use starknet_sierra_compile::config::SierraToCasmCompilationConfig; use starknet_types_core::felt::Felt; @@ -68,13 +66,7 @@ fn stateful_validator(block_context: BlockContext) -> StatefulTransactionValidat #[rstest] #[case::valid_tx( invoke_tx(CairoVersion::Cairo1), - Ok(ValidateInfo{ - tx_hash: TransactionHash(felt!( - "0x152b8dd0c30e95fa3a4ee7a9398fcfc46fb00c048b4fdcfa9958c64d65899b8" - )), - sender_address: contract_address!("0xc0020000"), - account_nonce: Nonce::default() - }) + Ok(ValidateInfo{account_nonce: Nonce::default()}) )] #[case::invalid_tx(invoke_tx(CairoVersion::Cairo1), Err(STATEFUL_VALIDATOR_FEE_ERROR))] fn test_stateful_tx_validator( diff --git a/crates/gateway/src/utils.rs b/crates/gateway/src/utils.rs index 7bea4e4bd66..f00191d7493 100644 --- a/crates/gateway/src/utils.rs +++ b/crates/gateway/src/utils.rs @@ -169,18 +169,3 @@ pub fn executable_transaction_to_account_tx( } } } - -// TODO(yael 9/5/54): Should be implemented as part of InternalTransaction in starknet-api -pub fn get_sender_address(tx: &AccountTransaction) -> ContractAddress { - match tx { - AccountTransaction::Declare(tx) => match &tx.tx { - DeclareTransaction::V3(tx) => tx.sender_address, - _ => panic!("Unsupported transaction version"), - }, - AccountTransaction::DeployAccount(tx) => tx.contract_address, - AccountTransaction::Invoke(tx) => match &tx.tx { - InvokeTransaction::V3(tx) => tx.sender_address, - _ => panic!("Unsupported transaction version"), - }, - } -} diff --git a/crates/starknet_api/src/executable_transaction.rs b/crates/starknet_api/src/executable_transaction.rs index 3b65f39a9f6..8f28f88b4d6 100644 --- a/crates/starknet_api/src/executable_transaction.rs +++ b/crates/starknet_api/src/executable_transaction.rs @@ -13,6 +13,7 @@ pub enum Transaction { } impl Transaction { + /// This parameter is somethimes called `sender_address`. pub fn contract_address(&self) -> ContractAddress { match self { Transaction::Declare(tx_data) => tx_data.tx.sender_address(),