diff --git a/crates/gateway/src/gateway.rs b/crates/gateway/src/gateway.rs index 8184890447..e814480252 100644 --- a/crates/gateway/src/gateway.rs +++ b/crates/gateway/src/gateway.rs @@ -142,9 +142,13 @@ fn process_tx( // TODO(Arni): Add the Sierra and the Casm to the mempool input. Ok(MempoolInput { - tx: Transaction::new_from_rpc_tx(tx, validate_info.tx_hash, validate_info.sender_address), + tx: Transaction::new_from_rpc_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 72bddcb7da..5456142500 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"] @@ -74,18 +73,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( @@ -145,7 +143,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 07918ed1d6..9cb2c6a340 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 07b9e19932..9c00ee8947 100644 --- a/crates/gateway/src/utils.rs +++ b/crates/gateway/src/utils.rs @@ -154,18 +154,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 { - starknet_api::transaction::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 a249bed64a..6bf9ce5e43 100644 --- a/crates/starknet_api/src/executable_transaction.rs +++ b/crates/starknet_api/src/executable_transaction.rs @@ -23,6 +23,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(),