From c94d1d7ea4e640363d8837026068e0f6ffa58624 Mon Sep 17 00:00:00 2001 From: giladchase Date: Sun, 16 Jun 2024 11:59:20 +0300 Subject: [PATCH] refactor: add MempoolClient type alias (#237) Co-Authored-By: Gilad Chase --- crates/gateway/src/gateway.rs | 6 +++--- crates/gateway/src/gateway_test.rs | 8 +++----- crates/mempool_types/src/mempool_types.rs | 4 ++++ crates/tests-integration/tests/end_to_end_test.rs | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/crates/gateway/src/gateway.rs b/crates/gateway/src/gateway.rs index 01850b78..da4f56a5 100644 --- a/crates/gateway/src/gateway.rs +++ b/crates/gateway/src/gateway.rs @@ -7,7 +7,7 @@ use axum::routing::{get, post}; use axum::{Json, Router}; use starknet_api::external_transaction::ExternalTransaction; use starknet_api::transaction::TransactionHash; -use starknet_mempool_types::mempool_types::{Account, MempoolClient, MempoolInput}; +use starknet_mempool_types::mempool_types::{Account, MempoolInput, SharedMempoolClient}; use crate::config::{GatewayConfig, GatewayNetworkConfig}; use crate::errors::{GatewayError, GatewayRunError}; @@ -33,14 +33,14 @@ pub struct AppState { pub stateless_tx_validator: StatelessTransactionValidator, pub stateful_tx_validator: Arc, pub state_reader_factory: Arc, - pub mempool_client: Arc, + pub mempool_client: SharedMempoolClient, } impl Gateway { pub fn new( config: GatewayConfig, state_reader_factory: Arc, - mempool_client: Arc, + mempool_client: SharedMempoolClient, ) -> Self { let app_state = AppState { stateless_tx_validator: StatelessTransactionValidator { diff --git a/crates/gateway/src/gateway_test.rs b/crates/gateway/src/gateway_test.rs index 6725b797..b57b0f9c 100644 --- a/crates/gateway/src/gateway_test.rs +++ b/crates/gateway/src/gateway_test.rs @@ -9,14 +9,12 @@ use blockifier::context::ChainInfo; use starknet_api::external_transaction::ExternalTransaction; use starknet_api::transaction::TransactionHash; use starknet_mempool::mempool::{create_mempool_server, Mempool}; -use starknet_mempool_types::mempool_types::{ - MempoolClient, MempoolClientImpl, MempoolRequestAndResponseSender, -}; +use starknet_mempool_types::mempool_types::{MempoolClientImpl, MempoolRequestAndResponseSender}; use tokio::sync::mpsc::channel; use tokio::task; use crate::config::{StatefulTransactionValidatorConfig, StatelessTransactionValidatorConfig}; -use crate::gateway::{add_tx, AppState}; +use crate::gateway::{add_tx, AppState, SharedMempoolClient}; use crate::starknet_api_test_utils::invoke_tx; use crate::state_reader_test_utils::local_test_state_reader_factory; use crate::stateful_transaction_validator::StatefulTransactionValidator; @@ -25,7 +23,7 @@ use crate::utils::{external_tx_to_account_tx, get_tx_hash}; const MEMPOOL_INVOCATIONS_QUEUE_SIZE: usize = 32; -pub fn app_state(mempool_client: Arc) -> AppState { +pub fn app_state(mempool_client: SharedMempoolClient) -> AppState { AppState { stateless_tx_validator: StatelessTransactionValidator { config: StatelessTransactionValidatorConfig { diff --git a/crates/mempool_types/src/mempool_types.rs b/crates/mempool_types/src/mempool_types.rs index cd9fbabc..48503e1a 100644 --- a/crates/mempool_types/src/mempool_types.rs +++ b/crates/mempool_types/src/mempool_types.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use async_trait::async_trait; use starknet_api::core::{ContractAddress, Nonce}; use starknet_api::transaction::{Tip, TransactionHash}; @@ -7,6 +9,8 @@ use thiserror::Error; use crate::errors::MempoolError; +pub type SharedMempoolClient = Arc; + #[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct ThinTransaction { pub sender_address: ContractAddress, diff --git a/crates/tests-integration/tests/end_to_end_test.rs b/crates/tests-integration/tests/end_to_end_test.rs index a540cd60..03631b8a 100644 --- a/crates/tests-integration/tests/end_to_end_test.rs +++ b/crates/tests-integration/tests/end_to_end_test.rs @@ -14,7 +14,7 @@ use starknet_gateway::state_reader_test_utils::rpc_test_state_reader_factory; use starknet_mempool::mempool::{create_mempool_server, Mempool}; use starknet_mempool_integration_tests::integration_test_utils::GatewayClient; use starknet_mempool_types::mempool_types::{ - MempoolClient, MempoolClientImpl, MempoolRequestAndResponseSender, + MempoolClient, MempoolClientImpl, MempoolRequestAndResponseSender, SharedMempoolClient, }; use tokio::sync::mpsc::channel; use tokio::task; @@ -22,7 +22,7 @@ use tokio::time::sleep; const MEMPOOL_INVOCATIONS_QUEUE_SIZE: usize = 32; -async fn set_up_gateway(mempool_client: Arc) -> SocketAddr { +async fn set_up_gateway(mempool_client: SharedMempoolClient) -> SocketAddr { let ip = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); let port = 3000; let network_config = GatewayNetworkConfig { ip, port };