Skip to content
Closed
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
3 changes: 3 additions & 0 deletions crates/blockchain/src/key_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ impl KeyManager {
epoch: u32,
message: &H256,
) -> Result<XmssSignature, KeyManagerError> {
let start = std::time::Instant::now();

let secret_key = self
.keys
.get_mut(&validator_id)
Expand All @@ -109,6 +111,7 @@ impl KeyManager {
let xmss_sig = XmssSignature::try_from(sig_bytes)
.map_err(|e| KeyManagerError::SignatureConversionError(e.to_string()))?;

crate::metrics::observe_pq_sig_attestation_signing_time(start.elapsed().as_secs_f64());
Ok(xmss_sig)
}
}
Expand Down
203 changes: 203 additions & 0 deletions crates/blockchain/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,206 @@ pub fn set_node_start_time() {
.as_secs();
LEAN_NODE_START_TIME_SECONDS.set(timestamp as i64);
}

/// Increment the valid attestations counter.
pub fn inc_attestations_valid(source: &str) {
static LEAN_ATTESTATIONS_VALID_TOTAL: std::sync::LazyLock<prometheus::IntCounterVec> =
std::sync::LazyLock::new(|| {
prometheus::register_int_counter_vec!(
"lean_attestations_valid_total",
"Count of valid attestations",
&["source"]
)
.unwrap()
});
LEAN_ATTESTATIONS_VALID_TOTAL
.with_label_values(&[source])
.inc();
}

/// Increment the invalid attestations counter.
pub fn inc_attestations_invalid(source: &str) {
static LEAN_ATTESTATIONS_INVALID_TOTAL: std::sync::LazyLock<prometheus::IntCounterVec> =
std::sync::LazyLock::new(|| {
prometheus::register_int_counter_vec!(
"lean_attestations_invalid_total",
"Count of invalid attestations",
&["source"]
)
.unwrap()
});
LEAN_ATTESTATIONS_INVALID_TOTAL
.with_label_values(&[source])
.inc();
}

/// Increment the fork choice reorgs counter.
pub fn inc_fork_choice_reorgs() {
static LEAN_FORK_CHOICE_REORGS_TOTAL: std::sync::LazyLock<prometheus::IntCounter> =
std::sync::LazyLock::new(|| {
prometheus::register_int_counter!(
"lean_fork_choice_reorgs_total",
"Count of fork choice reorganizations"
)
.unwrap()
});
LEAN_FORK_CHOICE_REORGS_TOTAL.inc();
}

/// Increment the PQ aggregated signatures counter.
pub fn inc_pq_sig_aggregated_signatures() {
static LEAN_PQ_SIG_AGGREGATED_SIGNATURES_TOTAL: std::sync::LazyLock<prometheus::IntCounter> =
std::sync::LazyLock::new(|| {
prometheus::register_int_counter!(
"lean_pq_sig_aggregated_signatures_total",
"Count of aggregated signatures created"
)
.unwrap()
});
LEAN_PQ_SIG_AGGREGATED_SIGNATURES_TOTAL.inc();
}

/// Increment the attestations in aggregated signatures counter.
pub fn inc_pq_sig_attestations_in_aggregated_signatures(count: u64) {
static LEAN_PQ_SIG_ATTESTATIONS_IN_AGGREGATED_SIGNATURES_TOTAL: std::sync::LazyLock<
prometheus::IntCounter,
> = std::sync::LazyLock::new(|| {
prometheus::register_int_counter!(
"lean_pq_sig_attestations_in_aggregated_signatures_total",
"Count of attestations included in aggregated signatures"
)
.unwrap()
});
LEAN_PQ_SIG_ATTESTATIONS_IN_AGGREGATED_SIGNATURES_TOTAL.inc_by(count);
}

/// Increment the valid aggregated signatures counter.
pub fn inc_pq_sig_aggregated_signatures_valid() {
static LEAN_PQ_SIG_AGGREGATED_SIGNATURES_VALID_TOTAL: std::sync::LazyLock<
prometheus::IntCounter,
> = std::sync::LazyLock::new(|| {
prometheus::register_int_counter!(
"lean_pq_sig_aggregated_signatures_valid_total",
"Count of valid aggregated signatures"
)
.unwrap()
});
LEAN_PQ_SIG_AGGREGATED_SIGNATURES_VALID_TOTAL.inc();
}

/// Increment the invalid aggregated signatures counter.
pub fn inc_pq_sig_aggregated_signatures_invalid() {
static LEAN_PQ_SIG_AGGREGATED_SIGNATURES_INVALID_TOTAL: std::sync::LazyLock<
prometheus::IntCounter,
> = std::sync::LazyLock::new(|| {
prometheus::register_int_counter!(
"lean_pq_sig_aggregated_signatures_invalid_total",
"Count of invalid aggregated signatures"
)
.unwrap()
});
LEAN_PQ_SIG_AGGREGATED_SIGNATURES_INVALID_TOTAL.inc();
}

/// Record block processing time in seconds.
pub fn observe_fork_choice_block_processing_time(duration_secs: f64) {
static LEAN_FORK_CHOICE_BLOCK_PROCESSING_TIME_SECONDS: std::sync::LazyLock<
prometheus::Histogram,
> = std::sync::LazyLock::new(|| {
prometheus::register_histogram!(
"lean_fork_choice_block_processing_time_seconds",
"Duration to process a block",
vec![0.005, 0.01, 0.025, 0.05, 0.1, 1.0]
)
.unwrap()
});
LEAN_FORK_CHOICE_BLOCK_PROCESSING_TIME_SECONDS.observe(duration_secs);
}

/// Record attestation validation time in seconds.
pub fn observe_attestation_validation_time(duration_secs: f64) {
static LEAN_ATTESTATION_VALIDATION_TIME_SECONDS: std::sync::LazyLock<prometheus::Histogram> =
std::sync::LazyLock::new(|| {
prometheus::register_histogram!(
"lean_attestation_validation_time_seconds",
"Duration to validate an attestation",
vec![0.005, 0.01, 0.025, 0.05, 0.1, 1.0]
)
.unwrap()
});
LEAN_ATTESTATION_VALIDATION_TIME_SECONDS.observe(duration_secs);
}

/// Record fork choice reorg depth.
pub fn observe_fork_choice_reorg_depth(depth: u64) {
static LEAN_FORK_CHOICE_REORG_DEPTH: std::sync::LazyLock<prometheus::Histogram> =
std::sync::LazyLock::new(|| {
prometheus::register_histogram!(
"lean_fork_choice_reorg_depth",
"Depth of reorganizations in blocks",
vec![1.0, 2.0, 3.0, 5.0, 7.0, 10.0, 20.0, 30.0, 50.0, 100.0]
)
.unwrap()
});
LEAN_FORK_CHOICE_REORG_DEPTH.observe(depth as f64);
}

/// Record attestation signing time in seconds.
pub fn observe_pq_sig_attestation_signing_time(duration_secs: f64) {
static LEAN_PQ_SIG_ATTESTATION_SIGNING_TIME_SECONDS: std::sync::LazyLock<
prometheus::Histogram,
> = std::sync::LazyLock::new(|| {
prometheus::register_histogram!(
"lean_pq_sig_attestation_signing_time_seconds",
"Duration to sign an attestation",
vec![0.005, 0.01, 0.025, 0.05, 0.1, 1.0]
)
.unwrap()
});
LEAN_PQ_SIG_ATTESTATION_SIGNING_TIME_SECONDS.observe(duration_secs);
}

/// Record attestation verification time in seconds.
pub fn observe_pq_sig_attestation_verification_time(duration_secs: f64) {
static LEAN_PQ_SIG_ATTESTATION_VERIFICATION_TIME_SECONDS: std::sync::LazyLock<
prometheus::Histogram,
> = std::sync::LazyLock::new(|| {
prometheus::register_histogram!(
"lean_pq_sig_attestation_verification_time_seconds",
"Duration to verify an attestation signature",
vec![0.005, 0.01, 0.025, 0.05, 0.1, 1.0]
)
.unwrap()
});
LEAN_PQ_SIG_ATTESTATION_VERIFICATION_TIME_SECONDS.observe(duration_secs);
}

/// Record attestation signatures building time in seconds.
pub fn observe_pq_sig_attestation_signatures_building_time(duration_secs: f64) {
static LEAN_PQ_SIG_ATTESTATION_SIGNATURES_BUILDING_TIME_SECONDS: std::sync::LazyLock<
prometheus::Histogram,
> = std::sync::LazyLock::new(|| {
prometheus::register_histogram!(
"lean_pq_sig_attestation_signatures_building_time_seconds",
"Duration to build attestation signatures",
vec![0.005, 0.01, 0.025, 0.05, 0.1, 1.0]
)
.unwrap()
});
LEAN_PQ_SIG_ATTESTATION_SIGNATURES_BUILDING_TIME_SECONDS.observe(duration_secs);
}

/// Record aggregated signatures verification time in seconds.
pub fn observe_pq_sig_aggregated_signatures_verification_time(duration_secs: f64) {
static LEAN_PQ_SIG_AGGREGATED_SIGNATURES_VERIFICATION_TIME_SECONDS: std::sync::LazyLock<
prometheus::Histogram,
> = std::sync::LazyLock::new(|| {
prometheus::register_histogram!(
"lean_pq_sig_aggregated_signatures_verification_time_seconds",
"Duration to verify aggregated signatures",
vec![0.005, 0.01, 0.025, 0.05, 0.1, 1.0]
)
.unwrap()
});
LEAN_PQ_SIG_AGGREGATED_SIGNATURES_VERIFICATION_TIME_SECONDS.observe(duration_secs);
}
Loading