Skip to content
Open
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## v0.12.6 (TBD)

- Improved tracing in `miden-network-monitor` binary ([#1366](https://github.com/0xMiden/miden-node/pull/1366)).
- Added Faucet metadata to the `miden-network-monitor` binary ([#1373](https://github.com/0xMiden/miden-node/pull/1373)).

## v0.12.5 (2025-11-27)
Expand Down
20 changes: 18 additions & 2 deletions bin/network-monitor/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

use crate::COMPONENT;
use crate::config::MonitorConfig;
Expand All @@ -15,7 +15,16 @@ use crate::monitor::tasks::Tasks;
///
/// This function initializes all monitoring tasks including RPC status checking,
/// remote prover testing, faucet testing, and the web frontend.
#[instrument(target = COMPONENT, name = "start-monitor", skip_all, fields(port = %config.port))]
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.start_monitor",
skip_all,
level = "info",
fields(port = %config.port),
ret(level = "debug"),
err
)]
pub async fn start_monitor(config: MonitorConfig) -> Result<()> {
// Load configuration from command-line arguments and environment variables
info!("Loaded configuration: {:?}", config);
Expand All @@ -29,17 +38,21 @@ 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 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?
};

// 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");
Expand All @@ -48,13 +61,16 @@ pub async fn start_monitor(config: MonitorConfig) -> Result<()> {

// 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 and tracking tasks");
(None, None)
} else {
let (increment_rx, tracking_rx) = tasks.spawn_ntx_service(&config).await?;
debug!(target: COMPONENT, "Initializing counter increment and tracking tasks");
(Some(increment_rx), Some(tracking_rx))
};

// Initialize HTTP server.
debug!(target: COMPONENT, "Initializing HTTP server");
let server_state = ServerState {
rpc: rpc_rx,
provers: prover_rxs,
Expand Down
30 changes: 27 additions & 3 deletions bin/network-monitor/src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,15 @@ async fn setup_increment_task(
/// # Returns
///
/// This function runs indefinitely, only returning on error.
#[instrument(target = COMPONENT, name = "run-increment-task", skip_all, ret(level = "debug"))]
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.counter.run_increment_task",
skip_all,
level = "info",
ret(level = "debug"),
err
)]
pub async fn run_increment_task(
config: MonitorConfig,
tx: watch::Sender<ServiceStatus>,
Expand Down Expand Up @@ -339,7 +347,15 @@ fn send_status(tx: &watch::Sender<ServiceStatus>, status: ServiceStatus) -> Resu
/// # Returns
///
/// This function runs indefinitely, only returning on error.
#[instrument(target = COMPONENT, name = "run-counter-tracking-task", skip_all, ret(level = "debug"))]
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.counter.run_counter_tracking_task",
skip_all,
level = "info",
ret(level = "debug"),
err
)]
pub async fn run_counter_tracking_task(
config: MonitorConfig,
tx: watch::Sender<ServiceStatus>,
Expand Down Expand Up @@ -458,7 +474,15 @@ fn load_counter_account(file_path: &Path) -> Result<Account> {

/// Create and submit a network note that targets the counter account.
#[allow(clippy::too_many_arguments)]
#[instrument(target = COMPONENT, name = "create-and-submit-network-note", skip_all, ret)]
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.counter.create_and_submit_network_note",
skip_all,
level = "info",
ret(level = "debug"),
err
)]
async fn create_and_submit_network_note(
wallet_account: &Account,
counter_account: &Account,
Expand Down
28 changes: 26 additions & 2 deletions bin/network-monitor/src/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ pub struct GetMetadataResponse {
/// # Returns
///
/// `Ok(())` if the task completes successfully, or an error if the task fails.
#[instrument(target = COMPONENT, name = "faucet-test-task", skip_all)]
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.faucet.run_faucet_test_task",
skip_all,
level = "info",
ret(level = "debug")
)]
pub async fn run_faucet_test_task(
faucet_url: Url,
status_sender: watch::Sender<ServiceStatus>,
Expand Down Expand Up @@ -167,6 +174,15 @@ pub async fn run_faucet_test_task(
/// # Returns
///
/// The response from the faucet if successful, or an error if the test fails.
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.faucet.perform_faucet_test",
skip_all,
level = "info",
ret(level = "debug"),
err
)]
async fn perform_faucet_test(
client: &Client,
faucet_url: &Url,
Expand Down Expand Up @@ -248,7 +264,15 @@ async fn perform_faucet_test(
///
/// The nonce that solves the challenge, or an error if no solution is found within reasonable
/// bounds.
#[instrument(target = COMPONENT, name = "solve-pow-challenge", skip_all, ret(level = "debug"))]
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.faucet.solve_pow_challenge",
skip_all,
level = "info",
ret(level = "debug"),
err
)]
fn solve_pow_challenge(challenge: &str, target: u64) -> anyhow::Result<u64> {
let challenge_bytes = hex::decode(challenge).context("Failed to decode challenge from hex")?;

Expand Down
53 changes: 48 additions & 5 deletions bin/network-monitor/src/monitor/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,21 @@ impl Tasks {
}

/// Spawn the RPC status checker task.
#[instrument(target = COMPONENT, name = "tasks.spawn-rpc-checker", skip_all)]
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.tasks.spawn_rpc_checker",
skip_all,
level = "info",
ret(level = "debug"),
err
)]
pub async fn spawn_rpc_checker(
&mut self,
config: &MonitorConfig,
) -> Result<Receiver<ServiceStatus>> {
debug!(target: COMPONENT, rpc_url = %config.rpc_url, "Spawning RPC status checker task");

// Create initial status for RPC service
let mut rpc = ClientBuilder::new(config.rpc_url.clone())
.with_tls()
Expand All @@ -74,15 +84,25 @@ impl Tasks {
.id();
self.names.insert(id, "rpc-checker".to_string());

debug!(target: COMPONENT, "RPC status checker task spawned successfully");
Ok(rpc_rx)
}

/// Spawn prover status and test tasks for all configured provers.
#[instrument(target = COMPONENT, name = "tasks.spawn-prover-tasks", skip_all)]
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.tasks.spawn_prover_tasks",
skip_all,
level = "info",
ret(level = "debug"),
err
)]
pub async fn spawn_prover_tasks(
&mut self,
config: &MonitorConfig,
) -> Result<Vec<(watch::Receiver<ServiceStatus>, watch::Receiver<ServiceStatus>)>> {
debug!(target: COMPONENT, prover_count = config.remote_prover_urls.len(), "Spawning prover tasks");
let mut prover_rxs = Vec::new();

for (i, prover_url) in config.remote_prover_urls.iter().enumerate() {
Expand Down Expand Up @@ -189,11 +209,19 @@ impl Tasks {
prover_rxs.push((prover_status_rx, prover_test_rx));
}

debug!(target: COMPONENT, spawned_provers = prover_rxs.len(), "All prover tasks spawned successfully");
Ok(prover_rxs)
}

/// Spawn the faucet testing task.
#[instrument(target = COMPONENT, name = "tasks.spawn-faucet", skip_all)]
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.tasks.spawn_faucet",
skip_all,
level = "info",
ret(level = "debug")
)]
pub fn spawn_faucet(&mut self, config: &MonitorConfig) -> Receiver<ServiceStatus> {
let current_time = current_unix_timestamp_secs();

Expand Down Expand Up @@ -231,7 +259,15 @@ impl Tasks {
}

/// Spawn the network transaction service checker tasks (increment and tracking).
#[instrument(target = COMPONENT, name = "tasks.spawn-ntx-service", skip_all)]
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.tasks.spawn_ntx_service",
skip_all,
level = "info",
ret(level = "debug"),
err
)]
pub async fn spawn_ntx_service(
&mut self,
config: &MonitorConfig,
Expand Down Expand Up @@ -306,7 +342,14 @@ impl Tasks {
}

/// Spawn the HTTP frontend server.
#[instrument(target = COMPONENT, name = "tasks.spawn-frontend", skip_all)]
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.tasks.spawn_http_server",
skip_all,
level = "info",
ret(level = "debug")
)]
pub fn spawn_http_server(&mut self, server_state: ServerState, config: &MonitorConfig) {
let config = config.clone();
let id = self.handles.spawn(async move { serve(server_state, config).await }).id();
Expand Down
35 changes: 33 additions & 2 deletions bin/network-monitor/src/remote_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ pub struct ProverTestDetails {
/// # Returns
///
/// `Ok(())` if the task completes successfully, or an error if the task fails.
#[instrument(target = COMPONENT, name = "remote-prover-test-task", skip_all)]
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.remote_prover.run_remote_prover_test_task",
skip_all,
level = "info",
ret(level = "debug")
)]
pub async fn run_remote_prover_test_task(
prover_url: Url,
name: &str,
Expand Down Expand Up @@ -153,7 +160,14 @@ pub async fn run_remote_prover_test_task(
/// # Returns
///
/// A `ServiceStatus` containing the results of the proof test.
#[instrument(target = COMPONENT, name = "test-remote-prover", skip_all, ret(level = "info"))]
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.remote_prover.test_remote_prover",
skip_all,
level = "info",
ret(level = "debug")
)]
async fn test_remote_prover(
client: &mut miden_node_proto::clients::RemoteProverClient,
name: &str,
Expand Down Expand Up @@ -256,6 +270,15 @@ fn tonic_status_to_json(status: &tonic::Status) -> String {
/// This function creates a mock transaction using `MockChainBuilder` similar to what's done
/// in the remote prover tests. The transaction is generated once and can be reused for
/// multiple proof test calls.
#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.remote_prover.generate_mock_transaction",
skip_all,
level = "info",
ret(level = "debug"),
err
)]
pub async fn generate_mock_transaction() -> anyhow::Result<TransactionInputs> {
let mut mock_chain_builder = MockChainBuilder::new();

Expand Down Expand Up @@ -303,6 +326,14 @@ pub async fn generate_mock_transaction() -> anyhow::Result<TransactionInputs> {
// GENERATE TEST REQUEST PAYLOAD
// ================================================================================================

#[instrument(
parent = None,
target = COMPONENT,
name = "network_monitor.remote_prover.generate_prover_test_payload",
skip_all,
level = "info",
ret(level = "debug")
)]
pub(crate) async fn generate_prover_test_payload() -> proto::remote_prover::ProofRequest {
proto::remote_prover::ProofRequest {
proof_type: proto::remote_prover::ProofType::Transaction.into(),
Expand Down
Loading