From 150dadf1cae7433a8b048c4a28e864754be04009 Mon Sep 17 00:00:00 2001 From: Terry <644052732@qq.com> Date: Thu, 25 Apr 2024 17:17:35 +0800 Subject: [PATCH] refactor: mvoe zeth_db_path to GLOBAL_ENV, fix ci --- Cargo.lock | 20 ++++++++++++------- src/env.rs | 9 ++++++--- src/main.rs | 4 ++-- src/operator.rs | 15 ++++++++------ .../ethereum/interfaces/eigen_bridge.rs | 4 +++- src/settlement/ethereum/mod.rs | 3 ++- src/settlement/mod.rs | 8 ++++++-- 7 files changed, 41 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 75d489f..dabe3fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -745,6 +745,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" + [[package]] name = "base64ct" version = "1.6.0" @@ -6575,11 +6581,11 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.7.0" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee80b0e361bbf88fd2f6e242ccd19cfda072cb0faa6ae694ecee08199938569a" +checksum = "2c85f8e96d1d6857f13768fcbd895fcb06225510022a2774ed8b5150581847b0" dependencies = [ - "base64 0.21.7", + "base64 0.22.0", "chrono", "hex", "indexmap 1.9.3", @@ -6593,9 +6599,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.7.0" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6561dc161a9224638a31d876ccdfefbc1df91d3f3a8342eddb35f055d48c7655" +checksum = "c8b3a576c4eb2924262d5951a3b737ccaf16c931e39a2810c36f9a7e25575557" dependencies = [ "darling 0.20.8", "proc-macro2", @@ -7975,9 +7981,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134306a13c5647ad6453e8deaec55d3a44d6021970129e6188735e74bf546697" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ "windows-sys 0.52.0", ] diff --git a/src/env.rs b/src/env.rs index 5bad256..0b4f20b 100644 --- a/src/env.rs +++ b/src/env.rs @@ -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 { @@ -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 = 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()), }); diff --git a/src/main.rs b/src/main.rs index 7680fac..3894b23 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(), diff --git a/src/operator.rs b/src/operator.rs index 6296f16..bf3e2a9 100644 --- a/src/operator.rs +++ b/src/operator.rs @@ -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; @@ -17,10 +21,9 @@ pub(crate) struct Operator { provider: Arc>, rx_proof: Receiver>, // 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); @@ -30,8 +33,8 @@ impl Operator { let provider = Provider::::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, diff --git a/src/settlement/ethereum/interfaces/eigen_bridge.rs b/src/settlement/ethereum/interfaces/eigen_bridge.rs index 492e570..ed20c54 100644 --- a/src/settlement/ethereum/interfaces/eigen_bridge.rs +++ b/src/settlement/ethereum/interfaces/eigen_bridge.rs @@ -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!( @@ -15,6 +15,8 @@ abigen!( ]"#, ); +// TODO: Fixme +#[allow(clippy::too_many_arguments)] pub(crate) async fn bridge_asset( address: Address, client: Arc>, diff --git a/src/settlement/ethereum/mod.rs b/src/settlement/ethereum/mod.rs index c09a533..1429d8b 100644 --- a/src/settlement/ethereum/mod.rs +++ b/src/settlement/ethereum/mod.rs @@ -28,6 +28,7 @@ impl Settlement for EthereumSettlement { token, force_update_global_exit_root, calldata, - ).await + ) + .await } } diff --git a/src/settlement/mod.rs b/src/settlement/mod.rs index f41f950..69d93dc 100644 --- a/src/settlement/mod.rs +++ b/src/settlement/mod.rs @@ -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, @@ -38,4 +42,4 @@ pub enum NetworkSpec { // }, // _ => todo!("Not supported network") // } -//} \ No newline at end of file +//}