Skip to content

Commit

Permalink
fix(mempool): convert invoke and deploy account transactions to rpc (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
AlonLStarkWare authored Nov 4, 2024
1 parent 9818bb1 commit 6d7572e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 18 deletions.
24 changes: 23 additions & 1 deletion crates/mempool/src/communication.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use async_trait::async_trait;
use papyrus_network_types::network_types::BroadcastedMessageMetadata;
use starknet_api::executable_transaction::Transaction;
use starknet_api::rpc_transaction::{
RpcDeployAccountTransaction,
RpcInvokeTransaction,
RpcTransaction,
};
use starknet_mempool_p2p_types::communication::SharedMempoolP2pPropagatorClient;
use starknet_mempool_types::communication::{
AddTransactionArgsWrapper,
Expand Down Expand Up @@ -58,7 +63,24 @@ impl MempoolCommunicationWrapper {
.await
.map_err(|_| MempoolError::P2pPropagatorClientError { tx_hash: tx.tx_hash() }),
None => {
self.mempool_p2p_propagator_client.add_transaction(tx.into()).await.unwrap();
let tx_hash = tx.tx_hash();
match tx {
Transaction::Invoke(invoke_tx) => self
.mempool_p2p_propagator_client
.add_transaction(RpcTransaction::Invoke(RpcInvokeTransaction::V3(
invoke_tx.into(),
)))
.await
.map_err(|_| MempoolError::P2pPropagatorClientError { tx_hash })?,
Transaction::DeployAccount(deploy_account_tx) => self
.mempool_p2p_propagator_client
.add_transaction(RpcTransaction::DeployAccount(
RpcDeployAccountTransaction::V3(deploy_account_tx.into()),
))
.await
.map_err(|_| MempoolError::P2pPropagatorClientError { tx_hash })?,
Transaction::Declare(_) => {}
}
Ok(())
}
}
Expand Down
58 changes: 41 additions & 17 deletions crates/starknet_api/src/executable_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::core::{calculate_contract_address, ChainId, ClassHash, ContractAddres
use crate::data_availability::DataAvailabilityMode;
use crate::rpc_transaction::{
RpcDeployAccountTransaction,
RpcDeployAccountTransactionV3,
RpcInvokeTransaction,
RpcInvokeTransactionV3,
RpcTransaction,
Expand Down Expand Up @@ -141,26 +142,49 @@ impl Transaction {
}
}

// TODO: replace with proper implementation.
impl From<Transaction> for RpcTransaction {
fn from(tx: Transaction) -> Self {
Self::Invoke(RpcInvokeTransaction::V3(RpcInvokeTransactionV3 {
sender_address: tx.contract_address(),
tip: tx.tip().unwrap_or_default(),
nonce: Nonce::default(),
// TODO: add a converter for Declare transactions as well.

impl From<InvokeTransaction> for RpcInvokeTransactionV3 {
fn from(tx: InvokeTransaction) -> Self {
Self {
sender_address: tx.sender_address(),
tip: tx.tip(),
nonce: tx.nonce(),
resource_bounds: match tx.resource_bounds() {
Some(ValidResourceBounds::AllResources(all_resource_bounds)) => {
*all_resource_bounds
ValidResourceBounds::AllResources(all_resource_bounds) => all_resource_bounds,
ValidResourceBounds::L1Gas(l1_gas) => {
AllResourceBounds { l1_gas, ..Default::default() }
}
_ => AllResourceBounds::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(),
}))
signature: tx.signature(),
calldata: tx.calldata(),
nonce_data_availability_mode: tx.nonce_data_availability_mode(),
fee_data_availability_mode: tx.fee_data_availability_mode(),
paymaster_data: tx.paymaster_data(),
account_deployment_data: tx.account_deployment_data(),
}
}
}

impl From<DeployAccountTransaction> for RpcDeployAccountTransactionV3 {
fn from(tx: DeployAccountTransaction) -> Self {
Self {
class_hash: tx.class_hash(),
constructor_calldata: tx.constructor_calldata(),
contract_address_salt: tx.contract_address_salt(),
nonce: tx.nonce(),
signature: tx.signature(),
resource_bounds: match tx.resource_bounds() {
ValidResourceBounds::AllResources(all_resource_bounds) => all_resource_bounds,
ValidResourceBounds::L1Gas(l1_gas) => {
AllResourceBounds { l1_gas, ..Default::default() }
}
},
tip: tx.tip(),
nonce_data_availability_mode: tx.nonce_data_availability_mode(),
fee_data_availability_mode: tx.fee_data_availability_mode(),
paymaster_data: tx.paymaster_data(),
}
}
}

Expand Down

0 comments on commit 6d7572e

Please sign in to comment.