diff --git a/Cargo.lock b/Cargo.lock index 7319999316be..9840be8502ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6030,10 +6030,12 @@ dependencies = [ "anyhow", "futures 0.3.28", "rand 0.8.5", + "structopt", "tokio", "tracing", "vise", "zksync_config", + "zksync_core_leftovers", "zksync_dal", "zksync_env_config", "zksync_object_store", diff --git a/core/bin/snapshots_creator/Cargo.toml b/core/bin/snapshots_creator/Cargo.toml index 763d2374b8c2..33b1fa82a857 100644 --- a/core/bin/snapshots_creator/Cargo.toml +++ b/core/bin/snapshots_creator/Cargo.toml @@ -19,8 +19,10 @@ zksync_env_config.workspace = true zksync_types.workspace = true zksync_object_store.workspace = true zksync_vlog.workspace = true +zksync_core_leftovers.workspace = true anyhow.workspace = true +structopt.workspace = true tokio = { workspace = true, features = ["full"] } tracing.workspace = true futures.workspace = true diff --git a/core/bin/snapshots_creator/src/main.rs b/core/bin/snapshots_creator/src/main.rs index aee3919a4b0a..e07a879746ad 100644 --- a/core/bin/snapshots_creator/src/main.rs +++ b/core/bin/snapshots_creator/src/main.rs @@ -10,13 +10,11 @@ //! at a time). use anyhow::Context as _; +use structopt::StructOpt; use tokio::{sync::watch, task::JoinHandle}; -use zksync_config::{ - configs::{DatabaseSecrets, ObservabilityConfig, PrometheusConfig}, - SnapshotsCreatorConfig, -}; +use zksync_config::configs::PrometheusConfig; +use zksync_core_leftovers::temp_config_store::{load_database_secrets, load_general_config}; use zksync_dal::{ConnectionPool, Core}; -use zksync_env_config::{object_store::SnapshotsObjectStoreConfig, FromEnv}; use zksync_object_store::ObjectStoreFactory; use zksync_vlog::prometheus::PrometheusExporterConfig; @@ -28,9 +26,9 @@ mod metrics; mod tests; async fn maybe_enable_prometheus_metrics( + prometheus_config: Option, stop_receiver: watch::Receiver, ) -> anyhow::Result>>> { - let prometheus_config = PrometheusConfig::from_env().ok(); match prometheus_config.map(|c| (c.gateway_endpoint(), c.push_interval())) { Some((Some(gateway_endpoint), push_interval)) => { tracing::info!("Starting prometheus exporter with gateway {gateway_endpoint:?} and push_interval {push_interval:?}"); @@ -49,18 +47,36 @@ async fn maybe_enable_prometheus_metrics( /// Minimum number of storage log chunks to produce. const MIN_CHUNK_COUNT: u64 = 10; +#[derive(StructOpt)] +#[structopt(name = "ZKsync snapshot creator", author = "Matter Labs")] +struct Opt { + /// Path to the configuration file. + #[structopt(long)] + config_path: Option, + + /// Path to the secrets file. + #[structopt(long)] + secrets_path: Option, +} + #[tokio::main] async fn main() -> anyhow::Result<()> { let (stop_sender, stop_receiver) = watch::channel(false); - let observability_config = - ObservabilityConfig::from_env().context("ObservabilityConfig::from_env()")?; + let opt = Opt::from_args(); + let general_config = load_general_config(opt.config_path).context("general config")?; + let database_secrets = load_database_secrets(opt.secrets_path).context("database secrets")?; + + let observability_config = general_config + .observability + .context("observability config")?; let log_format: zksync_vlog::LogFormat = observability_config .log_format .parse() .context("Invalid log format")?; - let prometheus_exporter_task = maybe_enable_prometheus_metrics(stop_receiver).await?; + let prometheus_exporter_task = + maybe_enable_prometheus_metrics(general_config.prometheus_config, stop_receiver).await?; let mut builder = zksync_vlog::ObservabilityBuilder::new().with_log_format(log_format); if let Some(sentry_url) = observability_config.sentry_url { builder = builder @@ -71,16 +87,19 @@ async fn main() -> anyhow::Result<()> { let _guard = builder.build(); tracing::info!("Starting snapshots creator"); - let object_store_config = - SnapshotsObjectStoreConfig::from_env().context("SnapshotsObjectStoreConfig::from_env()")?; - let blob_store = ObjectStoreFactory::new(object_store_config.0) + let creator_config = general_config + .snapshot_creator + .context("snapshot creator config")?; + + let object_store_config = creator_config + .clone() + .object_store + .context("snapshot creator object storage config")?; + + let blob_store = ObjectStoreFactory::new(object_store_config) .create_store() .await?; - let database_secrets = DatabaseSecrets::from_env().context("DatabaseSecrets")?; - let creator_config = - SnapshotsCreatorConfig::from_env().context("SnapshotsCreatorConfig::from_env")?; - let replica_pool = ConnectionPool::::builder( database_secrets.replica_url()?, creator_config.concurrent_queries_count, diff --git a/core/bin/snapshots_creator/src/tests.rs b/core/bin/snapshots_creator/src/tests.rs index 1c26f1081598..89a3807422be 100644 --- a/core/bin/snapshots_creator/src/tests.rs +++ b/core/bin/snapshots_creator/src/tests.rs @@ -10,6 +10,7 @@ use std::{ }; use rand::{thread_rng, Rng}; +use zksync_config::SnapshotsCreatorConfig; use zksync_dal::{Connection, CoreDal}; use zksync_object_store::{MockObjectStore, ObjectStore}; use zksync_types::{ diff --git a/core/lib/env_config/src/snapshots_creator.rs b/core/lib/env_config/src/snapshots_creator.rs index 6ed80e3780ce..80e1f5ec0b00 100644 --- a/core/lib/env_config/src/snapshots_creator.rs +++ b/core/lib/env_config/src/snapshots_creator.rs @@ -1,9 +1,13 @@ use zksync_config::SnapshotsCreatorConfig; -use crate::{envy_load, FromEnv}; +use crate::{envy_load, object_store::SnapshotsObjectStoreConfig, FromEnv}; impl FromEnv for SnapshotsCreatorConfig { fn from_env() -> anyhow::Result { - envy_load("snapshots_creator", "SNAPSHOTS_CREATOR_") + let mut snapshot_creator: SnapshotsCreatorConfig = + envy_load("snapshots_creator", "SNAPSHOTS_CREATOR_")?; + + snapshot_creator.object_store = SnapshotsObjectStoreConfig::from_env().map(|a| a.0).ok(); + Ok(snapshot_creator) } } diff --git a/docs/guides/external-node/09_decentralization.md b/docs/guides/external-node/09_decentralization.md index aa9598a825ca..fa780ba9ff55 100644 --- a/docs/guides/external-node/09_decentralization.md +++ b/docs/guides/external-node/09_decentralization.md @@ -17,11 +17,10 @@ On the gossipnet, the data integrity will be protected by the BFT (byzantine fau > current implementation it may take a couple of hours and gets faster the more nodes you add to the > `gossip_static_outbound` list (see below). We are working to remove this inconvenience. - > [!NOTE] > -> The minimal supported server version for this is [24.11.0](https://github.com/matter-labs/zksync-era/releases/tag/core-v24.11.0) - +> The minimal supported server version for this is +> [24.11.0](https://github.com/matter-labs/zksync-era/releases/tag/core-v24.11.0) ### Generating secrets