From df38d109a4f8016862b0cd1ab3b9baa05858cee3 Mon Sep 17 00:00:00 2001 From: Matan Markind Date: Wed, 18 Sep 2024 19:53:03 +0300 Subject: [PATCH] refactor(node): refactor how monitoring server is spawned --- crates/papyrus_monitoring_gateway/src/lib.rs | 7 +----- crates/papyrus_node/src/main.rs | 26 ++++++++++++++------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/papyrus_monitoring_gateway/src/lib.rs b/crates/papyrus_monitoring_gateway/src/lib.rs index 1f7e068c91..514ee92797 100644 --- a/crates/papyrus_monitoring_gateway/src/lib.rs +++ b/crates/papyrus_monitoring_gateway/src/lib.rs @@ -153,11 +153,6 @@ impl MonitoringServer { }) } - /// Spawns a monitoring server. - pub async fn spawn_server(self) -> tokio::task::JoinHandle> { - tokio::spawn(async move { self.run_server().await }) - } - #[instrument( skip(self), fields( @@ -167,7 +162,7 @@ impl MonitoringServer { public_general_config_presentation = %self.public_general_config_presentation, present_full_config_secret = %self.config.present_full_config_secret), level = "debug")] - async fn run_server(&self) -> std::result::Result<(), hyper::Error> { + pub async fn run_server(&self) -> std::result::Result<(), hyper::Error> { let server_address = SocketAddr::from_str(&self.config.server_address) .expect("Configuration value for monitor server address should be valid"); let app = app( diff --git a/crates/papyrus_node/src/main.rs b/crates/papyrus_node/src/main.rs index 1f3a885e4c..bbfe673ea4 100644 --- a/crates/papyrus_node/src/main.rs +++ b/crates/papyrus_node/src/main.rs @@ -129,6 +129,22 @@ async fn spawn_rpc_server( Ok(tokio::spawn(pending())) } +fn spawn_monitoring_server( + storage_reader: StorageReader, + local_peer_id: String, + config: &NodeConfig, +) -> anyhow::Result>> { + let monitoring_server = MonitoringServer::new( + config.monitoring_gateway.clone(), + get_config_presentation(config, true)?, + get_config_presentation(config, false)?, + storage_reader, + VERSION_FULL, + local_peer_id, + )?; + Ok(tokio::spawn(async move { Ok(monitoring_server.run_server().await?) })) +} + fn spawn_consensus( config: Option<&ConsensusConfig>, storage_reader: StorageReader, @@ -336,15 +352,11 @@ async fn run_threads(config: NodeConfig, mut resources: PapyrusResources) -> any ); // Monitoring server. - let monitoring_server = MonitoringServer::new( - config.monitoring_gateway.clone(), - get_config_presentation(&config, true)?, - get_config_presentation(&config, false)?, + let monitoring_server_handle = spawn_monitoring_server( resources.storage_reader.clone(), - VERSION_FULL, - resources.local_peer_id, + resources.local_peer_id.clone(), + &config, )?; - let monitoring_server_handle = monitoring_server.spawn_server().await; // JSON-RPC server. let rpc_server_handle = spawn_rpc_server(