Skip to content

Commit

Permalink
read circuit_type from env
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmountaintop authored and lispc committed Nov 5, 2024
1 parent 6727f86 commit 853c7c9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ ctor = "0.2.8"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
axum = "0.6.0"
dotenv = "0.15"
2 changes: 1 addition & 1 deletion examples/cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ async fn main() -> anyhow::Result<()> {
init_tracing();

let args = Args::parse();
let cfg: Config = Config::from_file(args.config_file)?;
let cfg: Config = Config::from_file_and_env(args.config_file)?;
let cloud_prover = CloudProver::new(
cfg.prover
.cloud
Expand Down
24 changes: 24 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::prover::CircuitType;
use dotenv::dotenv;
use serde::{Deserialize, Serialize};
use serde_json;
use std::fs::File;
Expand Down Expand Up @@ -72,4 +73,27 @@ impl Config {
let file = File::open(file_name)?;
Config::from_reader(&file)
}

pub fn from_file_and_env(file_name: String) -> anyhow::Result<Self> {
let mut cfg = Config::from_file(file_name)?;
cfg.override_with_env()?;
Ok(cfg)
}

fn override_with_env(&mut self) -> anyhow::Result<()> {
dotenv().ok();

// read circuit_type from env if set
if let Some(circuit_type) = std::env::var_os("CIRCUIT_TYPE") {
let circuit_type = circuit_type
.to_str()
.ok_or_else(|| anyhow::anyhow!("CIRCUIT_TYPE env var is not valid UTF-8"))?
.parse::<u8>()?;
self.prover.circuit_type = CircuitType::from_u8(circuit_type);
}

// TODO: PROVER_NAME_PREFIX, KEYS_DIR, COORDINATOR_BASE_URL, L2GETH_ENDPOINT, PROVING_SERVICE_BASE_URL, PROVING_SERVICE_API_KEY

Ok(())
}
}
2 changes: 1 addition & 1 deletion src/prover/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum CircuitType {
}

impl CircuitType {
fn from_u8(v: u8) -> Self {
pub fn from_u8(v: u8) -> Self {
match v {
1 => CircuitType::Chunk,
2 => CircuitType::Batch,
Expand Down

0 comments on commit 853c7c9

Please sign in to comment.