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

refactor: add env module and global env var #9

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ reth-libmdbx = { git = "https://github.com/0xEigenLabs/reth", package = "reth-li
ethers-providers = { version = "2.0.14", features = ["ws"] }
ethers-core = { version = "2.0.14", default-features = false }

# lazy_static
once_cell = "1.8.0"

# Async
futures = "0.3.26"
Expand Down
22 changes: 22 additions & 0 deletions src/env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! This module contains the environment variables for the EigenZeth service

use once_cell::sync::Lazy;

/// EigenZethEnv is a struct that holds the environment variables
pub struct EigenZethEnv {
pub db_path: String,
pub l1addr: String,
pub prover_addr: String,
pub curve_type: String,
pub host: String,
}

/// EIGEN_ZETH_ENV is a global variable that holds the environment variables,
/// it is lazy loaded and thread safe
pub static EIGEN_ZETH_ENV: Lazy<EigenZethEnv> = Lazy::new(|| EigenZethEnv {
db_path: std::env::var("ZETH_OPERATOR_DB").unwrap(),
l1addr: std::env::var("ZETH_L2_ADDR").unwrap(),
prover_addr: std::env::var("PROVER_ADDR").unwrap_or("http://127.0.0.1:50061".to_string()),
curve_type: std::env::var("CURVE_TYPE").unwrap_or("BN128".to_string()),
host: std::env::var("HOST").unwrap_or(":8545".to_string()),
});
16 changes: 10 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ mod db;
mod operator;

mod batchproposer;
mod env;

use crate::rpc::eigen::EigenRpcExtApiServer;

use crate::env::EIGEN_ZETH_ENV;
use tokio::select;
use tokio::signal::unix::signal;
use tokio::signal::unix::SignalKind;
Expand Down Expand Up @@ -348,10 +350,12 @@ where
#[tokio::main]
async fn main() -> eyre::Result<()> {
env_logger::init();
let db_path = std::env::var("ZETH_OPERATOR_DB")?;
let l1addr = std::env::var("ZETH_L2_ADDR")?;
let prover_addr = std::env::var("PROVER_ADDR").unwrap_or("http://127.0.0.1:50061".to_string());
let mut op = operator::Operator::new(&db_path, &l1addr, &prover_addr);

let mut op = operator::Operator::new(
&EIGEN_ZETH_ENV.db_path,
&EIGEN_ZETH_ENV.l1addr,
&EIGEN_ZETH_ENV.prover_addr,
);

let mut sigterm = signal(SignalKind::terminate()).unwrap();
let mut sigint = signal(SignalKind::interrupt()).unwrap();
Expand Down Expand Up @@ -412,8 +416,8 @@ async fn main() -> eyre::Result<()> {
server.merge_configured(custom_rpc.into_rpc())?;

// Start the server & keep it alive
let host = std::env::var("HOST").unwrap_or(":8545".to_string());
let server_args = RpcServerConfig::http(Default::default()).with_http_address(host.parse()?);
let server_args =
RpcServerConfig::http(Default::default()).with_http_address(EIGEN_ZETH_ENV.host.parse()?);
println!("Node started");
let _handle = server_args.start(server).await?;

Expand Down
7 changes: 3 additions & 4 deletions src/prover/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// TODO: Fix me
#![allow(dead_code)]

use crate::env::EIGEN_ZETH_ENV;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can name it GLOBAL_ENV

use crate::prover::provider::prover_service::prover_request::RequestType;
use crate::prover::provider::prover_service::prover_response::ResponseType;
use crate::prover::provider::prover_service::prover_service_client::ProverServiceClient;
Expand Down Expand Up @@ -203,10 +204,8 @@ impl ProverChannel {
id: uuid::Uuid::new_v4().to_string(),
request_type: Some(RequestType::GenFinalProof(GenFinalProofRequest {
recursive_proof: recursive_proof.clone(),
// TODO: from config or env
curve_name: "".to_string(),
// TODO: what's the aggregator address?
aggregator_addr: "".to_string(),
curve_name: EIGEN_ZETH_ENV.curve_type.clone(),
aggregator_addr: EIGEN_ZETH_ENV.host.clone(),
})),
};
self.request_sender.send(request).await?;
Expand Down
Loading