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

fix(zk_toolbox): Remove prover db from server init #3009

Merged
merged 2 commits into from
Oct 4, 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
8 changes: 0 additions & 8 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ jobs:
--deploy-ecosystem --l1-rpc-url=http://localhost:8545 \
--server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--server-db-name=zksync_server_localhost_era \
--prover-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--prover-db-name=zksync_prover_localhost_era \
--ignore-prerequisites --verbose \
--observability=false

Expand Down Expand Up @@ -246,8 +244,6 @@ jobs:
--l1-rpc-url=http://localhost:8545 \
--server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--server-db-name=zksync_server_localhost_validium \
--prover-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--prover-db-name=zksync_prover_localhost_validium \
--chain validium

- name: Create and initialize chain with Custom Token
Expand All @@ -269,8 +265,6 @@ jobs:
--l1-rpc-url=http://localhost:8545 \
--server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--server-db-name=zksync_server_localhost_custom_token \
--prover-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--prover-db-name=zksync_prover_localhost_custom_token \
--chain custom_token

- name: Create and register chain with transactions signed "offline"
Expand Down Expand Up @@ -327,8 +321,6 @@ jobs:
--l1-rpc-url=http://localhost:8545 \
--server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--server-db-name=zksync_server_localhost_consensus \
--prover-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--prover-db-name=zksync_prover_localhost_consensus \
--chain consensus

- name: Build test dependencies
Expand Down
8 changes: 3 additions & 5 deletions zk_toolbox/crates/config/src/secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ use crate::{
traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig},
};

pub fn set_databases(
pub fn set_server_database(
secrets: &mut SecretsConfig,
server_db_config: &DatabaseConfig,
prover_db_config: &DatabaseConfig,
) -> anyhow::Result<()> {
let database = secrets
.database
.as_mut()
.context("Databases must be presented")?;
.context("Server database must be presented")?;
database.server_url = Some(SensitiveUrl::from(server_db_config.full_url()));
database.prover_url = Some(SensitiveUrl::from(prover_db_config.full_url()));
Ok(())
}

Expand All @@ -33,7 +31,7 @@ pub fn set_prover_database(
let database = secrets
.database
.as_mut()
.context("Databases must be presented")?;
.context("Prover database must be presented")?;
database.prover_url = Some(SensitiveUrl::from(prover_db_config.full_url()));
Ok(())
}
Expand Down
44 changes: 4 additions & 40 deletions zk_toolbox/crates/zk_inception/src/commands/chain/args/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use slugify_rs::slugify;
use url::Url;

use crate::{
defaults::{generate_db_names, DBNames, DATABASE_PROVER_URL, DATABASE_SERVER_URL},
defaults::{generate_db_names, DBNames, DATABASE_SERVER_URL},
messages::{
msg_prover_db_name_prompt, msg_prover_db_url_prompt, msg_server_db_name_prompt,
msg_server_db_url_prompt, MSG_PROVER_DB_NAME_HELP, MSG_PROVER_DB_URL_HELP,
MSG_SERVER_DB_NAME_HELP, MSG_SERVER_DB_URL_HELP, MSG_USE_DEFAULT_DATABASES_HELP,
msg_server_db_name_prompt, msg_server_db_url_prompt, MSG_SERVER_DB_NAME_HELP,
MSG_SERVER_DB_URL_HELP, MSG_USE_DEFAULT_DATABASES_HELP,
},
};

Expand All @@ -21,10 +20,6 @@ pub struct GenesisArgs {
pub server_db_url: Option<Url>,
#[clap(long, help = MSG_SERVER_DB_NAME_HELP)]
pub server_db_name: Option<String>,
#[clap(long, help = MSG_PROVER_DB_URL_HELP)]
pub prover_db_url: Option<Url>,
#[clap(long, help = MSG_PROVER_DB_NAME_HELP)]
pub prover_db_name: Option<String>,
#[clap(long, short, help = MSG_USE_DEFAULT_DATABASES_HELP)]
pub use_default: bool,
#[clap(long, short, action)]
Expand All @@ -33,15 +28,11 @@ pub struct GenesisArgs {

impl GenesisArgs {
pub fn fill_values_with_prompt(self, config: &ChainConfig) -> GenesisArgsFinal {
let DBNames {
server_name,
prover_name,
} = generate_db_names(config);
let DBNames { server_name, .. } = generate_db_names(config);
let chain_name = config.name.clone();
if self.use_default {
GenesisArgsFinal {
server_db: DatabaseConfig::new(DATABASE_SERVER_URL.clone(), server_name),
prover_db: DatabaseConfig::new(DATABASE_PROVER_URL.clone(), prover_name),
dont_drop: self.dont_drop,
}
} else {
Expand All @@ -58,22 +49,8 @@ impl GenesisArgs {
}),
separator = "_"
);
let prover_db_url = self.prover_db_url.unwrap_or_else(|| {
Prompt::new(&msg_prover_db_url_prompt(&chain_name))
.default(DATABASE_PROVER_URL.as_str())
.ask()
});
let prover_db_name = slugify!(
&self.prover_db_name.unwrap_or_else(|| {
Prompt::new(&msg_prover_db_name_prompt(&chain_name))
.default(&prover_name)
.ask()
}),
separator = "_"
);
GenesisArgsFinal {
server_db: DatabaseConfig::new(server_db_url, server_db_name),
prover_db: DatabaseConfig::new(prover_db_url, prover_db_name),
dont_drop: self.dont_drop,
}
}
Expand All @@ -96,25 +73,13 @@ impl GenesisArgs {
(None, None)
};

let (prover_db_url, prover_db_name) = if let Some(db_full_url) = database.prover_url {
let db_config = DatabaseConfig::from_url(db_full_url.expose_url())
.context("Invalid prover database URL")?;
(Some(db_config.url), Some(db_config.name))
} else {
(None, None)
};

self.server_db_url = self.server_db_url.or(server_db_url);
self.server_db_name = self.server_db_name.or(server_db_name);
self.prover_db_url = self.prover_db_url.or(prover_db_url);
self.prover_db_name = self.prover_db_name.or(prover_db_name);

Ok(self.fill_values_with_prompt(chain_config))
}

pub fn reset_db_names(&mut self) {
self.prover_db_name = None;
self.prover_db_url = None;
self.server_db_name = None;
self.server_db_url = None;
}
Expand All @@ -123,6 +88,5 @@ impl GenesisArgs {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenesisArgsFinal {
pub server_db: DatabaseConfig,
pub prover_db: DatabaseConfig,
pub dont_drop: bool,
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use common::{
logger,
};
use config::{
override_config, set_databases, set_file_artifacts, set_rocks_db_config,
override_config, set_file_artifacts, set_rocks_db_config, set_server_database,
traits::SaveConfigWithBasePath, ChainConfig, EcosystemConfig, FileArtifacts,
};
use types::ProverMode;
Expand All @@ -18,12 +18,11 @@ use crate::{
commands::chain::args::genesis::{GenesisArgs, GenesisArgsFinal},
consts::{
PATH_TO_ONLY_REAL_PROOFS_OVERRIDE_CONFIG, PATH_TO_VALIDIUM_OVERRIDE_CONFIG,
PROVER_MIGRATIONS, SERVER_MIGRATIONS,
SERVER_MIGRATIONS,
},
messages::{
MSG_CHAIN_NOT_INITIALIZED, MSG_FAILED_TO_DROP_PROVER_DATABASE_ERR,
MSG_FAILED_TO_DROP_SERVER_DATABASE_ERR, MSG_GENESIS_DATABASES_INITIALIZED,
MSG_INITIALIZING_PROVER_DATABASE, MSG_INITIALIZING_SERVER_DATABASE,
MSG_CHAIN_NOT_INITIALIZED, MSG_FAILED_TO_DROP_SERVER_DATABASE_ERR,
MSG_GENESIS_DATABASES_INITIALIZED, MSG_INITIALIZING_SERVER_DATABASE,
MSG_RECREATE_ROCKS_DB_ERRROR,
},
utils::rocks_db::{recreate_rocksdb_dirs, RocksDBDirOption},
Expand All @@ -37,13 +36,12 @@ pub async fn run(args: GenesisArgs, shell: &Shell) -> anyhow::Result<()> {

let mut secrets = chain_config.get_secrets_config()?;
let args = args.fill_values_with_secrets(&chain_config)?;
set_databases(&mut secrets, &args.server_db, &args.prover_db)?;
set_server_database(&mut secrets, &args.server_db)?;
secrets.save_with_base_path(shell, &chain_config.configs)?;

initialize_databases(
initialize_server_database(
shell,
&args.server_db,
&args.prover_db,
chain_config.link_to_code.clone(),
args.dont_drop,
)
Expand All @@ -53,10 +51,9 @@ pub async fn run(args: GenesisArgs, shell: &Shell) -> anyhow::Result<()> {
Ok(())
}

pub async fn initialize_databases(
pub async fn initialize_server_database(
shell: &Shell,
server_db_config: &DatabaseConfig,
prover_db_config: &DatabaseConfig,
link_to_code: PathBuf,
dont_drop: bool,
) -> anyhow::Result<()> {
Expand All @@ -78,23 +75,6 @@ pub async fn initialize_databases(
)
.await?;

if global_config().verbose {
logger::debug(MSG_INITIALIZING_PROVER_DATABASE)
}
if !dont_drop {
drop_db_if_exists(prover_db_config)
.await
.context(MSG_FAILED_TO_DROP_PROVER_DATABASE_ERR)?;
init_db(prover_db_config).await?;
}
let path_to_prover_migration = link_to_code.join(PROVER_MIGRATIONS);
migrate_db(
shell,
path_to_prover_migration,
&prover_db_config.full_url(),
)
.await?;

Ok(())
}

Expand All @@ -107,7 +87,7 @@ pub fn update_configs(

// Update secrets configs
let mut secrets = config.get_secrets_config()?;
set_databases(&mut secrets, &args.server_db, &args.prover_db)?;
set_server_database(&mut secrets, &args.server_db)?;
secrets.save_with_base_path(shell, &config.configs)?;

// Update general config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use xshell::Shell;
use crate::{
commands::chain::{
args::genesis::{GenesisArgs, GenesisArgsFinal},
genesis::{self, database::initialize_databases, server::run_server_genesis},
genesis::{self, database::initialize_server_database, server::run_server_genesis},
},
messages::{
MSG_CHAIN_NOT_INITIALIZED, MSG_GENESIS_COMPLETED, MSG_INITIALIZING_DATABASES_SPINNER,
Expand Down Expand Up @@ -70,16 +70,14 @@ pub async fn genesis(
logger::object_to_string(serde_json::json!({
"chain_config": config,
"server_db_config": args.server_db,
"prover_db_config": args.prover_db,
})),
);
logger::info(MSG_STARTING_GENESIS);

let spinner = Spinner::new(MSG_INITIALIZING_DATABASES_SPINNER);
initialize_databases(
initialize_server_database(
shell,
&args.server_db,
&args.prover_db,
config.link_to_code.clone(),
args.dont_drop,
)
Expand Down
Loading