Skip to content

Commit

Permalink
revert AssetsDirEnvConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
yiweichi committed Jan 10, 2025
1 parent 5ee0d7a commit 4c83394
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
51 changes: 51 additions & 0 deletions prover/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use anyhow::{bail, Result};

static SCROLL_PROVER_ASSETS_DIR_ENV_NAME: &str = "SCROLL_PROVER_ASSETS_DIR";
static mut SCROLL_PROVER_ASSETS_DIRS: Vec<String> = vec![];

#[derive(Debug)]
pub struct AssetsDirEnvConfig {}

impl AssetsDirEnvConfig {
pub fn init() -> Result<()> {
let value = std::env::var(SCROLL_PROVER_ASSETS_DIR_ENV_NAME)?;
let dirs: Vec<&str> = value.split(',').collect();
if dirs.len() != 2 {
bail!("env variable SCROLL_PROVER_ASSETS_DIR value must be 2 parts seperated by comma.")
}
unsafe {
SCROLL_PROVER_ASSETS_DIRS = dirs.into_iter().map(|s| s.to_string()).collect();
log::info!(
"init SCROLL_PROVER_ASSETS_DIRS: {:?}",
SCROLL_PROVER_ASSETS_DIRS
);
}
Ok(())
}

pub fn enable_first() {
unsafe {
log::info!(
"set env {SCROLL_PROVER_ASSETS_DIR_ENV_NAME} to {}",
&SCROLL_PROVER_ASSETS_DIRS[0]
);
std::env::set_var(
SCROLL_PROVER_ASSETS_DIR_ENV_NAME,
&SCROLL_PROVER_ASSETS_DIRS[0],
);
}
}

pub fn enable_second() {
unsafe {
log::info!(
"set env {SCROLL_PROVER_ASSETS_DIR_ENV_NAME} to {}",
&SCROLL_PROVER_ASSETS_DIRS[1]
);
std::env::set_var(
SCROLL_PROVER_ASSETS_DIR_ENV_NAME,
&SCROLL_PROVER_ASSETS_DIRS[1],
);
}
}
}
1 change: 1 addition & 0 deletions prover/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(lazy_cell)]
#![feature(core_intrinsics)]

mod config;
mod prover;
mod types;
mod utils;
Expand Down
9 changes: 8 additions & 1 deletion prover/src/zk_circuits_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod common;
mod darwin;
mod darwin_v2;

use crate::{types::ProverType, utils::get_circuit_types};
use crate::{config::AssetsDirEnvConfig, types::ProverType, utils::get_circuit_types};
use anyhow::{bail, Result};
use async_trait::async_trait;
use darwin::DarwinHandler;
Expand Down Expand Up @@ -44,6 +44,11 @@ impl CircuitsHandlerProvider {
pub fn new(config: LocalProverConfig) -> Result<Self> {
let mut m: HashMap<HardForkName, CircuitsHandlerBuilder> = HashMap::new();

if let Err(e) = AssetsDirEnvConfig::init() {
log::error!("AssetsDirEnvConfig init failed: {:#}", e);
std::process::exit(-2);
}

fn handler_builder(
prover_types: Vec<ProverType>,
config: &LocalProverConfig,
Expand All @@ -52,6 +57,7 @@ impl CircuitsHandlerProvider {
"now init zk circuits handler, hard_fork_name: {}",
&config.low_version_circuit.hard_fork_name
);
AssetsDirEnvConfig::enable_first();
DarwinHandler::new(
prover_types,
&config.low_version_circuit.params_path,
Expand All @@ -72,6 +78,7 @@ impl CircuitsHandlerProvider {
"now init zk circuits handler, hard_fork_name: {}",
&config.high_version_circuit.hard_fork_name
);
AssetsDirEnvConfig::enable_second();
DarwinV2Handler::new(
prover_types,
&config.high_version_circuit.params_path,
Expand Down

0 comments on commit 4c83394

Please sign in to comment.