Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node): Move some stuff around #2151

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions core/bin/external_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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,
Expand All @@ -54,13 +56,10 @@ use zksync_web3_decl::{

use crate::{
config::ExternalNodeConfig,
helpers::{MainNodeHealthCheck, ValidateChainIdsTask},
init::{ensure_storage_initialized, SnapshotRecoveryConfig},
metrics::RUST_METRICS,
};

mod config;
mod helpers;
mod init;
mod metadata;
mod metrics;
Expand Down
19 changes: 0 additions & 19 deletions core/bin/external_node/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -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");
22 changes: 1 addition & 21 deletions core/bin/external_node/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -74,20 +71,3 @@ impl ExternalNodeMetrics {

#[vise::register]
pub(crate) static EN_METRICS: vise::Global<ExternalNodeMetrics> = vise::Global::new();

#[derive(Debug, Metrics)]
#[metrics(prefix = "rust")]
pub(crate) struct RustMetrics {
/// General information about the Rust compiler.
info: Info<RustcMetadata>,
}

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<RustMetrics> = vise::Global::new();
2 changes: 2 additions & 0 deletions core/node/node_sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ 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
tokio = { workspace = true, features = ["time"] }
thiserror.workspace = true

Expand Down
29 changes: 29 additions & 0 deletions core/node/node_sync/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -136,3 +137,31 @@ impl MainNodeClient for Box<DynClient<L2>> {
.await
}
}

/// Main node health check.
#[derive(Debug)]
pub struct MainNodeHealthCheck(Box<DynClient<L2>>);

impl From<Box<DynClient<L2>>> for MainNodeHealthCheck {
fn from(client: Box<DynClient<L2>>) -> 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()
}
}
3 changes: 2 additions & 1 deletion core/node/node_sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ pub mod testonly;
#[cfg(test)]
mod tests;
pub mod tree_data_fetcher;
pub mod validate_chain_ids_task;

pub use self::{
client::MainNodeClient,
client::{MainNodeClient, MainNodeHealthCheck},
external_io::ExternalIO,
sync_action::{ActionQueue, ActionQueueSender},
sync_state::SyncState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,16 @@ 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},
error::ClientRpcContext,
namespaces::{EthNamespaceClient, ZksNamespaceClient},
};

/// Main node health check.
#[derive(Debug)]
pub(crate) struct MainNodeHealthCheck(Box<DynClient<L2>>);

impl From<Box<DynClient<L2>>> for MainNodeHealthCheck {
fn from(client: Box<DynClient<L2>>) -> 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 {
pub struct ValidateChainIdsTask {
l1_chain_id: L1ChainId,
l2_chain_id: L2ChainId,
eth_client: Box<DynClient<L1>>,
Expand Down
4 changes: 4 additions & 0 deletions core/node/shared_metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
2 changes: 2 additions & 0 deletions core/node/shared_metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 36 additions & 0 deletions core/node/shared_metrics/src/rustc.rs
Original file line number Diff line number Diff line change
@@ -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<RustcMetadata>,
}

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<RustMetrics> = vise::Global::new();
2 changes: 2 additions & 0 deletions prover/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading