From f376d08e8598c0f42ec596841cd9a2f5c0ac4ae8 Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Tue, 15 Oct 2024 15:57:33 +0300 Subject: [PATCH] chore: clean http server module commit-id:5267cf65 --- Cargo.lock | 4 ++-- crates/gateway/Cargo.toml | 1 - crates/gateway/src/errors.rs | 7 ------- crates/http_server/Cargo.toml | 3 ++- crates/http_server/src/errors.rs | 6 ++++++ crates/http_server/src/http_server.rs | 20 +++++--------------- 6 files changed, 15 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a9eebaeb0f..d709bce013 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10253,7 +10253,6 @@ dependencies = [ "blockifier", "cairo-lang-sierra-to-casm", "cairo-lang-starknet-classes", - "hyper 0.14.30", "mempool_test_utils", "mockall", "mockito 1.5.0", @@ -10304,13 +10303,14 @@ name = "starknet_http_server" version = "0.0.0" dependencies = [ "axum", + "hyper 0.14.30", "papyrus_config", "serde", "serde_json", "starknet_api", - "starknet_gateway", "starknet_gateway_types", "starknet_mempool_infra", + "thiserror", "tokio", "tracing", "validator", diff --git a/crates/gateway/Cargo.toml b/crates/gateway/Cargo.toml index e6e1818457..b8006e96c9 100644 --- a/crates/gateway/Cargo.toml +++ b/crates/gateway/Cargo.toml @@ -16,7 +16,6 @@ async-trait.workspace = true axum.workspace = true blockifier = { workspace = true, features = ["testing"] } cairo-lang-starknet-classes.workspace = true -hyper.workspace = true mempool_test_utils.workspace = true papyrus_config.workspace = true papyrus_network_types.workspace = true diff --git a/crates/gateway/src/errors.rs b/crates/gateway/src/errors.rs index 2374b93706..5ffc49f2ce 100644 --- a/crates/gateway/src/errors.rs +++ b/crates/gateway/src/errors.rs @@ -68,13 +68,6 @@ pub type StatelessTransactionValidatorResult = Result = Result; -/// Errors originating from `[`Gateway::run`]` command, to be handled by infrastructure code. -#[derive(Debug, Error)] -pub enum GatewayRunError { - #[error(transparent)] - ServerStartupError(#[from] hyper::Error), -} - #[derive(Debug, Error)] pub enum RPCStateReaderError { #[error("Block not found for request {0}")] diff --git a/crates/http_server/Cargo.toml b/crates/http_server/Cargo.toml index ce122531d2..a94d018f7f 100644 --- a/crates/http_server/Cargo.toml +++ b/crates/http_server/Cargo.toml @@ -10,12 +10,13 @@ workspace = true [dependencies] axum.workspace = true +hyper.workspace = true papyrus_config.workspace = true serde.workspace = true starknet_api.workspace = true -starknet_gateway.workspace = true starknet_gateway_types.workspace = true starknet_mempool_infra.workspace = true +thiserror.workspace = true tracing.workspace = true validator.workspace = true diff --git a/crates/http_server/src/errors.rs b/crates/http_server/src/errors.rs index 8b13789179..5a01c057a1 100644 --- a/crates/http_server/src/errors.rs +++ b/crates/http_server/src/errors.rs @@ -1 +1,7 @@ +use thiserror::Error; +#[derive(Debug, Error)] +pub enum HttpServerRunError { + #[error(transparent)] + ServerStartupError(#[from] hyper::Error), +} diff --git a/crates/http_server/src/http_server.rs b/crates/http_server/src/http_server.rs index c216f8cf29..a8653c75b3 100644 --- a/crates/http_server/src/http_server.rs +++ b/crates/http_server/src/http_server.rs @@ -7,7 +7,6 @@ use axum::routing::{get, post}; use axum::{async_trait, Json, Router}; use starknet_api::rpc_transaction::RpcTransaction; use starknet_api::transaction::TransactionHash; -use starknet_gateway::errors::GatewayRunError; use starknet_gateway_types::communication::SharedGatewayClient; use starknet_gateway_types::errors::GatewaySpecError; use starknet_gateway_types::gateway_types::GatewayInput; @@ -16,6 +15,7 @@ use starknet_mempool_infra::errors::ComponentError; use tracing::{error, info, instrument}; use crate::config::HttpServerConfig; +use crate::errors::HttpServerRunError; #[cfg(test)] #[path = "http_server_test.rs"] @@ -39,8 +39,7 @@ impl HttpServer { HttpServer { config, app_state } } - // TODO(Tsabary/Lev): Rename "GatewayRunError" to "HttpServerRunError". - pub async fn run(&mut self) -> Result<(), GatewayRunError> { + pub async fn run(&mut self) -> Result<(), HttpServerRunError> { // Parses the bind address from HttpServerConfig, returning an error for invalid addresses. let HttpServerConfig { ip, port } = self.config; let addr = SocketAddr::new(ip, port); @@ -52,32 +51,23 @@ impl HttpServer { } pub fn app(&self) -> Router { - Router::new() - .route("/is_alive", get(is_alive)) - .route("/add_tx", post(add_tx)) - .with_state(self.app_state.clone()) + Router::new().route("/add_tx", post(add_tx)).with_state(self.app_state.clone()) } } // HttpServer handlers. -#[instrument] -async fn is_alive() -> HttpServerResult { - unimplemented!("Future handling should be implemented here."); -} - #[instrument(skip(app_state))] async fn add_tx( State(app_state): State, Json(tx): Json, ) -> HttpServerResult> { - let gateway_input: GatewayInput = GatewayInput { rpc_tx: tx.clone(), message_metadata: None }; - + info!("Received tx: {:?}", tx); + let gateway_input = GatewayInput { rpc_tx: tx, message_metadata: None }; let add_tx_result = app_state.gateway_client.add_tx(gateway_input).await.map_err(|join_err| { error!("Failed to process tx: {}", join_err); GatewaySpecError::UnexpectedError { data: "Internal server error".to_owned() } }); - add_tx_result_as_json(add_tx_result) }