Skip to content

Commit

Permalink
CitreaMode
Browse files Browse the repository at this point in the history
  • Loading branch information
jfldde committed Jan 9, 2025
1 parent df45afe commit ad85025
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
24 changes: 24 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ impl fmt::Display for DaLayer {
}
}

#[derive(Clone, Debug, Default, Copy)]
pub enum CitreaMode {
#[default]
Dev,
AllForks,
}

impl fmt::Display for CitreaMode {
// This trait requires `fmt` with this exact signature.
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CitreaMode::Dev => write!(f, "dev"),
CitreaMode::AllForks => write!(f, "all-forks"),
}
}
}

#[derive(Clone, Debug, Default)]
pub struct FullL2NodeConfig<T> {
pub node: T,
Expand All @@ -57,6 +74,7 @@ pub struct FullL2NodeConfig<T> {
pub dir: PathBuf,
pub env: Vec<(&'static str, &'static str)>,
pub da_layer: Option<DaLayer>,
pub mode: CitreaMode,
}

impl<T> FullL2NodeConfig<T>
Expand All @@ -70,6 +88,7 @@ where
docker_image: Option<String>,
dir: PathBuf,
env: Vec<(&'static str, &'static str)>,
mode: CitreaMode,
) -> Result<Self> {
let conf = Self {
node,
Expand All @@ -78,6 +97,7 @@ where
dir,
env,
da_layer: None,
mode,
};

let kind = FullL2NodeConfig::<T>::kind();
Expand Down Expand Up @@ -190,6 +210,10 @@ where
fn da_layer(&self) -> DaLayer {
self.da_layer.clone().unwrap_or_default()
}

fn mode(&self) -> CitreaMode {
self.mode
}
}

impl<T> LogPathProvider for FullL2NodeConfig<T>
Expand Down
4 changes: 4 additions & 0 deletions src/config/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use tempfile::TempDir;

use crate::utils::generate_test_id;

use super::CitreaMode;

#[derive(Clone, Default)]
pub struct TestCaseEnv {
pub test: Vec<(&'static str, &'static str)>,
Expand Down Expand Up @@ -60,6 +62,7 @@ pub struct TestCaseConfig {
// Defaults to resources/genesis/bitcoin-regtest
pub genesis_dir: Option<String>,
pub test_id: String,
pub mode: CitreaMode,
}

impl Default for TestCaseConfig {
Expand All @@ -85,6 +88,7 @@ impl Default for TestCaseConfig {
docker: TestCaseDockerConfig::default(),
genesis_dir: None,
test_id,
mode: CitreaMode::Dev,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,27 +443,31 @@ fn generate_test_config<T: TestCase>(
citrea_docker_image.clone(),
sequencer_dir,
env.sequencer(),
test_case.mode,
)?,
batch_prover: FullBatchProverConfig::new(
batch_prover,
batch_prover_rollup,
citrea_docker_image.clone(),
batch_prover_dir,
env.batch_prover(),
test_case.mode,
)?,
light_client_prover: FullLightClientProverConfig::new(
light_client_prover,
light_client_prover_rollup,
citrea_docker_image.clone(),
light_client_prover_dir,
env.light_client_prover(),
test_case.mode,
)?,
full_node: FullFullNodeConfig::new(
(),
full_node_rollup,
citrea_docker_image,
full_node_dir,
env.full_node(),
test_case.mode,
)?,
test_case,
})
Expand Down
10 changes: 3 additions & 7 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use tracing::{debug, info, trace};

use crate::{
client::Client,
config::{BitcoinConfig, DaLayer, DockerConfig, RollupConfig},
config::{BitcoinConfig, CitreaMode, DaLayer, DockerConfig, RollupConfig},
docker::DockerEnv,
log_provider::LogPathProvider,
traits::{NodeT, Restart, SpawnOutput},
Expand Down Expand Up @@ -80,6 +80,7 @@ pub trait Config: Clone {
// Not required for `full-node`
fn get_node_config_args(&self) -> Option<Vec<String>>;
fn get_rollup_config_args(&self) -> Vec<String>;
fn mode(&self) -> CitreaMode;
}

pub struct Node<C: Config + LogPathProvider + Send + Sync> {
Expand Down Expand Up @@ -283,13 +284,8 @@ where
let node_config_args = config.get_node_config_args().unwrap_or_default();
let rollup_config_args = config.get_rollup_config_args();

let network_arg = match std::env::var("CITREA_NETWORK") {
Ok(network) => vec!["--network".to_string(), network],
_ => vec!["--dev".to_string()],
};

[
network_arg,
vec![format!("--{}", config.mode())],
vec!["--da-layer".to_string(), config.da_layer().to_string()],
node_config_args,
rollup_config_args,
Expand Down

0 comments on commit ad85025

Please sign in to comment.