Skip to content

Commit

Permalink
feat(zk_toolbox): Move check sql to the lint step (#2757)
Browse files Browse the repository at this point in the history
## What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.

---------

Signed-off-by: Danil <deniallugo@gmail.com>
  • Loading branch information
Deniallugo authored Aug 29, 2024
1 parent 3757746 commit dcd3727
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 40 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/ci-core-lint-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:

jobs:
code_lint:
runs-on: [matterlabs-ci-runner]
runs-on: [ matterlabs-ci-runner ]

steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
Expand All @@ -16,6 +16,8 @@ jobs:
echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV
echo $(pwd)/bin >> $GITHUB_PATH
echo IN_DOCKER=1 >> .env
echo "prover_url=postgres://postgres:notsecurepassword@postgres:5432/zksync_local_prover" >> $GITHUB_ENV
echo "core_url=postgres://postgres:notsecurepassword@postgres:5432/zksync_local" >> $GITHUB_ENV
- name: Start services
run: |
Expand All @@ -27,6 +29,8 @@ jobs:
ci_run ./bin/zkt
ci_run yarn install
ci_run git config --global --add safe.directory /usr/src/zksync
ci_run zk_supervisor db setup --prover-url=${{ env.prover_url }} --core-url=${{ env.core_url }}
- name: Lints
run: |
Expand All @@ -36,3 +40,7 @@ jobs:
ci_run zk_supervisor lint -t js --check
ci_run zk_supervisor lint -t ts --check
ci_run zk_supervisor lint -t rs --check
- name: Check Database
run: |
ci_run zk_supervisor database check-sqlx-data --prover-url=${{ env.prover_url }} --core-url=${{ env.core_url }}
15 changes: 6 additions & 9 deletions .github/workflows/ci-zk-toolbox-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
uses: ./.github/workflows/ci-core-lint-reusable.yml

build:
runs-on: [matterlabs-ci-runner]
runs-on: [ matterlabs-ci-runner ]

steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
Expand Down Expand Up @@ -48,8 +48,8 @@ jobs:
compression-level: 0

tests:
runs-on: [matterlabs-ci-runner]
needs: [build]
runs-on: [ matterlabs-ci-runner ]
needs: [ build ]

steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
Expand Down Expand Up @@ -115,9 +115,6 @@ jobs:
--prover-db-url=postgres://postgres:notsecurepassword@postgres:5432 \
--prover-db-name=zksync_prover_localhost_rollup
- name: Check Database
run: |
ci_run zk_supervisor database check-sqlx-data
- name: Run server
run: |
Expand All @@ -137,11 +134,11 @@ jobs:
- name: Run recovery tests (from snapshot)
run: |
ci_run zk_supervisor test recovery --snapshot --ignore-prerequisites --verbose
- name: Run recovery tests (from genesis)
run: |
ci_run zk_supervisor test recovery --ignore-prerequisites --verbose
- name: Run external node server
run: |
ci_run zk_inception external-node run --ignore-prerequisites &>external_node.log &
Expand All @@ -164,7 +161,7 @@ jobs:
- name: Run upgrade test
run: |
ci_run zk_supervisor test upgrade
- name: Show server.log logs
if: always()
run: ci_run cat server.log || true
Expand Down
32 changes: 29 additions & 3 deletions zk_toolbox/crates/zk_supervisor/src/commands/database/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@ use clap::Parser;

use crate::{
dals::SelectedDals,
messages::{MSG_DATABASE_COMMON_CORE_HELP, MSG_DATABASE_COMMON_PROVER_HELP},
messages::{
MSG_DATABASE_COMMON_CORE_HELP, MSG_DATABASE_COMMON_CORE_URL_HELP,
MSG_DATABASE_COMMON_PROVER_HELP, MSG_DATABASE_COMMON_PROVER_URL_HELP,
},
};

pub mod new_migration;

#[derive(Debug, Parser)]
pub struct DatabaseCommonArgs {
#[clap(short, long, default_missing_value = "true", num_args = 0..=1, help = MSG_DATABASE_COMMON_PROVER_HELP)]
#[clap(
short, long, default_missing_value = "true", num_args = 0..=1, help = MSG_DATABASE_COMMON_PROVER_HELP
)]
pub prover: Option<bool>,
#[clap(short, long, default_missing_value = "true", num_args = 0..=1, help = MSG_DATABASE_COMMON_CORE_HELP)]
#[clap(long, help = MSG_DATABASE_COMMON_PROVER_URL_HELP)]
pub prover_url: Option<String>,
#[clap(
short, long, default_missing_value = "true", num_args = 0..=1, help = MSG_DATABASE_COMMON_CORE_HELP
)]
pub core: Option<bool>,
#[clap(long, help = MSG_DATABASE_COMMON_CORE_URL_HELP)]
pub core_url: Option<String>,
}

impl DatabaseCommonArgs {
Expand All @@ -23,6 +34,10 @@ impl DatabaseCommonArgs {
prover: true,
core: true,
},
urls: DalUrls {
prover: self.prover_url,
core: self.core_url,
},
};
}

Expand All @@ -31,11 +46,22 @@ impl DatabaseCommonArgs {
prover: self.prover.unwrap_or(false),
core: self.core.unwrap_or(false),
},
urls: DalUrls {
prover: self.prover_url,
core: self.core_url,
},
}
}
}

#[derive(Debug, Clone)]
pub struct DalUrls {
pub prover: Option<String>,
pub core: Option<String>,
}

#[derive(Debug)]
pub struct DatabaseCommonArgsFinal {
pub selected_dals: SelectedDals,
pub urls: DalUrls,
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn run(shell: &Shell, args: DatabaseCommonArgs) -> anyhow::Result<()> {

logger::info(msg_database_info(MSG_DATABASE_CHECK_SQLX_DATA_GERUND));

let dals = get_dals(shell, &args.selected_dals)?;
let dals = get_dals(shell, &args.selected_dals, &args.urls)?;
for dal in dals {
check_sqlx_data(shell, &ecosystem_config.link_to_code, dal)?;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub async fn run(shell: &Shell, args: DatabaseCommonArgs) -> anyhow::Result<()>

logger::info(msg_database_info(MSG_DATABASE_DROP_GERUND));

let dals = get_dals(shell, &args.selected_dals)?;
let dals = get_dals(shell, &args.selected_dals, &args.urls)?;
for dal in dals {
drop_database(dal).await?;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn run(shell: &Shell, args: DatabaseCommonArgs) -> anyhow::Result<()> {
logger::info(msg_database_info(MSG_DATABASE_MIGRATE_GERUND));
let ecosystem_config = EcosystemConfig::from_file(shell)?;

let dals = get_dals(shell, &args.selected_dals)?;
let dals = get_dals(shell, &args.selected_dals, &args.urls)?;
for dal in dals {
migrate_database(shell, &ecosystem_config.link_to_code, dal)?;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::messages::{
MSG_DATABASE_SETUP_ABOUT,
};

mod args;
pub mod args;
mod check_sqlx_data;
mod drop;
mod migrate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub fn run(shell: &Shell, args: DatabaseNewMigrationArgs) -> anyhow::Result<()>
let args = args.fill_values_with_prompt();

let dal = match args.selected_database {
SelectedDatabase::Core => get_core_dal(shell)?,
SelectedDatabase::Prover => get_prover_dal(shell)?,
SelectedDatabase::Core => get_core_dal(shell, None)?,
SelectedDatabase::Prover => get_prover_dal(shell, None)?,
};
let ecosystem_config = EcosystemConfig::from_file(shell)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn run(shell: &Shell, args: DatabaseCommonArgs) -> anyhow::Result<()> {

logger::info(msg_database_info(MSG_DATABASE_PREPARE_GERUND));

let dals = get_dals(shell, &args.selected_dals)?;
let dals = get_dals(shell, &args.selected_dals, &args.urls)?;
for dal in dals {
prepare_sqlx_data(shell, &ecosystem_config.link_to_code, dal)?;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub async fn run(shell: &Shell, args: DatabaseCommonArgs) -> anyhow::Result<()>

logger::info(msg_database_info(MSG_DATABASE_RESET_GERUND));

let dals = get_dals(shell, &args.selected_dals)?;
let dals = get_dals(shell, &args.selected_dals, &args.urls)?;
for dal in dals {
logger::info(msg_database_loading(MSG_DATABASE_RESET_GERUND, &dal.path));
reset_database(shell, ecoseystem_config.link_to_code.clone(), dal).await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn run(shell: &Shell, args: DatabaseCommonArgs) -> anyhow::Result<()> {

logger::info(msg_database_info(MSG_DATABASE_SETUP_GERUND));

let dals = get_dals(shell, &args.selected_dals)?;
let dals = get_dals(shell, &args.selected_dals, &args.urls)?;
for dal in dals {
setup_database(shell, &ecosystem_config.link_to_code, dal)?;
}
Expand Down
53 changes: 35 additions & 18 deletions zk_toolbox/crates/zk_supervisor/src/dals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use config::{EcosystemConfig, SecretsConfig};
use url::Url;
use xshell::Shell;

use crate::messages::{MSG_CHAIN_NOT_FOUND_ERR, MSG_DATABASE_MUST_BE_PRESENTED};
use crate::{
commands::database::args::DalUrls,
messages::{MSG_CHAIN_NOT_FOUND_ERR, MSG_DATABASE_MUST_BE_PRESENTED},
};

const CORE_DAL_PATH: &str = "core/lib/dal";
const PROVER_DAL_PATH: &str = "prover/crates/lib/prover_dal";
Expand All @@ -30,14 +33,18 @@ pub struct Dal {
pub url: Url,
}

pub fn get_dals(shell: &Shell, selected_dals: &SelectedDals) -> anyhow::Result<Vec<Dal>> {
pub fn get_dals(
shell: &Shell,
selected_dals: &SelectedDals,
urls: &DalUrls,
) -> anyhow::Result<Vec<Dal>> {
let mut dals = vec![];

if selected_dals.prover {
dals.push(get_prover_dal(shell)?);
dals.push(get_prover_dal(shell, urls.prover.clone())?);
}
if selected_dals.core {
dals.push(get_core_dal(shell)?);
dals.push(get_core_dal(shell, urls.core.clone())?);
}

Ok(dals)
Expand All @@ -47,33 +54,43 @@ pub fn get_test_dals(shell: &Shell) -> anyhow::Result<Vec<Dal>> {
Ok(vec![get_test_prover_dal(shell)?, get_test_core_dal(shell)?])
}

pub fn get_prover_dal(shell: &Shell) -> anyhow::Result<Dal> {
let secrets = get_secrets(shell)?;

Ok(Dal {
path: PROVER_DAL_PATH.to_string(),
url: secrets
pub fn get_prover_dal(shell: &Shell, url: Option<String>) -> anyhow::Result<Dal> {
let url = if let Some(url) = url {
Url::parse(&url)?
} else {
let secrets = get_secrets(shell)?;
secrets
.database
.as_ref()
.context(MSG_DATABASE_MUST_BE_PRESENTED)?
.prover_url()?
.expose_url()
.clone(),
.clone()
};

Ok(Dal {
path: PROVER_DAL_PATH.to_string(),
url,
})
}

pub fn get_core_dal(shell: &Shell) -> anyhow::Result<Dal> {
let secrets = get_secrets(shell)?;

Ok(Dal {
path: CORE_DAL_PATH.to_string(),
url: secrets
pub fn get_core_dal(shell: &Shell, url: Option<String>) -> anyhow::Result<Dal> {
let url = if let Some(url) = url {
Url::parse(&url)?
} else {
let secrets = get_secrets(shell)?;
secrets
.database
.as_ref()
.context(MSG_DATABASE_MUST_BE_PRESENTED)?
.master_url()?
.expose_url()
.clone(),
.clone()
};

Ok(Dal {
path: CORE_DAL_PATH.to_string(),
url,
})
}

Expand Down
4 changes: 4 additions & 0 deletions zk_toolbox/crates/zk_supervisor/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ pub(super) const MSG_DATABASE_SETUP_GERUND: &str = "Setting up";
pub(super) const MSG_DATABASE_SETUP_PAST: &str = "set up";
pub(super) const MSG_DATABASE_MUST_BE_PRESENTED: &str = "Database config must be presented";
pub(super) const MSG_DATABASE_COMMON_PROVER_HELP: &str = "Prover database";
pub(super) const MSG_DATABASE_COMMON_PROVER_URL_HELP: &str =
"URL of the Prover database. If not specified, it is used from the current chain's secrets";
pub(super) const MSG_DATABASE_COMMON_CORE_URL_HELP: &str =
"URL of the Core database. If not specified, it is used from the current chain's secrets.";
pub(super) const MSG_DATABASE_COMMON_CORE_HELP: &str = "Core database";
pub(super) const MSG_DATABASE_NEW_MIGRATION_DATABASE_HELP: &str =
"Database to create new migration for";
Expand Down

0 comments on commit dcd3727

Please sign in to comment.