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 rollup initialization #1714

Open
wants to merge 12 commits into
base: nightly
Choose a base branch
from
2 changes: 2 additions & 0 deletions Cargo.lock

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

132 changes: 132 additions & 0 deletions bin/citrea/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
use anyhow::Context;
use citrea::NetworkArg;
use citrea_common::{
from_toml_path, BatchProverConfig, FromEnv, LightClientProverConfig, SequencerConfig,
};
use clap::{command, Parser};

#[derive(clap::ValueEnum, Clone, Debug)]
pub(crate) enum SupportedDaLayer {
Mock,
Bitcoin,
}

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub(crate) struct Args {
/// The mode in which the node runs.
/// This determines which guest code to use.
/// Default is Mainnet.
#[clap(short, long, default_value_t, value_enum)]
pub(crate) network: NetworkArg,

/// Run the development chain
#[arg(long, default_value_t)]
pub(crate) dev: bool,

/// Run the regtest chain
#[arg(long, default_value_t, conflicts_with = "dev")]
pub(crate) dev_all_forks: bool,

/// Path to the genesis configuration.
/// Defines the genesis of module states like evm.
#[arg(long)]
pub(crate) genesis_paths: String,

/// The data layer type.
#[arg(long, default_value = "mock")]
pub(crate) da_layer: SupportedDaLayer,

/// The path to the rollup config, if a string is provided, it will be used as the path to the rollup config, otherwise environment variables will be used.
#[arg(long)]
pub(crate) rollup_config_path: Option<String>,

/// The option to run the node in sequencer mode, if a string is provided, it will be used as the path to the sequencer config, otherwise environment variables will be used.
#[arg(long, conflicts_with_all = ["batch_prover", "light_client_prover"])]
pub(crate) sequencer: Option<Option<String>>,

/// The option to run the node in batch prover mode, if a string is provided, it will be used as the path to the batch prover config, otherwise the environment variables will be used.
#[arg(long, conflicts_with_all = ["sequencer", "light_client_prover"])]
pub(crate) batch_prover: Option<Option<String>>,

/// The option to run the node in light client prover mode, if a string is provided, it will be used as the path to the light client prover config, otherwise the environment variables will be used.
#[arg(long, conflicts_with_all = ["sequencer", "batch_prover"])]
pub(crate) light_client_prover: Option<Option<String>>,

/// Logging verbosity
#[arg(long, short = 'v', action = clap::ArgAction::Count, default_value = "2")]
pub(crate) verbose: u8,
/// Logging verbosity
#[arg(long, short = 'q', action)]
pub(crate) quiet: bool,
}

pub(crate) enum NodeType {
Sequencer(SequencerConfig),
FullNode,
BatchProver(BatchProverConfig),
LightClientProver(LightClientProverConfig),
}

pub(crate) fn client_from_args(args: &Args) -> anyhow::Result<NodeType> {
let sequencer_config = match &args.sequencer {
Some(Some(path)) => Some(
from_toml_path(path)
.context("Failed to read sequencer configuration from the config file")?,
),
Some(None) => Some(
SequencerConfig::from_env()
.context("Failed to read sequencer configuration from the environment")?,
),
None => None,
};

let batch_prover_config = match &args.batch_prover {
Some(Some(path)) => Some(
from_toml_path(path)
.context("Failed to read prover configuration from the config file")?,
),
Some(None) => Some(
BatchProverConfig::from_env()
.context("Failed to read prover configuration from the environment")?,
),
None => None,
};

let light_client_prover_config = match &args.light_client_prover {
Some(Some(path)) => Some(
from_toml_path(path)
.context("Failed to read prover configuration from the config file")?,
),
Some(None) => Some(
LightClientProverConfig::from_env()
.context("Failed to read prover configuration from the environment")?,
),
None => None,
};

if batch_prover_config.is_some() && sequencer_config.is_some() {
return Err(anyhow::anyhow!(
"Cannot run in both batch prover and sequencer mode at the same time"
));
}
if batch_prover_config.is_some() && light_client_prover_config.is_some() {
return Err(anyhow::anyhow!(
"Cannot run in both batch prover and light client prover mode at the same time"
));
}
if light_client_prover_config.is_some() && sequencer_config.is_some() {
return Err(anyhow::anyhow!(
"Cannot run in both light client prover and sequencer mode at the same time"
));
}
rakanalh marked this conversation as resolved.
Show resolved Hide resolved

if let Some(sequencer_config) = sequencer_config {
return Ok(NodeType::Sequencer(sequencer_config));
} else if let Some(batch_prover_config) = batch_prover_config {
return Ok(NodeType::BatchProver(batch_prover_config));
} else if let Some(light_client_prover_config) = light_client_prover_config {
return Ok(NodeType::LightClientProver(light_client_prover_config));
}
return Ok(NodeType::FullNode);
}
Loading