diff --git a/core/node/state_keeper/src/io/mempool.rs b/core/node/state_keeper/src/io/mempool.rs index fcaf85573ef..38bcdaad193 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, UnexecutableReason, }, @@ -65,10 +65,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 37171f195a8..6d44dd247c4 100644 --- a/core/node/state_keeper/src/keeper.rs +++ b/core/node/state_keeper/src/keeper.rs @@ -333,6 +333,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 @@ -341,6 +342,7 @@ impl ZkSyncStateKeeper { .await .context("error waiting for new L2 block params")? { + latency.observe(); return Ok(params); } } @@ -719,7 +721,7 @@ impl ZkSyncStateKeeper { } else { SealResolution::ExcludeAndSeal }; - AGGREGATION_METRICS.inc(criterion, &resolution); + AGGREGATION_METRICS.l1_batch_reason_inc(criterion, &resolution); resolution } TxExecutionResult::RejectedByVm { reason } => { diff --git a/core/node/state_keeper/src/metrics.rs b/core/node/state_keeper/src/metrics.rs index 0c72f9415b4..66c6e7933e8 100644 --- a/core/node/state_keeper/src/metrics.rs +++ b/core/node/state_keeper/src/metrics.rs @@ -101,6 +101,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, } fn vm_revert_reason_as_metric_label(reason: &VmRevertReason) -> &'static str { @@ -203,6 +206,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, @@ -213,10 +223,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()), @@ -224,13 +235,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 d29e66cd2b5..cd00d4f8936 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 c1c9e59e49c..505d9944149 100644 --- a/core/node/state_keeper/src/seal_criteria/mod.rs +++ b/core/node/state_keeper/src/seal_criteria/mod.rs @@ -243,7 +243,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",