Skip to content

Commit

Permalink
refactor(gateway): send full tx instead of thin tx (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadNassar1 authored and guy-starkware committed Aug 20, 2024
1 parent 743ee99 commit 26ad7f7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 22 deletions.
5 changes: 2 additions & 3 deletions crates/gateway/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use async_trait::async_trait;
use axum::extract::State;
use axum::routing::{get, post};
use axum::{Json, Router};
use starknet_api::executable_transaction::Transaction;
use starknet_api::rpc_transaction::RpcTransaction;
use starknet_api::transaction::TransactionHash;
use starknet_mempool_infra::component_runner::{ComponentStartError, ComponentStarter};
Expand All @@ -20,7 +21,6 @@ use crate::rpc_state_reader::RpcStateReaderFactory;
use crate::state_reader::StateReaderFactory;
use crate::stateful_transaction_validator::StatefulTransactionValidator;
use crate::stateless_transaction_validator::StatelessTransactionValidator;
use crate::utils::external_tx_to_thin_tx;

#[cfg(test)]
#[path = "gateway_test.rs"]
Expand Down Expand Up @@ -143,8 +143,7 @@ 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))
.into(),
tx: Transaction::new_from_rpc_tx(tx, validate_info.tx_hash, validate_info.sender_address),
account: Account {
sender_address: validate_info.sender_address,
state: AccountState { nonce: validate_info.account_nonce },
Expand Down
2 changes: 2 additions & 0 deletions crates/gateway/src/stateful_transaction_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ impl StatefulTransactionValidatorTrait for BlockifierStatefulValidator {
}

impl StatefulTransactionValidator {
// TODO(Arni): consider separating validation from transaction conversion, as transaction
// conversion is also relevant for the Mempool.
pub fn run_validate<V: StatefulTransactionValidatorTrait>(
&self,
external_tx: &RpcTransaction,
Expand Down
20 changes: 2 additions & 18 deletions crates/gateway/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,13 @@ use starknet_api::transaction::{
DeclareTransactionV3,
DeployAccountTransaction,
DeployAccountTransactionV3,
InvokeTransaction,
InvokeTransactionV3,
TransactionHash,
TransactionHasher,
};
use starknet_mempool_types::mempool_types::ThinTransaction;
use tracing::error;

use crate::errors::{GatewaySpecError, StatefulTransactionValidatorResult};

pub fn external_tx_to_thin_tx(
external_tx: &RpcTransaction,
tx_hash: TransactionHash,
sender_address: ContractAddress,
) -> ThinTransaction {
ThinTransaction {
tip: *external_tx.tip(),
nonce: *external_tx.nonce(),
sender_address,
tx_hash,
}
}

pub fn external_tx_to_account_tx(
external_tx: &RpcTransaction,
// FIXME(yael 15/4/24): calculate class_info inside the function once compilation code is ready
Expand Down Expand Up @@ -114,7 +98,7 @@ pub fn external_tx_to_account_tx(
Ok(AccountTransaction::DeployAccount(deploy_account_tx))
}
RpcTransaction::Invoke(RpcInvokeTransaction::V3(tx)) => {
let invoke_tx = InvokeTransaction::V3(InvokeTransactionV3 {
let invoke_tx = starknet_api::transaction::InvokeTransaction::V3(InvokeTransactionV3 {
resource_bounds: tx.resource_bounds.clone().into(),
tip: tx.tip,
signature: tx.signature.clone(),
Expand Down Expand Up @@ -147,7 +131,7 @@ pub fn get_sender_address(tx: &AccountTransaction) -> ContractAddress {
},
AccountTransaction::DeployAccount(tx) => tx.contract_address,
AccountTransaction::Invoke(tx) => match &tx.tx {
InvokeTransaction::V3(tx) => tx.sender_address,
starknet_api::transaction::InvokeTransaction::V3(tx) => tx.sender_address,
_ => panic!("Unsupported transaction version"),
},
}
Expand Down
37 changes: 36 additions & 1 deletion crates/starknet_api/src/executable_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ use serde::{Deserialize, Serialize};

use crate::contract_class::ClassInfo;
use crate::core::{ContractAddress, Nonce};
use crate::transaction::{Tip, TransactionHash};
use crate::data_availability::DataAvailabilityMode;
use crate::rpc_transaction::RpcTransaction;
use crate::transaction::{
AccountDeploymentData,
Calldata,
PaymasterData,
ResourceBoundsMapping,
Tip,
TransactionHash,
TransactionSignature,
};

/// Represents a paid Starknet transaction.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
Expand Down Expand Up @@ -53,6 +63,31 @@ impl Transaction {
},
}
}

// TODO(Arni): Update the function to support all transaction types.
pub fn new_from_rpc_tx(
rpc_tx: RpcTransaction,
tx_hash: TransactionHash,
sender_address: ContractAddress,
) -> Transaction {
Transaction::Invoke(crate::executable_transaction::InvokeTransaction {
tx: crate::transaction::InvokeTransaction::V3(
crate::transaction::InvokeTransactionV3 {
sender_address,
tip: *rpc_tx.tip(),
nonce: *rpc_tx.nonce(),
resource_bounds: ResourceBoundsMapping::default(),
signature: TransactionSignature::default(),
calldata: Calldata::default(),
nonce_data_availability_mode: DataAvailabilityMode::L1,
fee_data_availability_mode: DataAvailabilityMode::L1,
paymaster_data: PaymasterData::default(),
account_deployment_data: AccountDeploymentData::default(),
},
),
tx_hash,
})
}
}

// TODO(Mohammad): Add constructor for all the transaction's structs.
Expand Down

0 comments on commit 26ad7f7

Please sign in to comment.