mod.rs

Overview

This file serves as a central module aggregating several submodules related to node operation, tracing, metrics, and key handling functionalities. It provides initialization and shutdown utilities for tracing and metrics collection, implements tracing spans for block flow events, manages shutdown signaling for graceful termination, and offers utility functions such as temporary file path generation and file hashing.

Modules

Constants and Static Variables

Functions

verbose_filter() -> EnvFilter

Constructs a verbose logging filter for tracing_subscriber based on whether the feature flag "tvm_tracing" is enabled. It sets detailed trace-level logging for several components such as gossip, HTTP server, block manager, node, executor, network, TVM, builder, and others.

Returns:
An EnvFilter configured with component-specific log levels.


init_tracing() -> (Option<Metrics>, WorkerGuard)

Initializes the tracing and metrics systems with configuration derived from environment variables:

Usage Example:

let (metrics_opt, guard) = init_tracing();
// Use metrics_opt for metrics recording if present
// Keep 'guard' alive for the lifetime of tracing

Returns:


shutdown_tracing(tracing_guard: WorkerGuard)

Shuts down the tracing system gracefully.

Parameters:


init_tracer(endpoint: String) -> opentelemetry_sdk::trace::Tracer

Creates an OTLP tracer connected to the specified endpoint.

Parameters:

Returns:
An OTLP Tracer instance for trace span creation.


init_noop_tracer() -> NoopTracer

Sets and returns a no-operation tracer provider and tracer, used when no telemetry exporter is configured.

Returns:
A NoopTracer instance.


block_flow_trace<const N: usize>(name: impl AsRef<str>, block_id: &BlockIdentifier, node_id: &NodeIdentifier, fields: [(&str, &str); N])

Creates and immediately ends a tracing span for a block flow event with the given name and associated metadata.

Parameters:

Example Usage:

block_flow_trace(
    "processing",
    &block_id,
    &node_id,
    [("status", "started"), ("priority", "high")]
);

block_flow_trace_with_time<const N: usize>(time: Option<std::time::SystemTime>, name: impl AsRef<str>, block_id: &BlockIdentifier, node_id: &NodeIdentifier, fields: [(&str, &str); N])

Same as block_flow_trace but allows specifying an explicit start time for the span.

Parameters:


get_temp_file_path(parent_path: &Path) -> PathBuf

Generates a unique temporary file path within the specified directory.

Parameters:

Returns:
A PathBuf representing the unique temporary file path.


start_shutdown()

Initiates the shutdown procedure for the application.

This function ensures that all finalization loops complete before marking the shutdown as fully active.


calc_file_hash<P: AsRef<Path>>(path: P) -> anyhow::Result<String>

Computes the SHA-256 hash of the contents of a file.

Parameters:

Returns:

Example Usage:

let hash = calc_file_hash("path/to/file.txt")?;
println!("File hash: {}", hash);

Implementation Details

Interaction with Other System Components

Mermaid Diagram

flowchart TD
A[init_tracing] -->|returns| B[Metrics?, WorkerGuard]
A --> C[Setup tracing filters]
A --> D[Configure OTLP tracer if endpoint]
D --> E[init_tracer]
A --> F[Init metrics if endpoint]
G[shutdown_tracing] -->|uses| B
G --> H[Shutdown tracer provider]
G --> I[Drop WorkerGuard]
J[block_flow_trace] --> K[Create SpanBuilder]
J --> L[Set trace_id from BlockIdentifier]
J --> M["Set attributes (node, fields)"]
J --> N[Build and end span]
O[start_shutdown] --> P[Set SHUTDOWN_FINALIZATION_FLAG]
O --> Q[Wait for FINALIZATION_LOOPS_COUNTER == 0]
O --> R[Set SHUTDOWN_FLAG]
S[get_temp_file_path] --> T[Generate random tmp filename]
T --> U[Check if file exists]
U -->|exists| T
U -->|not exists| V[Return tmp file path]
W[calc_file_hash] --> X[Read file bytes]
X --> Y[Update Sha256 hasher]
Y --> Z[Return hex-encoded digest]