Skip to content

Commit

Permalink
refactor: add MempoolClient type alias (#237)
Browse files Browse the repository at this point in the history
Co-Authored-By: Gilad Chase <[email protected]>
  • Loading branch information
giladchase and Gilad Chase authored Jun 16, 2024
1 parent 7aad112 commit c94d1d7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions crates/gateway/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -33,14 +33,14 @@ pub struct AppState {
pub stateless_tx_validator: StatelessTransactionValidator,
pub stateful_tx_validator: Arc<StatefulTransactionValidator>,
pub state_reader_factory: Arc<dyn StateReaderFactory>,
pub mempool_client: Arc<dyn MempoolClient>,
pub mempool_client: SharedMempoolClient,
}

impl Gateway {
pub fn new(
config: GatewayConfig,
state_reader_factory: Arc<dyn StateReaderFactory>,
mempool_client: Arc<dyn MempoolClient>,
mempool_client: SharedMempoolClient,
) -> Self {
let app_state = AppState {
stateless_tx_validator: StatelessTransactionValidator {
Expand Down
8 changes: 3 additions & 5 deletions crates/gateway/src/gateway_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<dyn MempoolClient>) -> AppState {
pub fn app_state(mempool_client: SharedMempoolClient) -> AppState {
AppState {
stateless_tx_validator: StatelessTransactionValidator {
config: StatelessTransactionValidatorConfig {
Expand Down
4 changes: 4 additions & 0 deletions crates/mempool_types/src/mempool_types.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -7,6 +9,8 @@ use thiserror::Error;

use crate::errors::MempoolError;

pub type SharedMempoolClient = Arc<dyn MempoolClient>;

#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct ThinTransaction {
pub sender_address: ContractAddress,
Expand Down
4 changes: 2 additions & 2 deletions crates/tests-integration/tests/end_to_end_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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;
use tokio::time::sleep;

const MEMPOOL_INVOCATIONS_QUEUE_SIZE: usize = 32;

async fn set_up_gateway(mempool_client: Arc<dyn MempoolClient>) -> 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 };
Expand Down

0 comments on commit c94d1d7

Please sign in to comment.