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: add general config and secrets opts to snapshot creator #2471

Merged
merged 10 commits into from
Jul 24, 2024
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions core/bin/snapshots_creator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 30 additions & 13 deletions core/bin/snapshots_creator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
//! 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_env_config::FromEnv;
use zksync_object_store::ObjectStoreFactory;
use zksync_vlog::prometheus::PrometheusExporterConfig;

Expand Down Expand Up @@ -49,12 +48,29 @@ 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<std::path::PathBuf>,

/// Path to the secrets file.
#[structopt(long)]
secrets_path: Option<std::path::PathBuf>,
}

#[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()
Expand All @@ -71,15 +87,16 @@ 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 object_store_config = general_config
manuelmauro marked this conversation as resolved.
Show resolved Hide resolved
.core_object_store
.context("ubject store config")?;
manuelmauro marked this conversation as resolved.
Show resolved Hide resolved
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 creator_config = general_config
.snapshot_creator
.context("SnapshotsCreatorConfig::from_env")?;

let replica_pool = ConnectionPool::<Core>::builder(
database_secrets.replica_url()?,
Expand Down
1 change: 1 addition & 0 deletions core/bin/snapshots_creator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
Loading