Skip to content

Commit

Permalink
refactor(gateway): send full tx instead of thin tx
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadNassar1 committed Aug 19, 2024
1 parent 33b5252 commit 2b8cc3a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
4 changes: 1 addition & 3 deletions crates/gateway/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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 +142,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: tx.new_from_rpc_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
26 changes: 9 additions & 17 deletions crates/gateway/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,32 @@ use blockifier::transaction::transactions::{
InvokeTransaction as BlockifierInvokeTransaction,
};
use starknet_api::core::{calculate_contract_address, ChainId, ClassHash, ContractAddress};
use starknet_api::data_availability::DataAvailabilityMode;
use starknet_api::executable_transaction::{InvokeTransaction, Transaction};
use starknet_api::rpc_transaction::{
RpcDeclareTransaction,
RpcDeployAccountTransaction,
RpcInvokeTransaction,
RpcTransaction,
};
use starknet_api::transaction::{
AccountDeploymentData,
Calldata,
DeclareTransaction,
DeclareTransactionV3,
DeployAccountTransaction,
DeployAccountTransactionV3,
InvokeTransaction,
InvokeTransactionV3,
PaymasterData,
ResourceBoundsMapping,
TransactionHash,
TransactionHasher,
TransactionSignature,
};
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 +106,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 +139,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
27 changes: 27 additions & 0 deletions crates/starknet_api/src/rpc_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::core::{
Nonce,
};
use crate::data_availability::DataAvailabilityMode;
use crate::executable_transaction::Transaction;
use crate::state::EntryPoint;
use crate::transaction::{
AccountDeploymentData,
Expand All @@ -24,6 +25,7 @@ use crate::transaction::{
Resource,
ResourceBounds,
Tip,
TransactionHash,
TransactionSignature,
};
use crate::StarknetApiError;
Expand Down Expand Up @@ -82,6 +84,31 @@ impl RpcTransaction {
RpcTransaction::Invoke(RpcInvokeTransaction::V3(tx)) => Ok(tx.sender_address),
}
}

// TODO(Arni): Update the function to support all transaction types.
pub fn new_from_rpc_tx(
&self,
tx_hash: TransactionHash,
sender_address: ContractAddress,
) -> Transaction {
Transaction::Invoke(crate::executable_transaction::InvokeTransaction {
tx: crate::transaction::InvokeTransaction::V3(
crate::transaction::InvokeTransactionV3 {
sender_address,
tip: *self.tip(),
nonce: *self.nonce(),
resource_bounds: crate::transaction::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,
})
}
}

/// A RPC declare transaction.
Expand Down

0 comments on commit 2b8cc3a

Please sign in to comment.