Skip to content

Commit

Permalink
refactor: mvoe zeth_db_path to GLOBAL_ENV, fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
captainlee1024 committed Apr 25, 2024
1 parent d21e87b commit 150dadf
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 22 deletions.
20 changes: 13 additions & 7 deletions Cargo.lock

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

9 changes: 6 additions & 3 deletions src/env.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! This module contains the environment variables for the EigenZeth service
use once_cell::sync::Lazy;
use std::string::ToString;

/// EigenZethEnv is a struct that holds the environment variables
pub struct EigenZethEnv {
Expand All @@ -9,14 +10,16 @@ pub struct EigenZethEnv {
pub prover_addr: String,
pub curve_type: String,
pub host: String,
pub zeth_db_path: String,
}

/// EIGEN_ZETH_ENV is a global variable that holds the environment variables,
/// it is lazy loaded and thread safe
pub static GLOBAL_ENV: Lazy<EigenZethEnv> = Lazy::new(|| EigenZethEnv {
db_path: std::env::var("ZETH_OPERATOR_DB").unwrap(),
l1addr: std::env::var("ZETH_L2_ADDR").unwrap(),
db_path: std::env::var("ZETH_OPERATOR_DB").unwrap_or("/tmp/operator".to_string()),
l1addr: std::env::var("ZETH_L2_ADDR").unwrap_or("http://localhost:8546".to_string()),
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()),
host: std::env::var("HOST").unwrap_or("0.0.0.0:8182".to_string()),
zeth_db_path: std::env::var("ZETH_DB_PATH").unwrap_or("/tmp/chain".to_string()),
});
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ async fn main() -> eyre::Result<()> {
// .build();
let spec = Arc::new(ChainSpecBuilder::mainnet().build());

let db_path = std::env::var("ZETH_DB_PATH")?;
let db_path = std::path::Path::new(&db_path);
// let db_path =;
let db_path = std::path::Path::new(&GLOBAL_ENV.zeth_db_path);
let db = Arc::new(open_db_read_only(
db_path.join("db").as_path(),
Default::default(),
Expand Down
15 changes: 9 additions & 6 deletions src/operator.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
//! Initialize all components of the eigen-zeth full node.
//! They will be launched in Run CMD.
// TODO: Fixme
#![allow(unused_imports)]

use crate::prover::ProverChannel;
use ethers_providers::{Http, Provider};
use crate::settlement::{NetworkSpec, Settlement};
use ethers_core::types::{Bytes, H160, U256};
use ethers_providers::{Http, Provider};
use std::sync::Arc;
use tokio::sync::mpsc::{self, Receiver};
use tokio::time::{interval, Duration};
use std::sync::Arc;

use crate::db::{lfs, Database};
use crate::settlement::ethereum::EthereumSettlement;
Expand All @@ -17,10 +21,9 @@ pub(crate) struct Operator {
provider: Arc<Provider<Http>>,
rx_proof: Receiver<Vec<u8>>,
// TODO: use trait object
settler: EthereumSettlement,
settler: EthereumSettlement,
}


impl Operator {
pub fn new(_db_path: &str, l1addr: &str, prover_addr: &str) -> Self {
let (sx, rx_proof) = mpsc::channel(10);
Expand All @@ -30,8 +33,8 @@ impl Operator {
let provider = Provider::<Http>::try_from(l1addr).unwrap();
let provider = Arc::new(provider);

//let settler = init_settlement(NetworkSpec::Ethereum);
let settler = EthereumSettlement{};
//let settler = init_settlement(NetworkSpec::Ethereum);
let settler = EthereumSettlement {};
Operator {
prover,
db,
Expand Down
4 changes: 3 additions & 1 deletion src/settlement/ethereum/interfaces/eigen_bridge.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Rust contract client for https://github.com/0xEigenLabs/eigen-bridge-contracts/blob/feature/bridge_contract/src/EigenBridge.sol
use anyhow::Result;
use ethers_contract::abigen;
use ethers_core::types::{Address, Bytes, U256};
use ethers_providers::{Http, Provider};
use std::sync::Arc;
use anyhow::Result;

// example: https://github.com/gakonst/ethers-rs/blob/master/examples/contracts/examples/abigen.rs#L55
abigen!(
Expand All @@ -15,6 +15,8 @@ abigen!(
]"#,
);

// TODO: Fixme
#[allow(clippy::too_many_arguments)]
pub(crate) async fn bridge_asset(
address: Address,
client: Arc<Provider<Http>>,
Expand Down
3 changes: 2 additions & 1 deletion src/settlement/ethereum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl Settlement for EthereumSettlement {
token,
force_update_global_exit_root,
calldata,
).await
)
.await
}
}
8 changes: 6 additions & 2 deletions src/settlement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
//! including the following settlement api:
//! 1. get_state: get the latest state of the settlement layer, including the state root and block number.
//! 2. update_state: update the state of the settlement layer with the given proof and public input.
// TODO: Fix me
#![allow(dead_code)]

use anyhow::Result;
use ethers_core::types::{Address, Bytes, U256};
use ethers_providers::{Http, Provider};
use std::sync::Arc;
use anyhow::Result;

pub(crate) mod ethereum;

// TODO: Fixme
#[allow(clippy::too_many_arguments)]
pub trait Settlement {
async fn bridge_asset(
&self,
Expand Down Expand Up @@ -38,4 +42,4 @@ pub enum NetworkSpec {
// },
// _ => todo!("Not supported network")
// }
//}
//}

0 comments on commit 150dadf

Please sign in to comment.