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(prover_cli): Fix the issues with home path #2104

Merged
merged 20 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions etc/pliconfig
ColoCarletti marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PLI__DB_URL=postgres://postgres:notsecurepassword@localhost/prover_local
2 changes: 2 additions & 0 deletions prover/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 prover/prover_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ prover_dal.workspace = true
zksync_eth_client.workspace = true
zksync_contracts.workspace = true
zksync_dal.workspace = true
zksync_utils.workspace = true
strum.workspace = true
colored.workspace = true
sqlx.workspace = true
circuit_definitions.workspace = true
serde_json.workspace = true
13 changes: 6 additions & 7 deletions prover/prover_cli/src/commands/status/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use zksync_eth_client::{
CallFunctionArgs,
};

use crate::helper;

pub(crate) async fn run() -> anyhow::Result<()> {
println!(" ====== L1 Status ====== ");
let postgres_config = PostgresConfig::from_env().context("PostgresConfig::from_env")?;
Expand All @@ -27,15 +29,15 @@ pub(crate) async fn run() -> anyhow::Result<()> {
let total_batches_committed: U256 = CallFunctionArgs::new("getTotalBatchesCommitted", ())
.for_contract(
contracts_config.diamond_proxy_addr,
&zksync_contracts::hyperchain_contract(),
&helper::hyperchain_contract(),
)
.call(&query_client)
.await?;

let total_batches_verified: U256 = CallFunctionArgs::new("getTotalBatchesVerified", ())
.for_contract(
contracts_config.diamond_proxy_addr,
&zksync_contracts::hyperchain_contract(),
&helper::hyperchain_contract(),
)
.call(&query_client)
.await?;
Expand Down Expand Up @@ -74,17 +76,14 @@ pub(crate) async fn run() -> anyhow::Result<()> {
);

let node_verification_key_hash: H256 = CallFunctionArgs::new("verificationKeyHash", ())
.for_contract(
contracts_config.verifier_addr,
&zksync_contracts::verifier_contract(),
)
.for_contract(contracts_config.verifier_addr, &helper::verifier_contract())
.call(&query_client)
.await?;

let node_verifier_params: VerifierParams = CallFunctionArgs::new("getVerifierParams", ())
.for_contract(
contracts_config.diamond_proxy_addr,
&zksync_contracts::hyperchain_contract(),
&helper::hyperchain_contract(),
)
.call(&query_client)
.await?;
Expand Down
14 changes: 8 additions & 6 deletions prover/prover_cli/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::io::Write;
use std::{io::Write, path::PathBuf};

pub fn get_envfile() -> anyhow::Result<String> {
use crate::helper::core_workspace_dir_or_current_dir;

pub fn get_envfile() -> anyhow::Result<PathBuf> {
if let Ok(envfile) = std::env::var("PLI__CONFIG") {
return Ok(envfile);
return Ok(envfile.into());
}
Ok(std::env::var("ZKSYNC_HOME").map(|home| home + "/etc/pliconfig")?)
Ok(core_workspace_dir_or_current_dir().join("/etc/pliconfig"))
}

pub fn load_envfile(path: impl AsRef<std::path::Path>) -> anyhow::Result<()> {
Expand All @@ -13,7 +15,6 @@ pub fn load_envfile(path: impl AsRef<std::path::Path>) -> anyhow::Result<()> {
.filter(|l| !l.starts_with('#'))
.filter_map(|l| l.split_once('='))
.for_each(|(k, v)| std::env::set_var(k, v));

Ok(())
}

Expand All @@ -28,7 +29,8 @@ pub fn update_envfile(
let mut out = std::io::BufWriter::new(std::fs::File::create_new(&swapfile)?);
let mut found = false;

std::fs::read_to_string(path)?
std::fs::read_to_string(path)
.unwrap_or_default()
.lines()
.map(|l| {
if l.starts_with(&prefix) {
Expand Down
47 changes: 47 additions & 0 deletions prover/prover_cli/src/helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use std::{
fs::File,
path::{Path, PathBuf},
};

use zksync_types::ethabi::Contract;
use zksync_utils::locate_workspace;

const ZKSYNC_HYPERCHAIN_CONTRACT_FILE: &str =
"contracts/l1-contracts/artifacts/contracts/state-transition/chain-interfaces/IZkSyncHyperchain.sol/IZkSyncHyperchain.json";
const VERIFIER_CONTRACT_FILE: &str =
"contracts/l1-contracts/artifacts/contracts/state-transition/Verifier.sol/Verifier.json";

pub fn hyperchain_contract() -> Contract {
load_contract_if_present(ZKSYNC_HYPERCHAIN_CONTRACT_FILE)
}

pub fn verifier_contract() -> Contract {
load_contract_if_present(VERIFIER_CONTRACT_FILE)
}

fn read_file_to_json_value(path: &PathBuf) -> serde_json::Value {
serde_json::from_reader(
File::open(&path).unwrap_or_else(|e| panic!("Failed to open file {:?}: {}", path, e)),
)
.unwrap_or_else(|e| panic!("Failed to parse file {:?}: {}", path, e))
}

fn load_contract_if_present(path: &str) -> Contract {
let home = core_workspace_dir_or_current_dir();
let path = Path::new(&home).join(path);
path.exists()
.then(|| {
serde_json::from_value(read_file_to_json_value(&path)["abi"].take()).unwrap_or_else(
|e| panic!("Failed to parse contract abi from file {:?}: {}", path, e),
)
})
.unwrap_or_else(|| {
panic!("Failed to load contract from {:?}", path);
})
}

pub fn core_workspace_dir_or_current_dir() -> PathBuf {
locate_workspace()
.map(|a| a.join(".."))
.unwrap_or_else(|| PathBuf::from("."))
}
1 change: 1 addition & 0 deletions prover/prover_cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod cli;
pub mod commands;
pub mod config;
pub mod helper;
2 changes: 0 additions & 2 deletions prover/prover_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ async fn main() {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::ERROR)
.init();

ColoCarletti marked this conversation as resolved.
Show resolved Hide resolved
config::get_envfile()
.and_then(config::load_envfile)
.inspect_err(|err| {
tracing::error!("{err:?}");
std::process::exit(1);
})
.unwrap();

ColoCarletti marked this conversation as resolved.
Show resolved Hide resolved
match cli::start().await {
Ok(_) => {}
Err(err) => {
Expand Down
Loading