diff --git a/core/node/state_keeper/src/io/mempool.rs b/core/node/state_keeper/src/io/mempool.rs index 8d44e38cc6ee..71352d9b5b5d 100644 --- a/core/node/state_keeper/src/io/mempool.rs +++ b/core/node/state_keeper/src/io/mempool.rs @@ -28,7 +28,7 @@ use crate::{ L1BatchParams, L2BlockParams, PendingBatchData, StateKeeperIO, }, mempool_actor::l2_tx_filter, - metrics::KEEPER_METRICS, + metrics::{L2BlockSealReason, AGGREGATION_METRICS, KEEPER_METRICS}, seal_criteria::{IoSealCriteria, L2BlockMaxPayloadSizeSealer, TimeoutSealer}, updates::UpdatesManager, MempoolGuard, @@ -63,10 +63,19 @@ impl IoSealCriteria for MempoolIO { fn should_seal_l2_block(&mut self, manager: &UpdatesManager) -> bool { if self.timeout_sealer.should_seal_l2_block(manager) { + AGGREGATION_METRICS.l2_block_reason_inc(&L2BlockSealReason::Timeout); return true; } - self.l2_block_max_payload_size_sealer + + if self + .l2_block_max_payload_size_sealer .should_seal_l2_block(manager) + { + AGGREGATION_METRICS.l2_block_reason_inc(&L2BlockSealReason::PayloadSize); + return true; + } + + false } } diff --git a/core/node/state_keeper/src/keeper.rs b/core/node/state_keeper/src/keeper.rs index c2b49f47a90a..21ac54a93819 100644 --- a/core/node/state_keeper/src/keeper.rs +++ b/core/node/state_keeper/src/keeper.rs @@ -332,6 +332,7 @@ impl ZkSyncStateKeeper { &mut self, updates: &UpdatesManager, ) -> Result { + let latency = KEEPER_METRICS.wait_for_l2_block_params.start(); let cursor = updates.io_cursor(); while !self.is_canceled() { if let Some(params) = self @@ -340,6 +341,7 @@ impl ZkSyncStateKeeper { .await .context("error waiting for new L2 block params")? { + latency.observe(); return Ok(params); } } @@ -712,7 +714,7 @@ impl ZkSyncStateKeeper { } else { SealResolution::ExcludeAndSeal }; - AGGREGATION_METRICS.inc(error_message, &resolution); + AGGREGATION_METRICS.l1_batch_reason_inc(error_message, &resolution); resolution } TxExecutionResult::RejectedByVm { reason } => { diff --git a/core/node/state_keeper/src/metrics.rs b/core/node/state_keeper/src/metrics.rs index cad02a4b0cba..7d33f9a841f2 100644 --- a/core/node/state_keeper/src/metrics.rs +++ b/core/node/state_keeper/src/metrics.rs @@ -87,6 +87,9 @@ pub struct StateKeeperMetrics { /// The time it takes for one iteration of the main loop in `process_l1_batch`. #[metrics(buckets = Buckets::LATENCIES)] pub process_l1_batch_loop_iteration: Histogram, + /// The time it takes to wait for new L2 block parameters + #[metrics(buckets = Buckets::LATENCIES)] + pub wait_for_l2_block_params: Histogram, } #[vise::register] @@ -151,6 +154,13 @@ impl From<&SealResolution> for SealResolutionLabel { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet, EncodeLabelValue)] +#[metrics(label = "reason", rename_all = "snake_case")] +pub(super) enum L2BlockSealReason { + Timeout, + PayloadSize, +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet)] struct TxAggregationLabels { criterion: &'static str, @@ -161,10 +171,11 @@ struct TxAggregationLabels { #[metrics(prefix = "server_tx_aggregation")] pub(super) struct TxAggregationMetrics { reason: Family, + l2_block_reason: Family, } impl TxAggregationMetrics { - pub fn inc(&self, criterion: &'static str, resolution: &SealResolution) { + pub fn l1_batch_reason_inc(&self, criterion: &'static str, resolution: &SealResolution) { let labels = TxAggregationLabels { criterion, seal_resolution: Some(resolution.into()), @@ -172,13 +183,17 @@ impl TxAggregationMetrics { self.reason[&labels].inc(); } - pub fn inc_criterion(&self, criterion: &'static str) { + pub fn l1_batch_reason_inc_criterion(&self, criterion: &'static str) { let labels = TxAggregationLabels { criterion, seal_resolution: None, }; self.reason[&labels].inc(); } + + pub fn l2_block_reason_inc(&self, reason: &L2BlockSealReason) { + self.l2_block_reason[reason].inc(); + } } #[vise::register] diff --git a/core/node/state_keeper/src/seal_criteria/conditional_sealer.rs b/core/node/state_keeper/src/seal_criteria/conditional_sealer.rs index d29e66cd2b5b..cd00d4f89360 100644 --- a/core/node/state_keeper/src/seal_criteria/conditional_sealer.rs +++ b/core/node/state_keeper/src/seal_criteria/conditional_sealer.rs @@ -103,7 +103,8 @@ impl ConditionalSealer for SequencerSealer { "L1 batch #{l1_batch_number} processed by `{name}` with resolution {seal_resolution:?}", name = sealer.prom_criterion_name() ); - AGGREGATION_METRICS.inc(sealer.prom_criterion_name(), &seal_resolution); + AGGREGATION_METRICS + .l1_batch_reason_inc(sealer.prom_criterion_name(), &seal_resolution); } SealResolution::NoSeal => { /* Don't do anything */ } } diff --git a/core/node/state_keeper/src/seal_criteria/mod.rs b/core/node/state_keeper/src/seal_criteria/mod.rs index 51ad1c4ad906..d309c6c20203 100644 --- a/core/node/state_keeper/src/seal_criteria/mod.rs +++ b/core/node/state_keeper/src/seal_criteria/mod.rs @@ -165,7 +165,7 @@ impl IoSealCriteria for TimeoutSealer { millis_since(manager.batch_timestamp()) > block_commit_deadline_ms; if should_seal_timeout { - AGGREGATION_METRICS.inc_criterion(RULE_NAME); + AGGREGATION_METRICS.l1_batch_reason_inc_criterion(RULE_NAME); tracing::debug!( "Decided to seal L1 batch using rule `{RULE_NAME}`; batch timestamp: {}, \ commit deadline: {block_commit_deadline_ms}ms",