-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: impl settlement * feat: impl settlement * feat: impl settlement * refactor: mvoe zeth_db_path to GLOBAL_ENV, fix ci * feat: refactor settlement, impl eigen_bridge, impl eigen_global_exit_root, add settlement env * refactor: remove prefix "eigen" * refactor: start with CLI, move settlement layer env to config file * fix: fix lint * refactor: support selection of DB, fix operator, move specific env to config * docs: update readme * style: update fmt * refactor: update the L1 provider_url --------- Co-authored-by: eigmax <stephen@ieigen.com>
- Loading branch information
1 parent
3937a00
commit 3cef759
Showing
28 changed files
with
2,269 additions
and
610 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[mdbx_config] | ||
path = "/tmp/operator" | ||
max_dbs = 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[ethereum_settlement_config] | ||
provider_url = "http://localhost:8545" | ||
|
||
[ethereum_settlement_config.local_wallet] | ||
private_key = "0x76af8cc59ecfabf983d423e2054b07c11212cabc532062da0bd8067c59cf4a40" | ||
chain_id = 12345 | ||
|
||
[ethereum_settlement_config.l1_contracts_addr] | ||
bridge = "0x732200433EE79cCBf5842F9b5aD8fda6BF569F01" | ||
global_exit = "0xAC97e12d0Ae20B2E0BF94e8Bd5752494577fC799" | ||
zkvm = "0x12bfb8B59144b96bE5E74ECbC9896667261c004A" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,30 @@ | ||
use crate::commands::{chain_info::ChainInfoCmd, config::ConfigCmd, run::RunCmd}; | ||
use anyhow::{bail, Result}; | ||
|
||
/// Cli is the root command for the CLI. | ||
#[derive(clap::Parser, Debug, Clone)] | ||
#[command(version, author, about)] | ||
pub struct Cli { | ||
#[command(subcommand)] | ||
pub subcommand: Option<SubCommand>, | ||
} | ||
|
||
#[derive(clap::Subcommand, Debug, Clone)] | ||
pub enum SubCommand { | ||
Run(RunCmd), | ||
ChainInfo(ChainInfoCmd), | ||
Config(ConfigCmd), | ||
} | ||
|
||
impl Cli { | ||
pub async fn run(&self) -> Result<()> { | ||
match &self.subcommand { | ||
Some(SubCommand::Run(cmd)) => cmd.run().await, | ||
Some(SubCommand::ChainInfo(cmd)) => cmd.run().await, | ||
Some(SubCommand::Config(cmd)) => cmd.run().await, | ||
None => { | ||
bail!("No subcommand provided") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use anyhow::Result; | ||
|
||
/// ChainInfoCmd used to print the Eigen-Zeth information. | ||
#[derive(clap::Parser, Debug, Clone, PartialEq, Eq)] | ||
pub struct ChainInfoCmd {} | ||
|
||
impl ChainInfoCmd { | ||
pub async fn run(&self) -> Result<()> { | ||
unimplemented!("TODO: implement ChainInfoCmd::run()") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use anyhow::Result; | ||
|
||
/// ConfigCmd used to write configuration to the stdout. | ||
#[derive(clap::Parser, Debug, Clone, PartialEq, Eq)] | ||
pub struct ConfigCmd {} | ||
|
||
impl ConfigCmd { | ||
pub async fn run(&self) -> Result<()> { | ||
unimplemented!("TODO: implement ConfigCmd::run()") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub(crate) mod chain_info; | ||
pub(crate) mod config; | ||
pub(crate) mod run; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
use std::fmt; | ||
|
||
use anyhow::Result; | ||
use tokio::select; | ||
use tokio::signal::unix::{signal, SignalKind}; | ||
use tokio::sync::mpsc; | ||
|
||
use crate::config::env::GLOBAL_ENV; | ||
use crate::custom_reth; | ||
use crate::db::lfs; | ||
use crate::operator; | ||
use crate::settlement::ethereum::EthereumSettlementConfig; | ||
use crate::settlement::NetworkSpec; | ||
|
||
/// The `RunCmd` struct is a command that runs the eigen-zeth. | ||
#[derive(clap::Args, Debug, Clone, PartialEq, Eq)] | ||
#[command(version, author, about, long_about)] | ||
pub struct RunCmd { | ||
/// The log level of the node. | ||
#[arg( | ||
long, | ||
value_name = "LOG_LEVEL", | ||
verbatim_doc_comment, | ||
default_value_t = LogLevel::Debug, | ||
ignore_case = true, | ||
)] | ||
pub log_level: LogLevel, | ||
|
||
/// The settlement layer to use. | ||
#[arg( | ||
long, | ||
default_value_t = SettlementLayer::Ethereum, | ||
verbatim_doc_comment | ||
)] | ||
pub settlement: SettlementLayer, | ||
|
||
/// Path to a file containing the settlement configuration. | ||
#[arg( | ||
long, | ||
value_name = "FILE", | ||
value_hint = clap::ValueHint::FilePath, | ||
requires = "settlement", | ||
default_value = "configs/settlement.toml" | ||
)] | ||
pub settlement_conf: Option<String>, | ||
|
||
#[clap(flatten)] | ||
pub base_params: BaseParams, | ||
} | ||
|
||
#[derive(clap::Args, Debug, Clone, PartialEq, Eq)] | ||
pub struct BaseParams { | ||
#[clap(flatten)] | ||
pub databases: DatabaseParams, | ||
|
||
/// Aggregator's EOA address, used to prove batch by the aggregator. | ||
#[arg( | ||
long, | ||
value_name = "EOA_ADDR", | ||
verbatim_doc_comment, | ||
default_value = "479881985774944702531460751064278034642760119942" | ||
)] | ||
pub aggregator_addr: String, | ||
} | ||
|
||
#[derive(clap::Args, Debug, Clone, PartialEq, Eq)] | ||
pub struct DatabaseParams { | ||
/// Choose a supported database. | ||
#[arg( | ||
long, | ||
value_name = "DB", | ||
verbatim_doc_comment, | ||
default_value_t = Database::Mdbx, | ||
ignore_case = true, | ||
)] | ||
pub database: Database, | ||
|
||
/// Path to a file containing the database configuration. | ||
#[arg( | ||
long, | ||
value_name = "FILE", | ||
value_hint = clap::ValueHint::FilePath, | ||
requires = "database", | ||
default_value = "configs/database.toml" | ||
)] | ||
pub database_conf: String, | ||
} | ||
|
||
#[derive(Debug, Clone, Eq, PartialEq, clap::ValueEnum)] | ||
pub enum Database { | ||
Memory, | ||
Mdbx, | ||
} | ||
|
||
impl fmt::Display for Database { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Database::Memory => write!(f, "memory"), | ||
Database::Mdbx => write!(f, "mdbx"), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Eq, PartialEq, clap::ValueEnum)] | ||
pub enum LogLevel { | ||
Trace, | ||
Debug, | ||
Info, | ||
Warn, | ||
Error, | ||
} | ||
|
||
impl fmt::Display for LogLevel { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
LogLevel::Debug => write!(f, "debug"), | ||
LogLevel::Info => write!(f, "info"), | ||
LogLevel::Warn => write!(f, "warn"), | ||
LogLevel::Error => write!(f, "error"), | ||
LogLevel::Trace => write!(f, "trace"), | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for SettlementLayer { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
SettlementLayer::Ethereum => write!(f, "ethereum"), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Eq, PartialEq, clap::ValueEnum)] | ||
#[non_exhaustive] | ||
pub enum SettlementLayer { | ||
Ethereum, | ||
} | ||
|
||
impl RunCmd { | ||
pub async fn run(&self) -> Result<()> { | ||
// initialize the logger | ||
std::env::set_var("RUST_LOG", self.log_level.to_string()); | ||
env_logger::init(); | ||
log::info!("Initialized logger with level: {}", self.log_level); | ||
|
||
// Load the settlement configuration | ||
let settlement_spec = match self.settlement { | ||
SettlementLayer::Ethereum => match &self.settlement_conf { | ||
None => { | ||
log::info!("Using Ethereum SettlementLayer"); | ||
return Err(anyhow::anyhow!( | ||
"Settlement configuration is required for Ethereum settlement layer" | ||
)); | ||
} | ||
Some(settlement_conf_path) => { | ||
log::info!("Using Ethereum SettlementLayer"); | ||
NetworkSpec::Ethereum(EthereumSettlementConfig::from_conf_path( | ||
settlement_conf_path, | ||
)?) | ||
} | ||
}, | ||
}; | ||
|
||
// Load the database configuration | ||
let db_config = match self.base_params.databases.database { | ||
Database::Memory => { | ||
log::info!("Using in-memory database"); | ||
lfs::DBConfig::Memory | ||
} | ||
Database::Mdbx => { | ||
log::info!("Using mdbx database"); | ||
lfs::DBConfig::Mdbx(lfs::libmdbx::Config::from_conf_path( | ||
&self.base_params.databases.database_conf, | ||
)?) | ||
} | ||
}; | ||
|
||
let aggregator_addr = &self.base_params.aggregator_addr; | ||
log::info!( | ||
"Load Aggregator address: {}", | ||
self.base_params.aggregator_addr | ||
); | ||
|
||
// Initialize the operator | ||
let mut op = operator::Operator::new( | ||
&GLOBAL_ENV.l1addr, | ||
&GLOBAL_ENV.prover_addr, | ||
settlement_spec, | ||
db_config, | ||
aggregator_addr, | ||
) | ||
.unwrap(); | ||
|
||
let mut sigterm = signal(SignalKind::terminate()).unwrap(); | ||
let mut sigint = signal(SignalKind::interrupt()).unwrap(); | ||
|
||
// initialize the signal channel | ||
let (stop_tx, stop_rx) = mpsc::channel::<()>(1); | ||
|
||
// Handle the SIGTERM and SIGINT signals | ||
tokio::spawn(async move { | ||
#[allow(clippy::let_underscore_future)] | ||
#[allow(clippy::never_loop)] | ||
loop { | ||
select! { | ||
_ = sigterm.recv() => { | ||
println!("Recieve SIGTERM"); | ||
break; | ||
} | ||
_ = sigint.recv() => { | ||
println!("Recieve SIGTERM"); | ||
break; | ||
} | ||
}; | ||
} | ||
stop_tx.send(()).await.unwrap(); | ||
}); | ||
|
||
// Launch the custom reth service | ||
custom_reth::launch_custom_node().await?; | ||
|
||
// Run the operator | ||
op.run(stop_rx).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub(crate) mod env; |
Oops, something went wrong.