Skip to content

Commit

Permalink
feat(sqlx): Use offline mode by default (#1539)
Browse files Browse the repository at this point in the history
## What ❔

* Introduce new zk command `zk db prepare`
* Add sqlx_offline=true to envs
* remove build.rs from prover  

## Why ❔

It allows us to make build faster and remove dependency from envs

## Checklist

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

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

Signed-off-by: Danil <deniallugo@gmail.com>
  • Loading branch information
Deniallugo committed Apr 2, 2024
1 parent 777ffca commit af01edd
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 67 deletions.

This file was deleted.

This file was deleted.

17 changes: 10 additions & 7 deletions etc/env/base/database.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# In our workspace we intentionally use offline mode in workspace,
# and you have to run `zk db prepare` for regenerating sqlx files
sqlx_offline = true
[database]
# Path to the directory that contains RocksDB with VM state cache.
state_keeper_db_path="./db/main/state_keeper"
backup_count=5
backup_interval_ms=60000
state_keeper_db_path = "./db/main/state_keeper"
backup_count = 5
backup_interval_ms = 60000
# Amount of open connections to the database.
pool_size=50
pool_size = 50
# Postgres statement timeout. Applies only to the replica connection pool
# used by the API servers.
statement_timeout_sec=300
statement_timeout_sec = 300

[database.merkle_tree]
# Path to the directory that contains RocksDB with Merkle tree.
path="./db/main/tree"
path = "./db/main/tree"
# Path to the directory that contains RocksDB backups for Merkle tree.
backup_path="./db/main/backups"
backup_path = "./db/main/backups"
24 changes: 19 additions & 5 deletions infrastructure/zk/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,20 @@ export async function wait(opts: DbOpts, tries: number = 4) {
}
}

async function checkSqlxDataForDal(dalPath: DalPath, dbUrl: string) {
async function prepareSqlxDataForDal(dalPath: DalPath, dbUrl: string, check: boolean) {
process.chdir(dalPath);
await utils.spawn(`cargo sqlx prepare --check --database-url ${dbUrl} -- --tests`);
let check_string = '';
if (check) {
check_string = '--check';
}
await utils.spawn(`cargo sqlx prepare ${check_string} --database-url ${dbUrl} -- --tests`);
process.chdir(process.env.ZKSYNC_HOME as string);
}

export async function checkSqlxData(opts: DbOpts) {
export async function prepareSqlxData(opts: DbOpts, check: boolean) {
let dals = getDals(opts);
for (const [dalPath, dbUrl] of dals.entries()) {
await checkSqlxDataForDal(dalPath, dbUrl);
await prepareSqlxDataForDal(dalPath, dbUrl, check);
}
}

Expand Down Expand Up @@ -230,4 +234,14 @@ command
.description('check sqlx-data.json is up to date')
.option('-p, --prover')
.option('-c, --core')
.action(checkSqlxData);
.action(async (cmd) => {
await prepareSqlxData(cmd, true);
});
command
.command('prepare')
.description('check sqlx-data.json is up to date')
.option('-p, --prover')
.option('-c, --core')
.action(async (cmd) => {
await prepareSqlxData(cmd, false);
});
2 changes: 1 addition & 1 deletion infrastructure/zk/src/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function rust(options: string[]) {
test_runner = 'cargo test';
}

let cmd = `SQLX_OFFLINE=true ${test_runner} --release ${options.join(' ')}`;
let cmd = `${test_runner} --release ${options.join(' ')}`;
console.log(`running unit tests with '${cmd}'`);

await utils.spawn(cmd);
Expand Down
11 changes: 0 additions & 11 deletions prover/prover_dal/build.rs

This file was deleted.

0 comments on commit af01edd

Please sign in to comment.