From 64459b2383a344b558ae648743c3f7d91c1b24c0 Mon Sep 17 00:00:00 2001 From: perekopskiy <53865202+perekopskiy@users.noreply.github.com> Date: Wed, 11 Oct 2023 20:29:51 +0300 Subject: [PATCH] fix(state-keeper): Add L2ToL1LogsCriterion (#195) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # What ❔ Added L1 batch seal criterion for number of L2 to L1 logs ## Why ❔ Number of logs must be <= 512 per batch. ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. --- .../seal_criteria/conditional_sealer.rs | 1 + .../criteria/geometry_seal_criteria.rs | 19 +++++++++++++++++++ .../seal_criteria/criteria/mod.rs | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/lib/zksync_core/src/state_keeper/seal_criteria/conditional_sealer.rs b/core/lib/zksync_core/src/state_keeper/seal_criteria/conditional_sealer.rs index 3fc378bcb6b..1c83f7d036f 100644 --- a/core/lib/zksync_core/src/state_keeper/seal_criteria/conditional_sealer.rs +++ b/core/lib/zksync_core/src/state_keeper/seal_criteria/conditional_sealer.rs @@ -101,6 +101,7 @@ impl ConditionalSealer { Box::new(criteria::MaxCyclesCriterion), Box::new(criteria::ComputationalGasCriterion), Box::new(criteria::TxEncodingSizeCriterion), + Box::new(criteria::L2ToL1LogsCriterion), ] } } diff --git a/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/geometry_seal_criteria.rs b/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/geometry_seal_criteria.rs index 6e5224f4032..5250ab98bb1 100644 --- a/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/geometry_seal_criteria.rs +++ b/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/geometry_seal_criteria.rs @@ -20,6 +20,8 @@ pub struct InitialWritesCriterion; pub struct MaxCyclesCriterion; #[derive(Debug, Default)] pub struct ComputationalGasCriterion; +#[derive(Debug, Default)] +pub struct L2ToL1LogsCriterion; trait MetricExtractor { const PROM_METRIC_CRITERION_NAME: &'static str; @@ -119,6 +121,18 @@ impl MetricExtractor for ComputationalGasCriterion { } } +impl MetricExtractor for L2ToL1LogsCriterion { + const PROM_METRIC_CRITERION_NAME: &'static str = "l2_to_l1_logs"; + + fn limit_per_block() -> usize { + GEOMETRY_CONFIG.limit_for_l1_messages_merklizer as usize + } + + fn extract(metrics: &ExecutionMetrics, _writes: &DeduplicatedWritesMetrics) -> usize { + metrics.l2_l1_logs + } +} + #[cfg(test)] mod tests { use super::*; @@ -322,4 +336,9 @@ mod tests { fn computational_gas_seal_criterion() { test_scenario_execution_metrics!(ComputationalGasCriterion, computational_gas_used, u32); } + + #[test] + fn l2_to_l1_logs_seal_criterion() { + test_scenario_execution_metrics!(L2ToL1LogsCriterion, l2_l1_logs, usize); + } } diff --git a/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/mod.rs b/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/mod.rs index 39b7165d99d..8e0d89e8e0f 100644 --- a/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/mod.rs @@ -7,7 +7,7 @@ mod tx_encoding_size; pub(in crate::state_keeper) use self::{ gas::GasCriterion, geometry_seal_criteria::{ - ComputationalGasCriterion, InitialWritesCriterion, MaxCyclesCriterion, + ComputationalGasCriterion, InitialWritesCriterion, L2ToL1LogsCriterion, MaxCyclesCriterion, RepeatedWritesCriterion, }, pubdata_bytes::PubDataBytesCriterion,