Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 21 additions & 73 deletions bin/network-monitor/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

use anyhow::Result;
use miden_node_utils::logging::OpenTelemetry;
use tokio::sync::watch;
use tracing::{debug, info, instrument, warn};
use tracing::{info, instrument};

use crate::COMPONENT;
use crate::config::MonitorConfig;
use crate::frontend::ServerState;
use crate::monitor::tasks::Tasks;
use crate::status::ServiceStatus;

/// Start the network monitoring service.
///
Expand All @@ -28,7 +26,6 @@ use crate::status::ServiceStatus;
err
)]
pub async fn start_monitor(config: MonitorConfig) -> Result<()> {
// Load configuration from command-line arguments and environment variables
info!("Loaded configuration: {:?}", config);

let _otel_guard = if config.enable_otel {
Expand All @@ -39,82 +36,33 @@ pub async fn start_monitor(config: MonitorConfig) -> Result<()> {

let mut tasks = Tasks::new();

// Initialize the RPC Status endpoint checker task.
debug!(target: COMPONENT, "Initializing RPC status checker");
let rpc_rx = tasks.spawn_rpc_checker(&config).await?;

// Initialize the explorer status checker task.
let explorer_rx = if config.explorer_url.is_some() {
Some(tasks.spawn_explorer_checker(&config).await?)
} else {
None
};

// Initialize the note transport status checker task.
let note_transport_rx = if config.note_transport_url.is_some() {
Some(tasks.spawn_note_transport_checker(&config).await?)
} else {
None
};
// Build the flat services Vec in the order the dashboard expects to render cards.
let mut services = vec![tasks.spawn_rpc_checker(&config)];

// Initialize the validator status checker task.
let validator_rx = if config.validator_url.is_some() {
Some(tasks.spawn_validator_checker(&config).await?)
} else {
None
};
if config.faucet_url.is_some() {
services.push(tasks.spawn_faucet(&config));
}

// Initialize the prover checkers & tests tasks, only if URLs were provided.
let prover_rxs = if config.remote_prover_urls.is_empty() {
debug!(target: COMPONENT, "No remote prover URLs configured, skipping prover tasks");
Vec::new()
} else {
debug!(target: COMPONENT, "Initializing prover checkers and tests");
tasks.spawn_prover_tasks(&config).await?
};
if !config.remote_prover_urls.is_empty() {
services.extend(tasks.spawn_prover_tasks(&config).await);
}

// Initialize the faucet testing task.
let faucet_rx = if config.faucet_url.is_some() {
debug!(target: COMPONENT, "Initializing faucet testing task");
Some(tasks.spawn_faucet(&config))
} else {
warn!("Faucet URL not configured, skipping faucet testing");
None
};
if config.explorer_url.is_some() {
services.push(tasks.spawn_explorer_checker(&config));
}

// Initialize the counter increment and tracking tasks only if enabled.
let (ntx_increment_rx, ntx_tracking_rx) = if config.disable_ntx_service {
debug!(target: COMPONENT, "NTX service disabled, skipping counter increment task");
(None, None)
} else {
debug!(target: COMPONENT, "Initializing counter increment task");
if !config.disable_ntx_service {
let (increment_rx, tracking_rx) = tasks.spawn_ntx_service(&config).await?;
(Some(increment_rx), Some(tracking_rx))
};

// Initialize HTTP server.
debug!(target: COMPONENT, "Initializing HTTP server");

// Build the flat services Vec in the order the dashboard expects to render cards.
let mut services: Vec<watch::Receiver<ServiceStatus>> = vec![rpc_rx];
if let Some(rx) = faucet_rx {
services.push(rx);
}
services.extend(prover_rxs);
if let Some(rx) = explorer_rx {
services.push(rx);
}
if let Some(rx) = ntx_increment_rx {
services.push(rx);
services.push(increment_rx);
services.push(tracking_rx);
}
if let Some(rx) = ntx_tracking_rx {
services.push(rx);
}
if let Some(rx) = note_transport_rx {
services.push(rx);

if config.note_transport_url.is_some() {
services.push(tasks.spawn_note_transport_checker(&config));
}
if let Some(rx) = validator_rx {
services.push(rx);

if config.validator_url.is_some() {
services.push(tasks.spawn_validator_checker(&config));
}

let server_state = ServerState {
Expand Down
Loading
Loading