signet-node 0.17.2

Core Signet rollup node: block processing, state management, and lifecycle orchestration
//! Metrics to track
//!
//! - Counters
//!   - Number of notifications received
//!   - Number of reorgs received
//!   - Number of notifications processed
//!   - Number of reorgs processed

use metrics::{Counter, counter, describe_counter};
use signet_node_types::HostNotification;
use std::sync::LazyLock;

const NOTIFICATION_RECEIVED: &str = "signet.node.notification_received";
const NOTIFICATION_RECEIVED_HELP: &str = "Number of notifications received";

const REORGS_RECEIVED: &str = "signet.node.reorgs_received";
const REORGS_RECEIVED_HELP: &str = "Number of reorgs received";

const NOTIFICATIONS_PROCESSED: &str = "signet.node.notifications_processed";
const NOTIFICATIONS_PROCESSED_HELP: &str = "Number of notifications processed";

const REORGS_PROCESSED: &str = "signet.node.reorgs_processed";
const REORGS_PROCESSED_HELP: &str = "Number of reorgs processed";

static DESCRIBE: LazyLock<()> = LazyLock::new(|| {
    describe_counter!(NOTIFICATION_RECEIVED, NOTIFICATION_RECEIVED_HELP);
    describe_counter!(REORGS_RECEIVED, REORGS_RECEIVED_HELP);
    describe_counter!(NOTIFICATIONS_PROCESSED, NOTIFICATIONS_PROCESSED_HELP);
    describe_counter!(REORGS_PROCESSED, REORGS_PROCESSED_HELP);
});

fn notifications_received() -> Counter {
    LazyLock::force(&DESCRIBE);
    counter!(NOTIFICATION_RECEIVED)
}

fn inc_notifications_received() {
    notifications_received().increment(1);
}

fn reorgs_received() -> Counter {
    LazyLock::force(&DESCRIBE);
    counter!(REORGS_RECEIVED)
}

fn inc_reorgs_received() {
    reorgs_received().increment(1);
}

fn notifications_processed() -> Counter {
    LazyLock::force(&DESCRIBE);
    counter!(NOTIFICATIONS_PROCESSED)
}

fn inc_notifications_processed() {
    notifications_processed().increment(1);
}

fn reorgs_processed() -> Counter {
    LazyLock::force(&DESCRIBE);
    counter!(REORGS_PROCESSED)
}

fn inc_reorgs_processed() {
    reorgs_processed().increment(1);
}

pub(crate) fn record_notification_received<C>(notification: &HostNotification<C>) {
    inc_notifications_received();
    if notification.revert_range().is_some() {
        inc_reorgs_received();
    }
}

pub(crate) fn record_notification_processed<C>(notification: &HostNotification<C>) {
    inc_notifications_processed();
    if notification.revert_range().is_some() {
        inc_reorgs_processed();
    }
}