deal with env variable SCROLL_PROVER_ASSETS_DIR for two circuits (#1361)

This commit is contained in:
Mengran Lan
2024-06-05 19:30:11 +08:00
committed by GitHub
parent 971e6c5aa7
commit c6d2c22bce
3 changed files with 49 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use std::fs::File;
use anyhow::Result;
use anyhow::{bail, Result};
use crate::types::ProofType;
@@ -51,3 +51,39 @@ impl Config {
Config::from_reader(&file)
}
}
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]);
}
}
}

View File

@@ -12,9 +12,9 @@ mod zk_circuits_handler;
use clap::{Parser, ArgAction};
use anyhow::Result;
use config::Config;
use config::{Config, AssetsDirEnvConfig};
use prover::Prover;
use std::rc::Rc;
use std::{f64::consts::E, rc::Rc};
use task_cache::{ClearCacheCoordinatorListener, TaskCache};
use task_processor::TaskProcessor;
use log;
@@ -48,6 +48,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let config: Config = Config::from_file(args.config_file)?;
if let Err(e) = AssetsDirEnvConfig::init() {
log::error!("AssetsDirEnvConfig init failed: {}", e);
std::process::exit(-2);
}
let task_cache = Rc::new(TaskCache::new(&config.db_path)?);
let coordinator_listener = Box::new(ClearCacheCoordinatorListener {

View File

@@ -7,7 +7,7 @@ use curie::NextCircuitsHandler;
use std::collections::HashMap;
use std::{cell::RefCell, rc::Rc};
use super::geth_client::GethClient;
use crate::{config::Config, types::{ProofType, Task}};
use crate::{config::{Config, AssetsDirEnvConfig}, types::{ProofType, Task}};
type HardForkName = String;
@@ -41,6 +41,8 @@ impl<'a> CircuitsHandlerProvider<'a> {
let mut m: HashMap<HardForkName, CircuitsHandlerBuilder> = HashMap::new();
fn handler_builder(proof_type: ProofType, config: &Config, geth_client: Option<Rc<RefCell<GethClient>>>) -> Result<Box<dyn CircuitsHandler>> {
log::info!("now init zk circuits handler, hard_fork_name: {}", &config.low_version_circuit.hard_fork_name);
AssetsDirEnvConfig::enable_first();
BaseCircuitsHandler::new(proof_type,
&config.low_version_circuit.params_path,
&config.low_version_circuit.assets_path,
@@ -50,6 +52,8 @@ impl<'a> CircuitsHandlerProvider<'a> {
m.insert(config.low_version_circuit.hard_fork_name.clone(), handler_builder);
fn next_handler_builder(proof_type: ProofType, config: &Config, geth_client: Option<Rc<RefCell<GethClient>>>) -> Result<Box<dyn CircuitsHandler>> {
log::info!("now init zk circuits handler, hard_fork_name: {}", &config.high_version_circuit.hard_fork_name);
AssetsDirEnvConfig::enable_second();
NextCircuitsHandler::new(proof_type,
&config.high_version_circuit.params_path,
&config.high_version_circuit.assets_path,