From 58ab508fa9238d6bf27b07f2c61093b03b6f4ea2 Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Tue, 14 Jan 2025 17:50:12 +0200 Subject: [PATCH] chore(starknet_gateway): refactor skip validate check towards early return --- .../src/stateful_transaction_validator.rs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/crates/starknet_gateway/src/stateful_transaction_validator.rs b/crates/starknet_gateway/src/stateful_transaction_validator.rs index c79224ee03..1729d34220 100644 --- a/crates/starknet_gateway/src/stateful_transaction_validator.rs +++ b/crates/starknet_gateway/src/stateful_transaction_validator.rs @@ -101,19 +101,18 @@ impl StatefulTransactionValidator { } } -// Check if validation of an invoke transaction should be skipped due to deploy_account not being -// processed yet. This feature is used to improve UX for users sending deploy_account + invoke at -// once. +/// Check if validation of an invoke transaction should be skipped due to deploy_account not being +/// processed yet. This feature is used to improve UX for users sending deploy_account + invoke at +/// once. fn skip_stateful_validations(tx: &ExecutableTransaction, account_nonce: Nonce) -> bool { - match tx { - ExecutableTransaction::Invoke(ExecutableInvokeTransaction { tx, .. }) => { - // check if the transaction nonce is 1, meaning it is post deploy_account, and the - // account nonce is zero, meaning the account was not deployed yet. The mempool also - // verifies that the deploy_account transaction exists. - tx.nonce() == Nonce(Felt::ONE) && account_nonce == Nonce(Felt::ZERO) - } - ExecutableTransaction::DeployAccount(_) | ExecutableTransaction::Declare(_) => false, + if let ExecutableTransaction::Invoke(ExecutableInvokeTransaction { tx, .. }) = tx { + // TODO(Arni): Add a verification that there is a deploy_account transaction in the mempool. + // check if the transaction nonce is 1, meaning it is post deploy_account, and the + // account nonce is zero, meaning the account was not deployed yet. + return tx.nonce() == Nonce(Felt::ONE) && account_nonce == Nonce(Felt::ZERO); } + + false } pub fn get_latest_block_info(