From 752967fd57353856028b636b302bc85ff68f23a5 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Wed, 5 Jun 2024 15:11:32 +0400 Subject: [PATCH 1/3] Move main node healtchcheck --- Cargo.lock | 1 + core/bin/external_node/src/helpers.rs | 29 --------------------------- core/bin/external_node/src/main.rs | 4 ++-- core/node/node_sync/Cargo.toml | 1 + core/node/node_sync/src/client.rs | 29 +++++++++++++++++++++++++++ core/node/node_sync/src/lib.rs | 2 +- 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd45d942b146..fa49904e7acd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8983,6 +8983,7 @@ dependencies = [ "chrono", "once_cell", "serde", + "serde_json", "test-casing", "thiserror", "tokio", diff --git a/core/bin/external_node/src/helpers.rs b/core/bin/external_node/src/helpers.rs index 1290428a231c..ead81158cb87 100644 --- a/core/bin/external_node/src/helpers.rs +++ b/core/bin/external_node/src/helpers.rs @@ -5,7 +5,6 @@ use std::time::Duration; use futures::FutureExt; use tokio::sync::watch; use zksync_eth_client::EthInterface; -use zksync_health_check::{async_trait, CheckHealth, Health, HealthStatus}; use zksync_types::{L1ChainId, L2ChainId}; use zksync_web3_decl::{ client::{DynClient, L1, L2}, @@ -13,34 +12,6 @@ use zksync_web3_decl::{ namespaces::{EthNamespaceClient, ZksNamespaceClient}, }; -/// Main node health check. -#[derive(Debug)] -pub(crate) struct MainNodeHealthCheck(Box>); - -impl From>> for MainNodeHealthCheck { - fn from(client: Box>) -> Self { - Self(client.for_component("main_node_health_check")) - } -} - -#[async_trait] -impl CheckHealth for MainNodeHealthCheck { - fn name(&self) -> &'static str { - "main_node_http_rpc" - } - - async fn check_health(&self) -> Health { - if let Err(err) = self.0.get_block_number().await { - tracing::warn!("Health-check call to main node HTTP RPC failed: {err}"); - let details = serde_json::json!({ - "error": err.to_string(), - }); - return Health::from(HealthStatus::NotReady).with_details(details); - } - HealthStatus::Ready.into() - } -} - /// Task that validates chain IDs using main node and Ethereum clients. #[derive(Debug)] pub(crate) struct ValidateChainIdsTask { diff --git a/core/bin/external_node/src/main.rs b/core/bin/external_node/src/main.rs index 05f4b2ba9d43..3d60fad59015 100644 --- a/core/bin/external_node/src/main.rs +++ b/core/bin/external_node/src/main.rs @@ -35,7 +35,7 @@ use zksync_node_db_pruner::{DbPruner, DbPrunerConfig}; use zksync_node_fee_model::l1_gas_price::MainNodeFeeParamsFetcher; use zksync_node_sync::{ batch_status_updater::BatchStatusUpdater, external_io::ExternalIO, - tree_data_fetcher::TreeDataFetcher, ActionQueue, SyncState, + tree_data_fetcher::TreeDataFetcher, ActionQueue, MainNodeHealthCheck, SyncState, }; use zksync_reorg_detector::ReorgDetector; use zksync_state::{PostgresStorageCaches, RocksdbStorageOptions}; @@ -54,7 +54,7 @@ use zksync_web3_decl::{ use crate::{ config::ExternalNodeConfig, - helpers::{MainNodeHealthCheck, ValidateChainIdsTask}, + helpers::ValidateChainIdsTask, init::{ensure_storage_initialized, SnapshotRecoveryConfig}, metrics::RUST_METRICS, }; diff --git a/core/node/node_sync/Cargo.toml b/core/node/node_sync/Cargo.toml index 9fd0aad73094..cdab113f22d6 100644 --- a/core/node/node_sync/Cargo.toml +++ b/core/node/node_sync/Cargo.toml @@ -31,6 +31,7 @@ async-trait.workspace = true chrono.workspace = true tracing.workspace = true serde.workspace = true +serde_json.workspace = true tokio = { workspace = true, features = ["time"] } thiserror.workspace = true diff --git a/core/node/node_sync/src/client.rs b/core/node/node_sync/src/client.rs index 2c25a0cea8e8..3d71d86f163b 100644 --- a/core/node/node_sync/src/client.rs +++ b/core/node/node_sync/src/client.rs @@ -4,6 +4,7 @@ use std::fmt; use async_trait::async_trait; use zksync_config::GenesisConfig; +use zksync_health_check::{CheckHealth, Health, HealthStatus}; use zksync_system_constants::ACCOUNT_CODE_STORAGE_ADDRESS; use zksync_types::{ api::{self, en}, @@ -136,3 +137,31 @@ impl MainNodeClient for Box> { .await } } + +/// Main node health check. +#[derive(Debug)] +pub struct MainNodeHealthCheck(Box>); + +impl From>> for MainNodeHealthCheck { + fn from(client: Box>) -> Self { + Self(client.for_component("main_node_health_check")) + } +} + +#[async_trait] +impl CheckHealth for MainNodeHealthCheck { + fn name(&self) -> &'static str { + "main_node_http_rpc" + } + + async fn check_health(&self) -> Health { + if let Err(err) = self.0.get_block_number().await { + tracing::warn!("Health-check call to main node HTTP RPC failed: {err}"); + let details = serde_json::json!({ + "error": err.to_string(), + }); + return Health::from(HealthStatus::NotReady).with_details(details); + } + HealthStatus::Ready.into() + } +} diff --git a/core/node/node_sync/src/lib.rs b/core/node/node_sync/src/lib.rs index 6a2c5b8c54b2..43295ac22c26 100644 --- a/core/node/node_sync/src/lib.rs +++ b/core/node/node_sync/src/lib.rs @@ -12,7 +12,7 @@ mod tests; pub mod tree_data_fetcher; pub use self::{ - client::MainNodeClient, + client::{MainNodeClient, MainNodeHealthCheck}, external_io::ExternalIO, sync_action::{ActionQueue, ActionQueueSender}, sync_state::SyncState, From 078c03bccfd850848af9aa141c5f9a9b35c4aa08 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Wed, 5 Jun 2024 15:21:50 +0400 Subject: [PATCH 2/3] Move task and rustc metrics --- Cargo.lock | 3 ++ core/bin/external_node/src/main.rs | 7 ++-- core/bin/external_node/src/metadata.rs | 19 ---------- core/bin/external_node/src/metrics.rs | 22 +----------- core/node/node_sync/Cargo.toml | 1 + core/node/node_sync/src/lib.rs | 1 + .../node_sync/src/validate_chain_ids_task.rs} | 2 +- core/node/shared_metrics/Cargo.toml | 4 +++ .../shared_metrics}/build.rs | 0 core/node/shared_metrics/src/lib.rs | 2 ++ core/node/shared_metrics/src/rustc.rs | 36 +++++++++++++++++++ 11 files changed, 52 insertions(+), 45 deletions(-) rename core/{bin/external_node/src/helpers.rs => node/node_sync/src/validate_chain_ids_task.rs} (99%) rename core/{bin/external_node => node/shared_metrics}/build.rs (100%) create mode 100644 core/node/shared_metrics/src/rustc.rs diff --git a/Cargo.lock b/Cargo.lock index fa49904e7acd..91c26b5c6372 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8981,6 +8981,7 @@ dependencies = [ "assert_matches", "async-trait", "chrono", + "futures 0.3.28", "once_cell", "serde", "serde_json", @@ -9196,6 +9197,8 @@ dependencies = [ name = "zksync_shared_metrics" version = "0.1.0" dependencies = [ + "rustc_version", + "tracing", "vise", "zksync_dal", "zksync_types", diff --git a/core/bin/external_node/src/main.rs b/core/bin/external_node/src/main.rs index 3d60fad59015..a651c97fdc8b 100644 --- a/core/bin/external_node/src/main.rs +++ b/core/bin/external_node/src/main.rs @@ -35,9 +35,11 @@ use zksync_node_db_pruner::{DbPruner, DbPrunerConfig}; use zksync_node_fee_model::l1_gas_price::MainNodeFeeParamsFetcher; use zksync_node_sync::{ batch_status_updater::BatchStatusUpdater, external_io::ExternalIO, - tree_data_fetcher::TreeDataFetcher, ActionQueue, MainNodeHealthCheck, SyncState, + tree_data_fetcher::TreeDataFetcher, validate_chain_ids_task::ValidateChainIdsTask, ActionQueue, + MainNodeHealthCheck, SyncState, }; use zksync_reorg_detector::ReorgDetector; +use zksync_shared_metrics::rustc::RUST_METRICS; use zksync_state::{PostgresStorageCaches, RocksdbStorageOptions}; use zksync_state_keeper::{ seal_criteria::NoopSealer, AsyncRocksdbCache, BatchExecutor, MainBatchExecutor, OutputHandler, @@ -54,13 +56,10 @@ use zksync_web3_decl::{ use crate::{ config::ExternalNodeConfig, - helpers::ValidateChainIdsTask, init::{ensure_storage_initialized, SnapshotRecoveryConfig}, - metrics::RUST_METRICS, }; mod config; -mod helpers; mod init; mod metadata; mod metrics; diff --git a/core/bin/external_node/src/metadata.rs b/core/bin/external_node/src/metadata.rs index ce454711a97d..73bc4b7b0626 100644 --- a/core/bin/external_node/src/metadata.rs +++ b/core/bin/external_node/src/metadata.rs @@ -1,22 +1,3 @@ //! Metadata information about the external node. -use vise::EncodeLabelSet; - -pub(crate) use self::values::RUSTC_METADATA; - -mod values { - use super::RustcMetadata; - include!(concat!(env!("OUT_DIR"), "/metadata_values.rs")); -} - -#[derive(Debug, EncodeLabelSet)] -pub(crate) struct RustcMetadata { - pub version: &'static str, - pub commit_hash: Option<&'static str>, - pub commit_date: Option<&'static str>, - pub channel: &'static str, - pub host: &'static str, - pub llvm: Option<&'static str>, -} - pub(crate) const SERVER_VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/core/bin/external_node/src/metrics.rs b/core/bin/external_node/src/metrics.rs index 08397f824f50..ca4495180226 100644 --- a/core/bin/external_node/src/metrics.rs +++ b/core/bin/external_node/src/metrics.rs @@ -4,10 +4,7 @@ use tokio::sync::watch; use vise::{EncodeLabelSet, Gauge, Info, Metrics}; use zksync_dal::{ConnectionPool, Core, CoreDal}; -use crate::{ - config::ExternalNodeConfig, - metadata::{RustcMetadata, RUSTC_METADATA, SERVER_VERSION}, -}; +use crate::{config::ExternalNodeConfig, metadata::SERVER_VERSION}; /// Immutable EN parameters that affect multiple components. #[derive(Debug, Clone, Copy, EncodeLabelSet)] @@ -74,20 +71,3 @@ impl ExternalNodeMetrics { #[vise::register] pub(crate) static EN_METRICS: vise::Global = vise::Global::new(); - -#[derive(Debug, Metrics)] -#[metrics(prefix = "rust")] -pub(crate) struct RustMetrics { - /// General information about the Rust compiler. - info: Info, -} - -impl RustMetrics { - pub fn initialize(&self) { - tracing::info!("Metadata for rustc that this EN was compiled with: {RUSTC_METADATA:?}"); - self.info.set(RUSTC_METADATA).ok(); - } -} - -#[vise::register] -pub(crate) static RUST_METRICS: vise::Global = vise::Global::new(); diff --git a/core/node/node_sync/Cargo.toml b/core/node/node_sync/Cargo.toml index cdab113f22d6..58eec35a630c 100644 --- a/core/node/node_sync/Cargo.toml +++ b/core/node/node_sync/Cargo.toml @@ -29,6 +29,7 @@ vm_utils.workspace = true anyhow.workspace = true async-trait.workspace = true chrono.workspace = true +futures.workspace = true tracing.workspace = true serde.workspace = true serde_json.workspace = true diff --git a/core/node/node_sync/src/lib.rs b/core/node/node_sync/src/lib.rs index 43295ac22c26..304ef87270bd 100644 --- a/core/node/node_sync/src/lib.rs +++ b/core/node/node_sync/src/lib.rs @@ -10,6 +10,7 @@ pub mod testonly; #[cfg(test)] mod tests; pub mod tree_data_fetcher; +pub mod validate_chain_ids_task; pub use self::{ client::{MainNodeClient, MainNodeHealthCheck}, diff --git a/core/bin/external_node/src/helpers.rs b/core/node/node_sync/src/validate_chain_ids_task.rs similarity index 99% rename from core/bin/external_node/src/helpers.rs rename to core/node/node_sync/src/validate_chain_ids_task.rs index ead81158cb87..5a75cb384aec 100644 --- a/core/bin/external_node/src/helpers.rs +++ b/core/node/node_sync/src/validate_chain_ids_task.rs @@ -14,7 +14,7 @@ use zksync_web3_decl::{ /// Task that validates chain IDs using main node and Ethereum clients. #[derive(Debug)] -pub(crate) struct ValidateChainIdsTask { +pub struct ValidateChainIdsTask { l1_chain_id: L1ChainId, l2_chain_id: L2ChainId, eth_client: Box>, diff --git a/core/node/shared_metrics/Cargo.toml b/core/node/shared_metrics/Cargo.toml index c6d60828b40a..5fbbf16a2ec7 100644 --- a/core/node/shared_metrics/Cargo.toml +++ b/core/node/shared_metrics/Cargo.toml @@ -11,5 +11,9 @@ categories.workspace = true [dependencies] vise.workspace = true +tracing.workspace = true zksync_types.workspace = true zksync_dal.workspace = true + +[build-dependencies] +rustc_version.workspace = true diff --git a/core/bin/external_node/build.rs b/core/node/shared_metrics/build.rs similarity index 100% rename from core/bin/external_node/build.rs rename to core/node/shared_metrics/build.rs diff --git a/core/node/shared_metrics/src/lib.rs b/core/node/shared_metrics/src/lib.rs index 46e80c8410fd..22a90349191d 100644 --- a/core/node/shared_metrics/src/lib.rs +++ b/core/node/shared_metrics/src/lib.rs @@ -8,6 +8,8 @@ use vise::{ use zksync_dal::transactions_dal::L2TxSubmissionResult; use zksync_types::aggregated_operations::AggregatedActionType; +pub mod rustc; + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "stage", rename_all = "snake_case")] pub enum SnapshotRecoveryStage { diff --git a/core/node/shared_metrics/src/rustc.rs b/core/node/shared_metrics/src/rustc.rs new file mode 100644 index 000000000000..11165dbf51b0 --- /dev/null +++ b/core/node/shared_metrics/src/rustc.rs @@ -0,0 +1,36 @@ +use vise::{EncodeLabelSet, Info, Metrics}; + +mod values { + use super::RustcMetadata; + include!(concat!(env!("OUT_DIR"), "/metadata_values.rs")); +} + +use values::RUSTC_METADATA; + +/// Metadata of Rust compiler used to compile the crate. +#[derive(Debug, EncodeLabelSet)] +pub struct RustcMetadata { + pub version: &'static str, + pub commit_hash: Option<&'static str>, + pub commit_date: Option<&'static str>, + pub channel: &'static str, + pub host: &'static str, + pub llvm: Option<&'static str>, +} + +#[derive(Debug, Metrics)] +#[metrics(prefix = "rust")] +pub struct RustMetrics { + /// General information about the Rust compiler. + info: Info, +} + +impl RustMetrics { + pub fn initialize(&self) { + tracing::info!("Metadata for rustc that this binary was compiled with: {RUSTC_METADATA:?}"); + self.info.set(RUSTC_METADATA).ok(); + } +} + +#[vise::register] +pub static RUST_METRICS: vise::Global = vise::Global::new(); From 51c6e5a1aa282108b667e14161425bc3b79b10fd Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Wed, 5 Jun 2024 16:10:53 +0400 Subject: [PATCH 3/3] Update prover's cargo.lock --- prover/Cargo.lock | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prover/Cargo.lock b/prover/Cargo.lock index f6f0425fa3e0..46c040206f12 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -8362,6 +8362,8 @@ dependencies = [ name = "zksync_shared_metrics" version = "0.1.0" dependencies = [ + "rustc_version", + "tracing", "vise", "zksync_dal", "zksync_types",