diff --git a/Cargo.lock b/Cargo.lock index 548e0368ef91..20b72299e3b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8239,6 +8239,7 @@ dependencies = [ "zksync_db_connection", "zksync_eth_client", "zksync_eth_signer", + "zksync_eth_watch", "zksync_health_check", "zksync_l1_contract_interface", "zksync_mempool", @@ -8249,6 +8250,7 @@ dependencies = [ "zksync_protobuf_build", "zksync_prover_interface", "zksync_queued_job_processor", + "zksync_shared_metrics", "zksync_state", "zksync_storage", "zksync_system_constants", @@ -8390,6 +8392,26 @@ dependencies = [ "zksync_types", ] +[[package]] +name = "zksync_eth_watch" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "metrics", + "thiserror", + "tokio", + "tracing", + "vise", + "zksync_config", + "zksync_contracts", + "zksync_dal", + "zksync_eth_client", + "zksync_shared_metrics", + "zksync_system_constants", + "zksync_types", +] + [[package]] name = "zksync_external_node" version = "0.1.0" @@ -8529,6 +8551,7 @@ dependencies = [ "zksync_db_connection", "zksync_env_config", "zksync_eth_client", + "zksync_eth_watch", "zksync_health_check", "zksync_object_store", "zksync_state", @@ -8666,6 +8689,15 @@ dependencies = [ "zksync_utils", ] +[[package]] +name = "zksync_shared_metrics" +version = "0.1.0" +dependencies = [ + "vise", + "zksync_dal", + "zksync_types", +] + [[package]] name = "zksync_snapshots_applier" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index f95f61117a38..a009a3735e48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -213,3 +213,8 @@ zksync_types = { path = "core/lib/types" } zksync_utils = { path = "core/lib/utils" } zksync_web3_decl = { path = "core/lib/web3_decl" } zksync_crypto_primitives = { path = "core/lib/crypto_primitives" } + +# Framework and components +zksync_node_framework = { path = "core/node/node_framework" } +zksync_eth_watch = { path = "core/node/eth_watch" } +zksync_shared_metrics = { path = "core/node/shared_metrics" } diff --git a/core/lib/zksync_core/Cargo.toml b/core/lib/zksync_core/Cargo.toml index d3d21334e77d..a70c63178a3f 100644 --- a/core/lib/zksync_core/Cargo.toml +++ b/core/lib/zksync_core/Cargo.toml @@ -42,6 +42,8 @@ zksync_web3_decl = { workspace = true, features = [ zksync_object_store.workspace = true zksync_health_check.workspace = true vlog.workspace = true +zksync_eth_watch.workspace = true +zksync_shared_metrics.workspace = true multivm.workspace = true diff --git a/core/lib/zksync_core/src/api_server/execution_sandbox/vm_metrics.rs b/core/lib/zksync_core/src/api_server/execution_sandbox/vm_metrics.rs index 63abec652830..d2caa11288aa 100644 --- a/core/lib/zksync_core/src/api_server/execution_sandbox/vm_metrics.rs +++ b/core/lib/zksync_core/src/api_server/execution_sandbox/vm_metrics.rs @@ -2,6 +2,7 @@ use std::time::Duration; use multivm::interface::{VmExecutionResultAndLogs, VmMemoryMetrics}; use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics}; +use zksync_shared_metrics::InteractionType; use zksync_state::StorageViewMetrics; use zksync_types::{ event::{extract_long_l2_to_l1_messages, extract_published_bytecodes}, @@ -10,8 +11,6 @@ use zksync_types::{ }; use zksync_utils::bytecode::bytecode_len_in_bytes; -use crate::metrics::InteractionType; - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "type", rename_all = "snake_case")] enum SizeType { diff --git a/core/lib/zksync_core/src/api_server/tx_sender/master_pool_sink.rs b/core/lib/zksync_core/src/api_server/tx_sender/master_pool_sink.rs index 48501e4aec3e..b65a0aa81498 100644 --- a/core/lib/zksync_core/src/api_server/tx_sender/master_pool_sink.rs +++ b/core/lib/zksync_core/src/api_server/tx_sender/master_pool_sink.rs @@ -2,13 +2,11 @@ use std::collections::hash_map::{Entry, HashMap}; use tokio::sync::Mutex; use zksync_dal::{transactions_dal::L2TxSubmissionResult, ConnectionPool, Core, CoreDal}; +use zksync_shared_metrics::{TxStage, APP_METRICS}; use zksync_types::{fee::TransactionExecutionMetrics, l2::L2Tx, Address, Nonce, H256}; use super::{tx_sink::TxSink, SubmitTxError}; -use crate::{ - api_server::web3::metrics::API_METRICS, - metrics::{TxStage, APP_METRICS}, -}; +use crate::api_server::web3::metrics::API_METRICS; /// Wrapper for the master DB pool that allows to submit transactions to the mempool. #[derive(Debug)] diff --git a/core/lib/zksync_core/src/api_server/tx_sender/proxy.rs b/core/lib/zksync_core/src/api_server/tx_sender/proxy.rs index 5877ce71abd6..8379c719e672 100644 --- a/core/lib/zksync_core/src/api_server/tx_sender/proxy.rs +++ b/core/lib/zksync_core/src/api_server/tx_sender/proxy.rs @@ -7,6 +7,7 @@ use std::{ use tokio::sync::{watch, RwLock}; use zksync_dal::{transactions_dal::L2TxSubmissionResult, ConnectionPool, Core, CoreDal}; +use zksync_shared_metrics::{TxStage, APP_METRICS}; use zksync_types::{ api::{BlockId, Transaction, TransactionDetails, TransactionId}, fee::TransactionExecutionMetrics, @@ -20,7 +21,6 @@ use zksync_web3_decl::{ }; use super::{tx_sink::TxSink, SubmitTxError}; -use crate::metrics::{TxStage, APP_METRICS}; #[derive(Debug, Clone, Default)] pub(crate) struct TxCache { diff --git a/core/lib/zksync_core/src/consistency_checker/mod.rs b/core/lib/zksync_core/src/consistency_checker/mod.rs index 63d54321cd14..60793af649ff 100644 --- a/core/lib/zksync_core/src/consistency_checker/mod.rs +++ b/core/lib/zksync_core/src/consistency_checker/mod.rs @@ -8,6 +8,7 @@ use zksync_dal::{Connection, ConnectionPool, Core, CoreDal}; use zksync_eth_client::{CallFunctionArgs, Error as L1ClientError, EthInterface}; use zksync_health_check::{Health, HealthStatus, HealthUpdater, ReactiveHealthCheck}; use zksync_l1_contract_interface::i_executor::commit::kzg::ZK_SYNC_BYTES_PER_BLOB; +use zksync_shared_metrics::{CheckerComponent, EN_METRICS}; use zksync_types::{ commitment::L1BatchWithMetadata, ethabi::Token, @@ -18,7 +19,6 @@ use zksync_types::{ use crate::{ eth_sender::l1_batch_commit_data_generator::L1BatchCommitDataGenerator, - metrics::{CheckerComponent, EN_METRICS}, utils::wait_for_l1_batch_with_metadata, }; diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs index d51a7fd863bb..2ec08cd951e1 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs @@ -10,6 +10,7 @@ use zksync_l1_contract_interface::{ multicall3::{Multicall3Call, Multicall3Result}, Detokenize, Tokenizable, Tokenize, }; +use zksync_shared_metrics::BlockL1Stage; use zksync_types::{ aggregated_operations::AggregatedActionType, commitment::SerializeCommitment, @@ -31,7 +32,6 @@ use crate::{ Aggregator, ETHSenderError, }, gas_tracker::agg_l1_batch_base_cost, - metrics::BlockL1Stage, }; /// Data queried from L1 using multicall contract. diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs index 5a081ef343d5..acc05b9c6416 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs @@ -8,6 +8,7 @@ use zksync_eth_client::{ encode_blob_tx_with_sidecar, BoundEthInterface, Error, EthInterface, ExecutedTxStatus, Options, RawTransactionBytes, SignedCallResult, }; +use zksync_shared_metrics::BlockL1Stage; use zksync_types::{ aggregated_operations::AggregatedActionType, eth_sender::{EthTx, EthTxBlobSidecar}, @@ -20,7 +21,7 @@ use zksync_types::{ use zksync_utils::time::seconds_since_epoch; use super::{metrics::METRICS, ETHSenderError}; -use crate::{l1_gas_price::L1TxParamsProvider, metrics::BlockL1Stage}; +use crate::l1_gas_price::L1TxParamsProvider; #[derive(Debug)] struct EthFee { diff --git a/core/lib/zksync_core/src/eth_sender/metrics.rs b/core/lib/zksync_core/src/eth_sender/metrics.rs index 055413d23838..08523b08d83c 100644 --- a/core/lib/zksync_core/src/eth_sender/metrics.rs +++ b/core/lib/zksync_core/src/eth_sender/metrics.rs @@ -4,13 +4,11 @@ use std::{fmt, time::Duration}; use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics}; use zksync_dal::{Connection, Core, CoreDal}; +use zksync_shared_metrics::{BlockL1Stage, BlockStage, APP_METRICS}; use zksync_types::{aggregated_operations::AggregatedActionType, eth_sender::EthTx}; use zksync_utils::time::seconds_since_epoch; -use crate::{ - eth_sender::eth_tx_manager::L1BlockNumbers, - metrics::{BlockL1Stage, BlockStage, APP_METRICS}, -}; +use crate::eth_sender::eth_tx_manager::L1BlockNumbers; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet, EncodeLabelValue)] #[metrics(label = "kind", rename_all = "snake_case")] diff --git a/core/lib/zksync_core/src/house_keeper/blocks_state_reporter.rs b/core/lib/zksync_core/src/house_keeper/blocks_state_reporter.rs index 38a9c4101858..bdff4b250015 100644 --- a/core/lib/zksync_core/src/house_keeper/blocks_state_reporter.rs +++ b/core/lib/zksync_core/src/house_keeper/blocks_state_reporter.rs @@ -1,11 +1,9 @@ use async_trait::async_trait; use zksync_dal::{ConnectionPool, Core, CoreDal}; +use zksync_shared_metrics::{BlockL1Stage, BlockStage, L1StageLatencyLabel, APP_METRICS}; use zksync_utils::time::seconds_since_epoch; -use crate::{ - house_keeper::periodic_job::PeriodicJob, - metrics::{BlockL1Stage, BlockStage, L1StageLatencyLabel, APP_METRICS}, -}; +use crate::house_keeper::periodic_job::PeriodicJob; #[derive(Debug)] pub struct L1BatchMetricsReporter { diff --git a/core/lib/zksync_core/src/house_keeper/fri_gpu_prover_archiver.rs b/core/lib/zksync_core/src/house_keeper/fri_gpu_prover_archiver.rs index 0297dc9c328f..6d1ac3f711d2 100644 --- a/core/lib/zksync_core/src/house_keeper/fri_gpu_prover_archiver.rs +++ b/core/lib/zksync_core/src/house_keeper/fri_gpu_prover_archiver.rs @@ -1,7 +1,7 @@ use prover_dal::{Prover, ProverDal}; use zksync_db_connection::connection_pool::ConnectionPool; -use crate::{house_keeper::periodic_job::PeriodicJob, metrics::HOUSE_KEEPER_METRICS}; +use crate::house_keeper::{metrics::HOUSE_KEEPER_METRICS, periodic_job::PeriodicJob}; /// FriGpuProverArchiver is a task that periodically archives old fri GPU prover records. /// The task will archive the `dead` prover records that have not been updated for a certain amount of time. diff --git a/core/lib/zksync_core/src/house_keeper/fri_prover_jobs_archiver.rs b/core/lib/zksync_core/src/house_keeper/fri_prover_jobs_archiver.rs index afbd7d8c0054..0050961985b4 100644 --- a/core/lib/zksync_core/src/house_keeper/fri_prover_jobs_archiver.rs +++ b/core/lib/zksync_core/src/house_keeper/fri_prover_jobs_archiver.rs @@ -1,7 +1,7 @@ use prover_dal::{Prover, ProverDal}; use zksync_db_connection::connection_pool::ConnectionPool; -use crate::{house_keeper::periodic_job::PeriodicJob, metrics::HOUSE_KEEPER_METRICS}; +use crate::house_keeper::{metrics::HOUSE_KEEPER_METRICS, periodic_job::PeriodicJob}; #[derive(Debug)] pub struct FriProverJobArchiver { diff --git a/core/lib/zksync_core/src/house_keeper/metrics.rs b/core/lib/zksync_core/src/house_keeper/metrics.rs new file mode 100644 index 000000000000..69615c634cff --- /dev/null +++ b/core/lib/zksync_core/src/house_keeper/metrics.rs @@ -0,0 +1,11 @@ +use vise::{Counter, Metrics}; + +#[derive(Debug, Metrics)] +#[metrics(prefix = "house_keeper")] +pub(crate) struct HouseKeeperMetrics { + pub prover_job_archived: Counter, + pub gpu_prover_archived: Counter, +} + +#[vise::register] +pub(crate) static HOUSE_KEEPER_METRICS: vise::Global = vise::Global::new(); diff --git a/core/lib/zksync_core/src/house_keeper/mod.rs b/core/lib/zksync_core/src/house_keeper/mod.rs index ca28384fab17..10de4e0702b9 100644 --- a/core/lib/zksync_core/src/house_keeper/mod.rs +++ b/core/lib/zksync_core/src/house_keeper/mod.rs @@ -8,5 +8,6 @@ pub mod fri_prover_queue_monitor; pub mod fri_scheduler_circuit_queuer; pub mod fri_witness_generator_jobs_retry_manager; pub mod fri_witness_generator_queue_monitor; +mod metrics; pub mod periodic_job; pub mod waiting_to_queued_fri_witness_job_mover; diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 2ae7a4e64bf6..912d632bfefd 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -43,9 +43,11 @@ use zksync_eth_client::{ clients::{PKSigningClient, QueryClient}, BoundEthInterface, }; +use zksync_eth_watch::start_eth_watch; use zksync_health_check::{AppHealthCheck, HealthStatus, ReactiveHealthCheck}; use zksync_object_store::{ObjectStore, ObjectStoreFactory}; use zksync_queued_job_processor::JobProcessor; +use zksync_shared_metrics::{InitStage, APP_METRICS}; use zksync_state::PostgresStorageCaches; use zksync_types::{fee_model::FeeModelConfig, L2ChainId}; @@ -67,7 +69,6 @@ use crate::{ }, Aggregator, EthTxAggregator, EthTxManager, }, - eth_watch::start_eth_watch, genesis::GenesisParams, house_keeper::{ blocks_state_reporter::L1BatchMetricsReporter, @@ -87,7 +88,6 @@ use crate::{ GasAdjusterSingleton, PubdataPricing, RollupPubdataPricing, ValidiumPubdataPricing, }, metadata_calculator::{MetadataCalculator, MetadataCalculatorConfig}, - metrics::{InitStage, APP_METRICS}, state_keeper::{ create_state_keeper, MempoolFetcher, MempoolGuard, OutputHandler, SequencerSealer, StateKeeperPersistence, @@ -102,14 +102,12 @@ pub mod commitment_generator; pub mod consensus; pub mod consistency_checker; pub mod eth_sender; -pub mod eth_watch; pub mod fee_model; pub mod gas_tracker; pub mod genesis; pub mod house_keeper; pub mod l1_gas_price; pub mod metadata_calculator; -mod metrics; pub mod proof_data_handler; pub mod proto; pub mod reorg_detector; diff --git a/core/lib/zksync_core/src/metadata_calculator/metrics.rs b/core/lib/zksync_core/src/metadata_calculator/metrics.rs index 7be194f9f5a7..2181d9080751 100644 --- a/core/lib/zksync_core/src/metadata_calculator/metrics.rs +++ b/core/lib/zksync_core/src/metadata_calculator/metrics.rs @@ -6,11 +6,11 @@ use vise::{ Buckets, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, LatencyObserver, Metrics, Unit, }; +use zksync_shared_metrics::{BlockStage, APP_METRICS}; use zksync_types::block::L1BatchHeader; use zksync_utils::time::seconds_since_epoch; use super::MetadataCalculator; -use crate::metrics::{BlockStage, APP_METRICS}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "stage", rename_all = "snake_case")] diff --git a/core/lib/zksync_core/src/reorg_detector/mod.rs b/core/lib/zksync_core/src/reorg_detector/mod.rs index 15d06a6b10b4..11cc9c0a3cab 100644 --- a/core/lib/zksync_core/src/reorg_detector/mod.rs +++ b/core/lib/zksync_core/src/reorg_detector/mod.rs @@ -5,6 +5,7 @@ use async_trait::async_trait; use tokio::sync::watch; use zksync_dal::{ConnectionPool, Core, CoreDal, DalError}; use zksync_health_check::{Health, HealthStatus, HealthUpdater, ReactiveHealthCheck}; +use zksync_shared_metrics::{CheckerComponent, EN_METRICS}; use zksync_types::{L1BatchNumber, MiniblockNumber, H256}; use zksync_web3_decl::{ client::L2Client, @@ -12,10 +13,7 @@ use zksync_web3_decl::{ namespaces::{EthNamespaceClient, ZksNamespaceClient}, }; -use crate::{ - metrics::{CheckerComponent, EN_METRICS}, - utils::binary_search_with, -}; +use crate::utils::binary_search_with; #[cfg(test)] mod tests; diff --git a/core/lib/zksync_core/src/state_keeper/batch_executor/main_executor.rs b/core/lib/zksync_core/src/state_keeper/batch_executor/main_executor.rs index 1769dfa25fe2..db480556affb 100644 --- a/core/lib/zksync_core/src/state_keeper/batch_executor/main_executor.rs +++ b/core/lib/zksync_core/src/state_keeper/batch_executor/main_executor.rs @@ -15,18 +15,16 @@ use tokio::{ runtime::Handle, sync::{mpsc, watch}, }; +use zksync_shared_metrics::{InteractionType, TxStage, APP_METRICS}; use zksync_state::{ReadStorage, StorageView, WriteStorage}; use zksync_types::{vm_trace::Call, Transaction}; use zksync_utils::bytecode::CompressedBytecodeInfo; use super::{BatchExecutor, BatchExecutorHandle, Command, TxExecutionResult}; -use crate::{ - metrics::{InteractionType, TxStage, APP_METRICS}, - state_keeper::{ - metrics::{TxExecutionStage, BATCH_TIP_METRICS, EXECUTOR_METRICS, KEEPER_METRICS}, - state_keeper_storage::ReadStorageFactory, - types::ExecutionMetricsForCriteria, - }, +use crate::state_keeper::{ + metrics::{TxExecutionStage, BATCH_TIP_METRICS, EXECUTOR_METRICS, KEEPER_METRICS}, + state_keeper_storage::ReadStorageFactory, + types::ExecutionMetricsForCriteria, }; /// The default implementation of [`BatchExecutor`]. diff --git a/core/lib/zksync_core/src/state_keeper/io/persistence.rs b/core/lib/zksync_core/src/state_keeper/io/persistence.rs index edbd866da4a8..06ba273980b7 100644 --- a/core/lib/zksync_core/src/state_keeper/io/persistence.rs +++ b/core/lib/zksync_core/src/state_keeper/io/persistence.rs @@ -5,15 +5,13 @@ use std::time::Instant; use async_trait::async_trait; use tokio::sync::{mpsc, oneshot}; use zksync_dal::{ConnectionPool, Core}; +use zksync_shared_metrics::{BlockStage, APP_METRICS}; use zksync_types::Address; -use crate::{ - metrics::{BlockStage, APP_METRICS}, - state_keeper::{ - io::StateKeeperOutputHandler, - metrics::{MiniblockQueueStage, MINIBLOCK_METRICS}, - updates::{MiniblockSealCommand, UpdatesManager}, - }, +use crate::state_keeper::{ + io::StateKeeperOutputHandler, + metrics::{MiniblockQueueStage, MINIBLOCK_METRICS}, + updates::{MiniblockSealCommand, UpdatesManager}, }; /// A command together with the return address allowing to track command processing completion. diff --git a/core/lib/zksync_core/src/state_keeper/io/seal_logic.rs b/core/lib/zksync_core/src/state_keeper/io/seal_logic.rs index 96ee93e87448..7ceeeaa27213 100644 --- a/core/lib/zksync_core/src/state_keeper/io/seal_logic.rs +++ b/core/lib/zksync_core/src/state_keeper/io/seal_logic.rs @@ -6,6 +6,7 @@ use std::time::{Duration, Instant}; use itertools::Itertools; use multivm::utils::{get_max_batch_gas_limit, get_max_gas_per_pubdata_byte}; use zksync_dal::{Connection, Core, CoreDal}; +use zksync_shared_metrics::{BlockStage, MiniblockStage, APP_METRICS}; use zksync_types::{ block::{unpack_block_info, L1BatchHeader, MiniblockHeader}, event::{extract_added_tokens, extract_long_l2_to_l1_messages}, @@ -26,15 +27,12 @@ use zksync_types::{ }; use zksync_utils::{h256_to_u256, u256_to_h256}; -use crate::{ - metrics::{BlockStage, MiniblockStage, APP_METRICS}, - state_keeper::{ - metrics::{ - L1BatchSealStage, MiniblockSealStage, TxExecutionType, KEEPER_METRICS, - L1_BATCH_METRICS, MINIBLOCK_METRICS, - }, - updates::{MiniblockSealCommand, UpdatesManager}, +use crate::state_keeper::{ + metrics::{ + L1BatchSealStage, MiniblockSealStage, TxExecutionType, KEEPER_METRICS, L1_BATCH_METRICS, + MINIBLOCK_METRICS, }, + updates::{MiniblockSealCommand, UpdatesManager}, }; impl UpdatesManager { diff --git a/core/lib/zksync_core/src/state_keeper/metrics.rs b/core/lib/zksync_core/src/state_keeper/metrics.rs index 6635587f30c4..cb2f55f5aadf 100644 --- a/core/lib/zksync_core/src/state_keeper/metrics.rs +++ b/core/lib/zksync_core/src/state_keeper/metrics.rs @@ -11,10 +11,10 @@ use vise::{ Metrics, }; use zksync_mempool::MempoolStore; +use zksync_shared_metrics::InteractionType; use zksync_types::{tx::tx_execution_info::DeduplicatedWritesMetrics, ProtocolVersionId}; use super::seal_criteria::SealResolution; -use crate::metrics::InteractionType; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "stage", rename_all = "snake_case")] diff --git a/core/lib/zksync_core/src/sync_layer/batch_status_updater/mod.rs b/core/lib/zksync_core/src/sync_layer/batch_status_updater/mod.rs index b262c0715616..deb54e864668 100644 --- a/core/lib/zksync_core/src/sync_layer/batch_status_updater/mod.rs +++ b/core/lib/zksync_core/src/sync_layer/batch_status_updater/mod.rs @@ -11,6 +11,7 @@ use tokio::sync::mpsc; use tokio::sync::watch; use zksync_dal::{Connection, ConnectionPool, Core, CoreDal}; use zksync_health_check::{Health, HealthStatus, HealthUpdater, ReactiveHealthCheck}; +use zksync_shared_metrics::EN_METRICS; use zksync_types::{ aggregated_operations::AggregatedActionType, api, L1BatchNumber, MiniblockNumber, H256, }; @@ -21,7 +22,7 @@ use zksync_web3_decl::{ }; use super::metrics::{FetchStage, FETCHER_METRICS}; -use crate::{metrics::EN_METRICS, utils::projected_first_l1_batch}; +use crate::utils::projected_first_l1_batch; #[cfg(test)] mod tests; diff --git a/core/lib/zksync_core/src/sync_layer/fetcher.rs b/core/lib/zksync_core/src/sync_layer/fetcher.rs index f7837e6c1cca..99053f3d1395 100644 --- a/core/lib/zksync_core/src/sync_layer/fetcher.rs +++ b/core/lib/zksync_core/src/sync_layer/fetcher.rs @@ -1,5 +1,6 @@ use anyhow::Context as _; use zksync_dal::{Connection, Core, CoreDal}; +use zksync_shared_metrics::{TxStage, APP_METRICS}; use zksync_types::{ api::en::SyncBlock, block::MiniblockHasher, fee_model::BatchFeeInput, helpers::unix_timestamp_ms, Address, L1BatchNumber, MiniblockNumber, ProtocolVersionId, H256, @@ -9,10 +10,7 @@ use super::{ metrics::{L1BatchStage, FETCHER_METRICS}, sync_action::SyncAction, }; -use crate::{ - metrics::{TxStage, APP_METRICS}, - state_keeper::io::{common::IoCursor, L1BatchParams, MiniblockParams}, -}; +use crate::state_keeper::io::{common::IoCursor, L1BatchParams, MiniblockParams}; /// Same as [`zksync_types::Transaction`], just with additional guarantees that the "received at" timestamp was set locally. /// We cannot transfer `Transaction`s without these timestamps, because this would break backward compatibility. diff --git a/core/lib/zksync_core/src/sync_layer/sync_state.rs b/core/lib/zksync_core/src/sync_layer/sync_state.rs index 85f2239692c3..a82f5d62e3c5 100644 --- a/core/lib/zksync_core/src/sync_layer/sync_state.rs +++ b/core/lib/zksync_core/src/sync_layer/sync_state.rs @@ -7,13 +7,11 @@ use tokio::sync::watch; use zksync_concurrency::{ctx, sync}; use zksync_dal::{ConnectionPool, Core, CoreDal}; use zksync_health_check::{CheckHealth, Health, HealthStatus}; +use zksync_shared_metrics::EN_METRICS; use zksync_types::MiniblockNumber; use zksync_web3_decl::{client::L2Client, namespaces::EthNamespaceClient}; -use crate::{ - metrics::EN_METRICS, - state_keeper::{io::IoCursor, updates::UpdatesManager, StateKeeperOutputHandler}, -}; +use crate::state_keeper::{io::IoCursor, updates::UpdatesManager, StateKeeperOutputHandler}; /// `SyncState` is a structure that holds the state of the syncing process. /// The intended use case is to signalize to Web3 API whether the node is fully synced. diff --git a/core/node/eth_watch/Cargo.toml b/core/node/eth_watch/Cargo.toml new file mode 100644 index 000000000000..43d4d98f57ae --- /dev/null +++ b/core/node/eth_watch/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "zksync_eth_watch" +version = "0.1.0" +edition.workspace = true +authors.workspace = true +homepage.workspace = true +repository.workspace = true +license.workspace = true +keywords.workspace = true +categories.workspace = true + +[dependencies] +vise.workspace = true +zksync_types.workspace = true +zksync_dal.workspace = true +zksync_config.workspace = true +zksync_contracts.workspace = true +zksync_system_constants.workspace = true +zksync_eth_client.workspace = true +zksync_shared_metrics.workspace = true + +tokio = { workspace = true, features = ["time"] } +anyhow.workspace = true +thiserror.workspace = true +async-trait.workspace = true +tracing.workspace = true +metrics.workspace = true diff --git a/core/node/eth_watch/README.md b/core/node/eth_watch/README.md new file mode 100644 index 000000000000..06b1b620941e --- /dev/null +++ b/core/node/eth_watch/README.md @@ -0,0 +1,4 @@ +# zkSync Era Eth Watcher + +This crate contains implementation of zkSync Era Eth Watcher component, responsible for fetching the changes from the +corresponding L1 contract. diff --git a/core/lib/zksync_core/src/eth_watch/client.rs b/core/node/eth_watch/src/client.rs similarity index 100% rename from core/lib/zksync_core/src/eth_watch/client.rs rename to core/node/eth_watch/src/client.rs diff --git a/core/lib/zksync_core/src/eth_watch/event_processors/governance_upgrades.rs b/core/node/eth_watch/src/event_processors/governance_upgrades.rs similarity index 99% rename from core/lib/zksync_core/src/eth_watch/event_processors/governance_upgrades.rs rename to core/node/eth_watch/src/event_processors/governance_upgrades.rs index 1a157cf6d529..9218ac29ce7c 100644 --- a/core/lib/zksync_core/src/eth_watch/event_processors/governance_upgrades.rs +++ b/core/node/eth_watch/src/event_processors/governance_upgrades.rs @@ -6,7 +6,7 @@ use zksync_types::{ ProtocolUpgrade, ProtocolVersionId, H256, }; -use crate::eth_watch::{ +use crate::{ client::{Error, EthClient}, event_processors::EventProcessor, }; diff --git a/core/lib/zksync_core/src/eth_watch/event_processors/mod.rs b/core/node/eth_watch/src/event_processors/mod.rs similarity index 91% rename from core/lib/zksync_core/src/eth_watch/event_processors/mod.rs rename to core/node/eth_watch/src/event_processors/mod.rs index 1d945331f977..84aa4336cb04 100644 --- a/core/lib/zksync_core/src/eth_watch/event_processors/mod.rs +++ b/core/node/eth_watch/src/event_processors/mod.rs @@ -3,7 +3,7 @@ use std::fmt; use zksync_dal::{Connection, Core}; use zksync_types::{web3::types::Log, H256}; -use crate::eth_watch::client::{Error, EthClient}; +use crate::client::{Error, EthClient}; pub mod governance_upgrades; pub mod priority_ops; diff --git a/core/lib/zksync_core/src/eth_watch/event_processors/priority_ops.rs b/core/node/eth_watch/src/event_processors/priority_ops.rs similarity index 94% rename from core/lib/zksync_core/src/eth_watch/event_processors/priority_ops.rs rename to core/node/eth_watch/src/event_processors/priority_ops.rs index c9f0561b54c2..d7d4f681a802 100644 --- a/core/lib/zksync_core/src/eth_watch/event_processors/priority_ops.rs +++ b/core/node/eth_watch/src/event_processors/priority_ops.rs @@ -2,15 +2,13 @@ use std::convert::TryFrom; use zksync_contracts::zksync_contract; use zksync_dal::{Connection, Core, CoreDal}; +use zksync_shared_metrics::{TxStage, APP_METRICS}; use zksync_types::{l1::L1Tx, web3::types::Log, PriorityOpId, H256}; use crate::{ - eth_watch::{ - client::{Error, EthClient}, - event_processors::EventProcessor, - metrics::{PollStage, METRICS}, - }, - metrics::{TxStage, APP_METRICS}, + client::{Error, EthClient}, + event_processors::EventProcessor, + metrics::{PollStage, METRICS}, }; /// Responsible for saving new priority L1 transactions to the database. diff --git a/core/lib/zksync_core/src/eth_watch/event_processors/upgrades.rs b/core/node/eth_watch/src/event_processors/upgrades.rs similarity index 99% rename from core/lib/zksync_core/src/eth_watch/event_processors/upgrades.rs rename to core/node/eth_watch/src/event_processors/upgrades.rs index fbffe0f15bbd..01b04b3ed578 100644 --- a/core/lib/zksync_core/src/eth_watch/event_processors/upgrades.rs +++ b/core/node/eth_watch/src/event_processors/upgrades.rs @@ -3,7 +3,7 @@ use std::convert::TryFrom; use zksync_dal::{Connection, Core, CoreDal}; use zksync_types::{web3::types::Log, ProtocolUpgrade, ProtocolVersionId, H256}; -use crate::eth_watch::{ +use crate::{ client::{Error, EthClient}, event_processors::EventProcessor, metrics::{PollStage, METRICS}, diff --git a/core/lib/zksync_core/src/eth_watch/mod.rs b/core/node/eth_watch/src/lib.rs similarity index 100% rename from core/lib/zksync_core/src/eth_watch/mod.rs rename to core/node/eth_watch/src/lib.rs diff --git a/core/lib/zksync_core/src/eth_watch/metrics.rs b/core/node/eth_watch/src/metrics.rs similarity index 100% rename from core/lib/zksync_core/src/eth_watch/metrics.rs rename to core/node/eth_watch/src/metrics.rs diff --git a/core/lib/zksync_core/src/eth_watch/tests.rs b/core/node/eth_watch/src/tests.rs similarity index 99% rename from core/lib/zksync_core/src/eth_watch/tests.rs rename to core/node/eth_watch/src/tests.rs index 9a0c91c06870..a9577b793a69 100644 --- a/core/lib/zksync_core/src/eth_watch/tests.rs +++ b/core/node/eth_watch/src/tests.rs @@ -13,9 +13,7 @@ use zksync_types::{ }; use super::client::Error; -use crate::eth_watch::{ - client::EthClient, event_processors::upgrades::UPGRADE_PROPOSAL_SIGNATURE, EthWatch, -}; +use crate::{client::EthClient, event_processors::upgrades::UPGRADE_PROPOSAL_SIGNATURE, EthWatch}; #[derive(Debug)] struct FakeEthClientData { diff --git a/core/node/node_framework/Cargo.toml b/core/node/node_framework/Cargo.toml index 89e2934ad3c9..0c83e9d0f06f 100644 --- a/core/node/node_framework/Cargo.toml +++ b/core/node/node_framework/Cargo.toml @@ -27,6 +27,7 @@ zksync_web3_decl.workspace = true zksync_utils.workspace = true zksync_circuit_breaker.workspace = true zksync_concurrency.workspace = true +zksync_eth_watch.workspace = true tracing.workspace = true thiserror.workspace = true diff --git a/core/node/node_framework/src/implementations/layers/eth_watch.rs b/core/node/node_framework/src/implementations/layers/eth_watch.rs index 43fad7750345..6fee3f718ba8 100644 --- a/core/node/node_framework/src/implementations/layers/eth_watch.rs +++ b/core/node/node_framework/src/implementations/layers/eth_watch.rs @@ -2,8 +2,8 @@ use std::time::Duration; use zksync_config::{ContractsConfig, ETHWatchConfig}; use zksync_contracts::governance_contract; -use zksync_core::eth_watch::{client::EthHttpQueryClient, EthWatch}; use zksync_dal::{ConnectionPool, Core}; +use zksync_eth_watch::{client::EthHttpQueryClient, EthWatch}; use zksync_types::{ethabi::Contract, Address}; use crate::{ diff --git a/core/node/shared_metrics/Cargo.toml b/core/node/shared_metrics/Cargo.toml new file mode 100644 index 000000000000..5ba0ebfbfca1 --- /dev/null +++ b/core/node/shared_metrics/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "zksync_shared_metrics" +version = "0.1.0" +edition.workspace = true +authors.workspace = true +homepage.workspace = true +repository.workspace = true +license.workspace = true +keywords.workspace = true +categories.workspace = true + + +[dependencies] +vise.workspace = true +zksync_types.workspace = true +zksync_dal.workspace = true diff --git a/core/node/shared_metrics/README.md b/core/node/shared_metrics/README.md new file mode 100644 index 000000000000..45aa229f808a --- /dev/null +++ b/core/node/shared_metrics/README.md @@ -0,0 +1,3 @@ +# zkSync Era shared metrics + +This crate contains the definitions of various metrics that are shared among different zkSync Era components. diff --git a/core/lib/zksync_core/src/metrics.rs b/core/node/shared_metrics/src/lib.rs similarity index 88% rename from core/lib/zksync_core/src/metrics.rs rename to core/node/shared_metrics/src/lib.rs index 066f8f3e251b..06608861352a 100644 --- a/core/lib/zksync_core/src/metrics.rs +++ b/core/node/shared_metrics/src/lib.rs @@ -8,7 +8,7 @@ use zksync_types::aggregated_operations::AggregatedActionType; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "stage")] -pub(crate) enum InitStage { +pub enum InitStage { HttpApi, WsApi, ContractVerificationApi, @@ -39,7 +39,7 @@ impl fmt::Display for InitStage { } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub(crate) enum BlockL1Stage { +pub enum BlockL1Stage { Saved, Mined, } @@ -47,7 +47,7 @@ pub(crate) enum BlockL1Stage { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "stage", rename_all = "snake_case")] #[allow(clippy::enum_variant_names)] -pub(crate) enum L1StageLatencyLabel { +pub enum L1StageLatencyLabel { UncommittedBlock, UnprovedBlock, UnexecutedBlock, @@ -55,7 +55,7 @@ pub(crate) enum L1StageLatencyLabel { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "stage")] -pub(crate) enum BlockStage { +pub enum BlockStage { Sealed, Tree, MetadataCalculated, @@ -84,7 +84,7 @@ impl fmt::Display for BlockStage { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "stage")] -pub(crate) enum TxStage { +pub enum TxStage { Mempool(L2TxSubmissionResult), Proxied, StateKeeper, @@ -120,13 +120,13 @@ impl TxStage { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "stage", rename_all = "snake_case")] -pub(crate) enum MiniblockStage { +pub enum MiniblockStage { Sealed, } #[derive(Debug, Metrics)] #[metrics(prefix = "server")] -pub(crate) struct AppMetrics { +pub struct AppMetrics { /// Latency to initialize a specific server component. pub init_latency: Family>, pub block_number: Family>, @@ -144,12 +144,12 @@ pub(crate) struct AppMetrics { } #[vise::register] -pub(crate) static APP_METRICS: vise::Global = vise::Global::new(); +pub static APP_METRICS: vise::Global = vise::Global::new(); /// Type of VM interaction with the storage. Used both for API server and state keeper metrics. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "interaction", rename_all = "snake_case")] -pub(crate) enum InteractionType { +pub enum InteractionType { Missed, GetValue, SetValue, @@ -158,7 +158,7 @@ pub(crate) enum InteractionType { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "component", rename_all = "snake_case")] -pub(crate) enum CheckerComponent { +pub enum CheckerComponent { ConsistencyChecker, ReorgDetector, } @@ -166,7 +166,7 @@ pub(crate) enum CheckerComponent { /// General-purpose external node metrics. #[derive(Debug, Metrics)] #[metrics(prefix = "external_node")] -pub(crate) struct ExternalNodeMetrics { +pub struct ExternalNodeMetrics { #[metrics(buckets = Buckets::LATENCIES)] pub update_batch_statuses: Histogram, #[metrics(buckets = Buckets::LATENCIES)] @@ -182,14 +182,4 @@ pub(crate) struct ExternalNodeMetrics { } #[vise::register] -pub(crate) static EN_METRICS: vise::Global = vise::Global::new(); - -#[derive(Debug, Metrics)] -#[metrics(prefix = "house_keeper")] -pub(crate) struct HouseKeeperMetrics { - pub prover_job_archived: Counter, - pub gpu_prover_archived: Counter, -} - -#[vise::register] -pub(crate) static HOUSE_KEEPER_METRICS: vise::Global = vise::Global::new(); +pub static EN_METRICS: vise::Global = vise::Global::new();