Skip to content

Commit

Permalink
refactor(node): refactor how monitoring server is spawned
Browse files Browse the repository at this point in the history
  • Loading branch information
matan-starkware committed Sep 19, 2024
1 parent 98a4868 commit 4d56284
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
7 changes: 1 addition & 6 deletions crates/papyrus_monitoring_gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@ impl MonitoringServer {
})
}

/// Spawns a monitoring server.
pub async fn spawn_server(self) -> tokio::task::JoinHandle<Result<(), hyper::Error>> {
tokio::spawn(async move { self.run_server().await })
}

#[instrument(
skip(self),
fields(
Expand All @@ -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(
Expand Down
26 changes: 19 additions & 7 deletions crates/papyrus_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JoinHandle<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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 4d56284

Please sign in to comment.