From f763d1f193bac0dcdc367c8566b31d8384fe0651 Mon Sep 17 00:00:00 2001 From: AnastasiiaVashchuk <72273339+AnastasiiaVashchuk@users.noreply.github.com> Date: Fri, 12 Apr 2024 17:31:28 +0300 Subject: [PATCH] feat: Extract commitment generator into a separate crate (#1636) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ Extract `zksync_core::commitment_generator` to separate the crate in the node folder Put `zksync_commitment_utils` to `zksync_commitment_generator ` (reason: utils are used only by generator) ## Why ❔ Part of the "modularize the codebase" process, required for legolizer and publishing on crates.io. ## Checklist - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`. - [ ] Spellcheck has been run via `zk spellcheck`. - [ ] Linkcheck has been run via `zk linkcheck`. --- Cargo.lock | 15 +++++++++++++-- Cargo.toml | 4 ++-- core/bin/external_node/Cargo.toml | 1 + core/bin/external_node/src/main.rs | 2 +- core/lib/zksync_core/Cargo.toml | 2 +- core/lib/zksync_core/src/lib.rs | 3 +-- .../commitment_generator}/Cargo.toml | 15 +++++++++++++-- core/node/commitment_generator/README.md | 4 ++++ .../commitment_generator/src/lib.rs} | 8 ++++++-- .../commitment_generator/src}/metrics.rs | 0 .../commitment_generator/src/utils.rs} | 0 core/node/node_framework/Cargo.toml | 1 + .../layers/commitment_generator.rs | 2 +- 13 files changed, 44 insertions(+), 13 deletions(-) rename core/{lib/commitment_utils => node/commitment_generator}/Cargo.toml (62%) create mode 100644 core/node/commitment_generator/README.md rename core/{lib/zksync_core/src/commitment_generator/mod.rs => node/commitment_generator/src/lib.rs} (98%) rename core/{lib/zksync_core/src/commitment_generator => node/commitment_generator/src}/metrics.rs (100%) rename core/{lib/commitment_utils/src/lib.rs => node/commitment_generator/src/utils.rs} (100%) diff --git a/Cargo.lock b/Cargo.lock index f0ee6540d8a..8c7b736c578 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8123,16 +8123,25 @@ dependencies = [ ] [[package]] -name = "zksync_commitment_utils" +name = "zksync_commitment_generator" version = "0.1.0" dependencies = [ + "anyhow", "circuit_sequencer_api 0.1.40", "circuit_sequencer_api 0.1.41", "circuit_sequencer_api 0.1.50", + "itertools 0.10.5", "multivm", + "serde_json", + "tokio", + "tracing", + "vise", "zk_evm 1.3.3 (git+https://github.com/matter-labs/era-zk_evm.git?tag=v1.3.3-rc2)", "zk_evm 1.4.1", "zk_evm 1.5.0", + "zksync_dal", + "zksync_health_check", + "zksync_l1_contract_interface", "zksync_types", "zksync_utils", ] @@ -8400,7 +8409,7 @@ dependencies = [ "vlog", "vm_utils", "zksync_circuit_breaker", - "zksync_commitment_utils", + "zksync_commitment_generator", "zksync_concurrency", "zksync_config", "zksync_consensus_bft", @@ -8608,6 +8617,7 @@ dependencies = [ "vise", "vlog", "zksync_basic_types", + "zksync_commitment_generator", "zksync_concurrency", "zksync_config", "zksync_consensus_roles", @@ -8722,6 +8732,7 @@ dependencies = [ "tracing", "vlog", "zksync_circuit_breaker", + "zksync_commitment_generator", "zksync_concurrency", "zksync_config", "zksync_contracts", diff --git a/Cargo.toml b/Cargo.toml index 1216fc810a2..8aa37038e30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ members = [ "core/bin/genesis_generator", # Node services "core/node/node_framework", + "core/node/commitment_generator", # Libraries "core/lib/db_connection", "core/lib/zksync_core", @@ -21,7 +22,6 @@ members = [ "core/lib/contracts", "core/lib/crypto", "core/lib/circuit_breaker", - "core/lib/commitment_utils", "core/lib/dal", "core/lib/env_config", "core/lib/eth_client", @@ -191,7 +191,6 @@ vm-benchmark-harness = { path = "core/tests/vm-benchmark/harness" } zksync = { path = "sdk/zksync-rs" } zksync_basic_types = { path = "core/lib/basic_types" } zksync_circuit_breaker = { path = "core/lib/circuit_breaker" } -zksync_commitment_utils = { path = "core/lib/commitment_utils" } zksync_config = { path = "core/lib/config" } zksync_contracts = { path = "core/lib/contracts" } zksync_core = { path = "core/lib/zksync_core" } @@ -224,3 +223,4 @@ zksync_crypto_primitives = { path = "core/lib/crypto_primitives" } zksync_node_framework = { path = "core/node/node_framework" } zksync_eth_watch = { path = "core/node/eth_watch" } zksync_shared_metrics = { path = "core/node/shared_metrics" } +zksync_commitment_generator = { path = "core/node/commitment_generator" } diff --git a/core/bin/external_node/Cargo.toml b/core/bin/external_node/Cargo.toml index b447d649190..d0f653abdb3 100644 --- a/core/bin/external_node/Cargo.toml +++ b/core/bin/external_node/Cargo.toml @@ -12,6 +12,7 @@ publish = false [dependencies] zksync_core.workspace = true +zksync_commitment_generator.workspace = true zksync_dal.workspace = true zksync_db_connection.workspace = true zksync_config.workspace = true diff --git a/core/bin/external_node/src/main.rs b/core/bin/external_node/src/main.rs index adc5f116557..074ae97388b 100644 --- a/core/bin/external_node/src/main.rs +++ b/core/bin/external_node/src/main.rs @@ -8,6 +8,7 @@ use tokio::{ sync::{watch, RwLock}, task::{self, JoinHandle}, }; +use zksync_commitment_generator::CommitmentGenerator; use zksync_concurrency::{ctx, scope}; use zksync_config::configs::{ api::MerkleTreeApiConfig, chain::L1BatchCommitDataGeneratorMode, database::MerkleTreeMode, @@ -21,7 +22,6 @@ use zksync_core::{ web3::{mempool_cache::MempoolCache, ApiBuilder, Namespace}, }, block_reverter::{BlockReverter, BlockReverterFlags, L1ExecutedBatchesRevert, NodeRole}, - commitment_generator::CommitmentGenerator, consensus, consistency_checker::ConsistencyChecker, db_pruner::{ diff --git a/core/lib/zksync_core/Cargo.toml b/core/lib/zksync_core/Cargo.toml index 0ed908204b4..62c75ef3e8f 100644 --- a/core/lib/zksync_core/Cargo.toml +++ b/core/lib/zksync_core/Cargo.toml @@ -24,7 +24,6 @@ zksync_protobuf_config.workspace = true zksync_utils.workspace = true zksync_contracts.workspace = true zksync_system_constants.workspace = true -zksync_commitment_utils.workspace = true zksync_eth_client.workspace = true zksync_eth_signer.workspace = true zksync_l1_contract_interface.workspace = true @@ -45,6 +44,7 @@ zksync_health_check.workspace = true vlog.workspace = true zksync_eth_watch.workspace = true zksync_shared_metrics.workspace = true +zksync_commitment_generator.workspace = true multivm.workspace = true diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index d1594d6a910..609346f40cf 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -21,6 +21,7 @@ use zksync_circuit_breaker::{ l1_txs::FailedL1TransactionChecker, replication_lag::ReplicationLagChecker, CircuitBreakerChecker, CircuitBreakers, }; +use zksync_commitment_generator::CommitmentGenerator; use zksync_concurrency::{ctx, scope}; use zksync_config::{ configs::{ @@ -62,7 +63,6 @@ use crate::{ web3::{self, mempool_cache::MempoolCache, state::InternalApiConfig, Namespace}, }, basic_witness_input_producer::BasicWitnessInputProducer, - commitment_generator::CommitmentGenerator, eth_sender::{ l1_batch_commit_data_generator::{ L1BatchCommitDataGenerator, RollupModeL1BatchCommitDataGenerator, @@ -99,7 +99,6 @@ use crate::{ pub mod api_server; pub mod basic_witness_input_producer; pub mod block_reverter; -pub mod commitment_generator; pub mod consensus; pub mod consistency_checker; pub mod db_pruner; diff --git a/core/lib/commitment_utils/Cargo.toml b/core/node/commitment_generator/Cargo.toml similarity index 62% rename from core/lib/commitment_utils/Cargo.toml rename to core/node/commitment_generator/Cargo.toml index b3d8e74b2fa..a15266c7a67 100644 --- a/core/lib/commitment_utils/Cargo.toml +++ b/core/node/commitment_generator/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "zksync_commitment_utils" +name = "zksync_commitment_generator" version = "0.1.0" edition.workspace = true authors.workspace = true @@ -10,8 +10,13 @@ keywords.workspace = true categories.workspace = true [dependencies] +vise.workspace = true zksync_types.workspace = true +zksync_dal.workspace = true +zksync_health_check.workspace = true +zksync_l1_contract_interface.workspace = true zksync_utils.workspace = true +multivm.workspace = true circuit_sequencer_api_1_4_0.workspace = true circuit_sequencer_api_1_4_1.workspace = true circuit_sequencer_api_1_5_0.workspace = true @@ -19,4 +24,10 @@ circuit_sequencer_api_1_5_0.workspace = true zk_evm_1_5_0.workspace = true zk_evm_1_4_1.workspace = true zk_evm_1_3_3.workspace = true -multivm.workspace = true + +tokio = { workspace = true, features = ["time"] } +anyhow.workspace = true +tracing.workspace = true +itertools.workspace = true +serde_json.workspace = true + diff --git a/core/node/commitment_generator/README.md b/core/node/commitment_generator/README.md new file mode 100644 index 00000000000..da99ca9403a --- /dev/null +++ b/core/node/commitment_generator/README.md @@ -0,0 +1,4 @@ +# zkSync Era commitment generator + +This crate contains an implementation of the zkSync Era commitment generator component, which is responsible for the +calculation commitment info for L1 batches. diff --git a/core/lib/zksync_core/src/commitment_generator/mod.rs b/core/node/commitment_generator/src/lib.rs similarity index 98% rename from core/lib/zksync_core/src/commitment_generator/mod.rs rename to core/node/commitment_generator/src/lib.rs index 266b9a5cde1..5b1ccbb2bc1 100644 --- a/core/lib/zksync_core/src/commitment_generator/mod.rs +++ b/core/node/commitment_generator/src/lib.rs @@ -2,10 +2,8 @@ use std::time::Duration; use anyhow::Context; use itertools::Itertools; -use metrics::{CommitmentStage, METRICS}; use multivm::zk_evm_latest::ethereum_types::U256; use tokio::{sync::watch, task::JoinHandle}; -use zksync_commitment_utils::{bootloader_initial_content_commitment, events_queue_commitment}; use zksync_dal::{ConnectionPool, Core, CoreDal}; use zksync_health_check::{Health, HealthStatus, HealthUpdater, ReactiveHealthCheck}; use zksync_l1_contract_interface::i_executor::commit::kzg::pubdata_to_blob_commitments; @@ -18,7 +16,13 @@ use zksync_types::{ }; use zksync_utils::h256_to_u256; +use crate::{ + metrics::{CommitmentStage, METRICS}, + utils::{bootloader_initial_content_commitment, events_queue_commitment}, +}; + mod metrics; +mod utils; const SLEEP_INTERVAL: Duration = Duration::from_millis(100); diff --git a/core/lib/zksync_core/src/commitment_generator/metrics.rs b/core/node/commitment_generator/src/metrics.rs similarity index 100% rename from core/lib/zksync_core/src/commitment_generator/metrics.rs rename to core/node/commitment_generator/src/metrics.rs diff --git a/core/lib/commitment_utils/src/lib.rs b/core/node/commitment_generator/src/utils.rs similarity index 100% rename from core/lib/commitment_utils/src/lib.rs rename to core/node/commitment_generator/src/utils.rs diff --git a/core/node/node_framework/Cargo.toml b/core/node/node_framework/Cargo.toml index 1b8341bf1ae..10011443fdb 100644 --- a/core/node/node_framework/Cargo.toml +++ b/core/node/node_framework/Cargo.toml @@ -29,6 +29,7 @@ zksync_utils.workspace = true zksync_circuit_breaker.workspace = true zksync_concurrency.workspace = true zksync_eth_watch.workspace = true +zksync_commitment_generator.workspace = true tracing.workspace = true thiserror.workspace = true diff --git a/core/node/node_framework/src/implementations/layers/commitment_generator.rs b/core/node/node_framework/src/implementations/layers/commitment_generator.rs index 583996a1bcd..9dbb7b7a4c6 100644 --- a/core/node/node_framework/src/implementations/layers/commitment_generator.rs +++ b/core/node/node_framework/src/implementations/layers/commitment_generator.rs @@ -1,4 +1,4 @@ -use zksync_core::commitment_generator::CommitmentGenerator; +use zksync_commitment_generator::CommitmentGenerator; use crate::{ implementations::resources::{healthcheck::AppHealthCheckResource, pools::MasterPoolResource},