diff --git a/crates/gateway/src/gateway.rs b/crates/gateway/src/gateway.rs index 38b8a54d72..a6b0913f55 100644 --- a/crates/gateway/src/gateway.rs +++ b/crates/gateway/src/gateway.rs @@ -130,12 +130,13 @@ fn process_tx( // TODO(Yael 31/7/24): refactor after IntrnalTransaction is ready, delete validate_info and // compute all the info outside of run_validate. let validate_info = stateful_tx_validator.run_validate(&executable_tx, validator)?; + let sender_address = executable_tx.contract_address(); // TODO(Arni): Add the Sierra and the Casm to the mempool input. Ok(MempoolInput { tx: executable_tx, account: Account { - sender_address: validate_info.sender_address, + sender_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 f064acf130..35449e41fd 100644 --- a/crates/gateway/src/stateful_transaction_validator.rs +++ b/crates/gateway/src/stateful_transaction_validator.rs @@ -15,7 +15,6 @@ use starknet_api::executable_transaction::{ InvokeTransaction as ExecutableInvokeTransaction, Transaction as ExecutableTransaction, }; -use starknet_api::transaction::TransactionHash; use starknet_gateway_types::errors::GatewaySpecError; use starknet_types_core::felt::Felt; use tracing::error; @@ -74,9 +73,12 @@ impl StatefulTransactionValidator { executable_tx: &ExecutableTransaction, mut validator: V, ) -> StatefulTransactionValidatorResult { - let tx_hash = executable_tx.tx_hash(); 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 = AccountTransaction::try_from( // TODO(Arni): create a try_from for &ExecutableTransaction. executable_tx.clone(), @@ -85,15 +87,10 @@ impl StatefulTransactionValidator { error!("Failed to convert executable transaction into account transaction: {}", error); GatewaySpecError::UnexpectedError { data: "Internal server error".to_owned() } })?; - 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); 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( @@ -149,12 +146,9 @@ pub fn get_latest_block_info( }) } -// TODO(Arni): Remove irrelevant fields. /// Holds members created by the stateful transaction validator, needed for /// [`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 3e41c3c524..5f4024a487 100644 --- a/crates/gateway/src/stateful_transaction_validator_test.rs +++ b/crates/gateway/src/stateful_transaction_validator_test.rs @@ -15,12 +15,12 @@ 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::Nonce; use starknet_api::executable_transaction::Transaction; use starknet_api::test_utils::deploy_account::executable_deploy_account_tx; use starknet_api::test_utils::invoke::executable_invoke_tx; -use starknet_api::transaction::{Resource, TransactionHash}; -use starknet_api::{contract_address, deploy_account_tx_args, felt, invoke_tx_args, patricia_key}; +use starknet_api::transaction::Resource; +use starknet_api::{deploy_account_tx_args, invoke_tx_args}; use starknet_gateway_types::errors::GatewaySpecError; use starknet_types_core::felt::Felt; @@ -66,11 +66,7 @@ fn stateful_validator(block_context: BlockContext) -> StatefulTransactionValidat #[rstest] #[case::valid_tx( create_executable_invoke_tx(CairoVersion::Cairo1), - Ok(ValidateInfo{ - tx_hash: TransactionHash::default(), - sender_address: contract_address!("0xc0020000"), - account_nonce: Nonce::default() - }) + Ok(ValidateInfo{account_nonce: Nonce::default()}) )] #[case::invalid_tx( create_executable_invoke_tx(CairoVersion::Cairo1), diff --git a/crates/starknet_api/src/executable_transaction.rs b/crates/starknet_api/src/executable_transaction.rs index 2cd0c1e9fa..9b3a15fa18 100644 --- a/crates/starknet_api/src/executable_transaction.rs +++ b/crates/starknet_api/src/executable_transaction.rs @@ -58,6 +58,10 @@ impl Transaction { } } + pub fn sender_address(&self) -> ContractAddress { + self.contract_address() + } + pub fn nonce(&self) -> Nonce { match self { Transaction::Declare(tx_data) => tx_data.tx.nonce(),