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

Merged
merged 30 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0f6f838
Refactor rollup initialization
rakanalh Jan 15, 2025
59d3d3d
Move sync_l1 to common
rakanalh Jan 15, 2025
c508688
WIP move instantiation of L1BlockHandler
rakanalh Jan 15, 2025
83c440f
Remove unnecessary comment
rakanalh Jan 16, 2025
e534f81
Lots of changes
rakanalh Jan 16, 2025
700a794
Better way to spawn multiple services
rakanalh Jan 18, 2025
dfb8cb5
Finalize node initialization
rakanalh Jan 20, 2025
61f9ba7
Fix tests
rakanalh Jan 20, 2025
96f8fab
Fix clippy
rakanalh Jan 20, 2025
108f165
Rename argument
rakanalh Jan 20, 2025
e5f028a
Merge remote-tracking branch 'origin/nightly' into rakanalh/refactor-…
rakanalh Jan 20, 2025
9ac87b6
Move native stuff in light client to services
rakanalh Jan 20, 2025
2defabb
Initialize chain prior to trying to construct mempool
rakanalh Jan 21, 2025
b0d7ba5
Execute migrations before anything else
rakanalh Jan 21, 2025
a55c683
Unwrap migrations in test
rakanalh Jan 21, 2025
2b9c1f4
Make start_rpc sync
rakanalh Jan 21, 2025
bf80e7c
Fix reporting channel issue
rakanalh Jan 21, 2025
8138194
Remove RPC module param from full node
rakanalh Jan 21, 2025
7c23d45
Fix tests hanging
rakanalh Jan 22, 2025
3dc2ae3
Remove loop label
rakanalh Jan 22, 2025
2686c37
fmt
rakanalh Jan 22, 2025
5567856
Merge remote-tracking branch 'origin/nightly' into rakanalh/refactor-…
rakanalh Jan 22, 2025
adbe09d
Fetch start l1 height in the DA handler task
rakanalh Jan 22, 2025
32b030d
Add error messages
rakanalh Jan 23, 2025
d600e7f
rename client to node_type
rakanalh Jan 23, 2025
30e6b2c
Merge remote-tracking branch 'origin/nightly' into rakanalh/refactor-…
rakanalh Jan 23, 2025
f90e2d9
Pass table names in tests
rakanalh Jan 23, 2025
bb8e0f8
Pass correct table names
rakanalh Jan 23, 2025
177b0b7
Merge branch 'nightly' into rakanalh/refactor-rollup
jfldde Jan 24, 2025
fc8ed59
Use tokio unboundedsender / receiver
rakanalh Jan 25, 2025
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
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 RollupClient {
Sequencer(SequencerConfig),
FullNode,
BatchProver(BatchProverConfig),
LightClientProver(LightClientProverConfig),
}
rakanalh marked this conversation as resolved.
Show resolved Hide resolved

pub(crate) fn client_from_args(args: &Args) -> anyhow::Result<RollupClient> {
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(RollupClient::Sequencer(sequencer_config));
} else if let Some(batch_prover_config) = batch_prover_config {
return Ok(RollupClient::BatchProver(batch_prover_config));
} else if let Some(light_client_prover_config) = light_client_prover_config {
return Ok(RollupClient::LightClientProver(light_client_prover_config));
}
return Ok(RollupClient::FullNode);
}
Loading