Skip to content

Commit

Permalink
Merge branch 'main' of github.com:chainwayxyz/citrea-e2e into fee_config
Browse files Browse the repository at this point in the history
  • Loading branch information
jfldde committed Jan 20, 2025
2 parents 963465e + e6140b2 commit 6cee848
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 16 deletions.
18 changes: 16 additions & 2 deletions src/bitcoin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
collections::HashSet,
collections::{HashMap, HashSet},
fs::File,
future::Future,
process::Stdio,
Expand Down Expand Up @@ -165,6 +165,16 @@ impl BitcoinNode {
) -> bitcoincore_rpc::Result<Vec<bitcoin::BlockHash>> {
RpcApi::generate(self, block_num, None).await
}

pub async fn generate_block(
&self,
// Address to send the block reward to
output: String,
// Either raw txs or txids, should be in mempool and in correct order
transactions: Vec<String>,
) -> bitcoincore_rpc::Result<HashMap<String, String>> {
RpcApi::call(self, "generateblock", &[output.into(), transactions.into()]).await
}
}

#[async_trait]
Expand Down Expand Up @@ -273,7 +283,11 @@ impl Restart for BitcoinNode {
}
}

async fn start(&mut self, config: Option<Self::Config>) -> Result<()> {
async fn start(
&mut self,
config: Option<Self::Config>,
_extra_args: Option<Vec<String>>,
) -> Result<()> {
if let Some(config) = config {
self.config = config;
}
Expand Down
4 changes: 0 additions & 4 deletions src/citrea_config/batch_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ pub struct BatchProverConfig {
pub proof_sampling_number: usize,
/// If true prover will try to recover ongoing proving sessions
pub enable_recovery: bool,
/// Wether to always use the latest ELF or not
pub use_latest_elf: bool,
}

impl Default for BatchProverConfig {
Expand All @@ -49,7 +47,6 @@ impl Default for BatchProverConfig {
proving_mode: ProverGuestRunConfig::Execute,
proof_sampling_number: 0,
enable_recovery: true,
use_latest_elf: true,
}
}
}
Expand Down Expand Up @@ -101,7 +98,6 @@ mod tests {
proving_mode: ProverGuestRunConfig::Skip,
proof_sampling_number: 500,
enable_recovery: true,
use_latest_elf: true,
};
assert_eq!(config, expected);
}
Expand Down
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,
DevAllForks,
}

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::DevAllForks => write!(f, "dev-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
3 changes: 3 additions & 0 deletions src/config/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{env, path::PathBuf, time::Duration};

use tempfile::TempDir;

use super::CitreaMode;
use crate::utils::generate_test_id;

#[derive(Clone, Default)]
Expand Down Expand Up @@ -60,6 +61,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 +87,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
18 changes: 12 additions & 6 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 @@ -124,7 +125,7 @@ where
})
}

fn spawn(config: &C) -> Result<SpawnOutput> {
fn spawn(config: &C, extra_args: Option<Vec<String>>) -> Result<SpawnOutput> {
let citrea = get_citrea_path()?;

let kind = C::node_kind();
Expand All @@ -144,6 +145,7 @@ where

Command::new(citrea)
.args(get_citrea_args(config))
.args(extra_args.unwrap_or_default())
.envs(config.env())
.stdout(Stdio::from(stdout_file))
.stderr(Stdio::from(stderr_file))
Expand Down Expand Up @@ -190,7 +192,7 @@ where
async fn spawn(config: &Self::Config, docker: &Arc<Option<DockerEnv>>) -> Result<SpawnOutput> {
match docker.as_ref() {
Some(docker) if docker.citrea() => docker.spawn(config.to_owned().into()).await,
_ => Self::spawn(config),
_ => Self::spawn(config, None),
}
}

Expand Down Expand Up @@ -250,7 +252,11 @@ where
Ok(())
}

async fn start(&mut self, new_config: Option<Self::Config>) -> Result<()> {
async fn start(
&mut self,
new_config: Option<Self::Config>,
extra_args: Option<Vec<String>>,
) -> Result<()> {
let config = self.config_mut();

if let Some(new_config) = new_config {
Expand All @@ -271,7 +277,7 @@ where
copy_directory(old_dir, &new_dir)?;
config.set_dir(new_dir);

*self.spawn_output() = Self::spawn(config)?;
*self.spawn_output() = Self::spawn(config, extra_args)?;
self.wait_for_ready(None).await
}
}
Expand All @@ -284,7 +290,7 @@ where
let rollup_config_args = config.get_rollup_config_args();

[
vec!["--dev".to_string()],
vec![format!("--{}", config.mode())],
vec!["--da-layer".to_string(), config.da_layer().to_string()],
node_config_args,
rollup_config_args,
Expand Down
14 changes: 11 additions & 3 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,19 @@ pub trait NodeT: Send {
#[async_trait]
pub trait Restart: NodeT + Send {
async fn wait_until_stopped(&mut self) -> Result<()>;
async fn start(&mut self, new_config: Option<Self::Config>) -> Result<()>;
async fn start(
&mut self,
new_config: Option<Self::Config>,
extra_args: Option<Vec<String>>,
) -> Result<()>;

// Default implementation to support waiting for node to be fully shutdown and brough back up with new config.
async fn restart(&mut self, new_config: Option<Self::Config>) -> Result<()> {
async fn restart(
&mut self,
new_config: Option<Self::Config>,
extra_args: Option<Vec<String>>,
) -> Result<()> {
self.wait_until_stopped().await?;
self.start(new_config).await
self.start(new_config, extra_args).await
}
}
2 changes: 1 addition & 1 deletion tests/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl TestCase for RestartBitcoinTest {
assert_eq!(info.txindex, None);

// Restart node with txindex
da.restart(Some(new_conf)).await?;
da.restart(Some(new_conf), None).await?;

let block_after = da.get_block_count().await?;
let info = da.get_index_info().await?;
Expand Down

0 comments on commit 6cee848

Please sign in to comment.