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 start_rollup #1210

Merged
merged 14 commits into from
Sep 26, 2024
22 changes: 11 additions & 11 deletions bin/citrea/tests/e2e/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;

use bollard::secret::Node;
use citrea_evm::smart_contracts::SimpleStorageContract;
use citrea_stf::genesis_config::GenesisPaths;
use reth_primitives::{Address, BlockNumberOrTag, U256};
Expand All @@ -24,8 +25,7 @@ use tokio::task::JoinHandle;
use crate::evm::{init_test_rollup, make_test_client};
use crate::test_client::TestClient;
use crate::test_helpers::{
start_rollup, tempdir_with_children, wait_for_l1_block, wait_for_l2_block, wait_for_proof,
wait_for_prover_l1_height, NodeMode,
create_default_rollup_config, create_default_sequencer_config, start_rollup, tempdir_with_children, wait_for_l1_block, wait_for_l2_block, wait_for_proof, wait_for_prover_l1_height, NodeMode
};
use crate::{
DEFAULT_DEPOSIT_MEMPOOL_FETCH_LIMIT, DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
Expand Down Expand Up @@ -65,20 +65,20 @@ async fn test_all_flow() {
let (seq_port_tx, seq_port_rx) = tokio::sync::oneshot::channel();

let da_db_dir_cloned = da_db_dir.clone();
let sequencer_config = create_default_sequencer_config(Some(4), Some(true), None);
let rollup_config = create_default_rollup_config(
true,
&sequencer_db_dir,
&da_db_dir,
NodeMode::SequencerNode,
);
let seq_task = tokio::spawn(async {
start_rollup(
seq_port_tx,
GenesisPaths::from_dir(TEST_DATA_GENESIS_PATH),
None,
NodeMode::SequencerNode,
sequencer_db_dir,
da_db_dir_cloned,
4,
true,
None,
None,
Some(true),
DEFAULT_DEPOSIT_MEMPOOL_FETCH_LIMIT,
rollup_config,
Some(sequencer_config),
)
.await;
});
Expand Down
148 changes: 74 additions & 74 deletions bin/citrea/tests/test_helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use citrea::{CitreaRollupBlueprint, MockDemoRollup};
use citrea_primitives::TEST_PRIVATE_KEY;
use citrea_sequencer::SequencerConfig;
use citrea_stf::genesis_config::GenesisPaths;
use rand::seq;
use sov_mock_da::{MockAddress, MockBlock, MockDaConfig, MockDaService};
use sov_modules_api::default_signature::private_key::DefaultPrivateKey;
use sov_modules_api::PrivateKey;
Expand All @@ -22,7 +23,7 @@ use tokio::time::sleep;
use tracing::{debug, info_span, instrument, warn, Instrument};

use crate::test_client::TestClient;
use crate::DEFAULT_PROOF_WAIT_DURATION;
use crate::{DEFAULT_DEPOSIT_MEMPOOL_FETCH_LIMIT, DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT, DEFAULT_PROOF_WAIT_DURATION};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NodeMode {
Expand All @@ -36,89 +37,85 @@ pub enum NodeMode {
pub async fn start_rollup(
rpc_reporting_channel: oneshot::Sender<SocketAddr>,
rt_genesis_paths: GenesisPaths,

rollup_prover_config: Option<ProverConfig>,
node_mode: NodeMode,
rollup_db_path: PathBuf,
da_db_path: PathBuf,
min_soft_confirmations_per_commitment: u64,
include_tx_body: bool,
rollup_config: Option<FullNodeConfig<MockDaConfig>>,
//node_mode: NodeMode,

//rollup_db_path: PathBuf,
//da_db_path: PathBuf,

//min_soft_confirmations_per_commitment: u64,
//include_tx_body: bool,

rollup_config: FullNodeConfig<MockDaConfig>,
sequencer_config: Option<SequencerConfig>,
test_mode: Option<bool>,
deposit_mempool_fetch_limit: usize,

//test_mode: Option<bool>,
//deposit_mempool_fetch_limit: usize,
) {
// create rollup config default creator function and use them here for the configs
let rollup_config = rollup_config.unwrap_or_else(|| {
create_default_rollup_config(include_tx_body, &rollup_db_path, &da_db_path, node_mode)
});

let mock_demo_rollup = MockDemoRollup {};

match node_mode {
NodeMode::FullNode(_) => {
let span = info_span!("FullNode");
let rollup = CitreaRollupBlueprint::create_new_rollup(
&mock_demo_rollup,
&rt_genesis_paths,
rollup_config.clone(),
)
.instrument(span.clone())
assert_ne!(sequencer_config.is_some(), rollup_prover_config.is_some());

if sequencer_config.is_some(){
warn!(
"Starting sequencer node pub key: {:?}",
DefaultPrivateKey::from_hex(TEST_PRIVATE_KEY)
.unwrap()
.pub_key()
);
let sequencer_config = sequencer_config.unwrap();

let span = info_span!("Sequencer");
let sequencer_rollup = CitreaRollupBlueprint::create_new_sequencer(
exeokan marked this conversation as resolved.
Show resolved Hide resolved
&mock_demo_rollup,
&rt_genesis_paths,
rollup_config.clone(),
sequencer_config,
)
.instrument(span.clone())
.await
.unwrap();
sequencer_rollup
.run_and_report_rpc_port(Some(rpc_reporting_channel))
.instrument(span)
.await
.unwrap();
rollup
.run_and_report_rpc_port(Some(rpc_reporting_channel))
.instrument(span)
.await
.unwrap();
}
NodeMode::Prover(_) => {
let span = info_span!("Prover");
let rollup = CitreaRollupBlueprint::create_new_prover(
&mock_demo_rollup,
&rt_genesis_paths,
rollup_config,
rollup_prover_config.unwrap(),
)
.instrument(span.clone())
}
else if rollup_prover_config.is_some(){
let span = info_span!("Prover");
let rollup = CitreaRollupBlueprint::create_new_prover(
&mock_demo_rollup,
&rt_genesis_paths,
rollup_config,
rollup_prover_config.unwrap(),
)
.instrument(span.clone())
.await
.unwrap();
rollup
.run_and_report_rpc_port(Some(rpc_reporting_channel))
.instrument(span)
.await
.unwrap();
rollup
.run_and_report_rpc_port(Some(rpc_reporting_channel))
.instrument(span)
.await
.unwrap();
}
NodeMode::SequencerNode => {
warn!(
"Starting sequencer node pub key: {:?}",
DefaultPrivateKey::from_hex(TEST_PRIVATE_KEY)
.unwrap()
.pub_key()
);
let sequencer_config = sequencer_config.unwrap_or_else(|| {
create_default_sequencer_config(
min_soft_confirmations_per_commitment,
test_mode,
deposit_mempool_fetch_limit,
)
});

let span = info_span!("Sequencer");
let sequencer_rollup = CitreaRollupBlueprint::create_new_sequencer(
&mock_demo_rollup,
&rt_genesis_paths,
rollup_config.clone(),
sequencer_config,
)
.instrument(span.clone())
}
else {
let span = info_span!("FullNode");
let rollup = CitreaRollupBlueprint::create_new_rollup(
&mock_demo_rollup,
&rt_genesis_paths,
rollup_config.clone(),
)
.instrument(span.clone())
.await
.unwrap();
rollup
.run_and_report_rpc_port(Some(rpc_reporting_channel))
.instrument(span)
.await
.unwrap();
sequencer_rollup
.run_and_report_rpc_port(Some(rpc_reporting_channel))
.instrument(span)
.await
.unwrap();
}
}
}

Expand Down Expand Up @@ -168,14 +165,17 @@ pub fn create_default_rollup_config(
}

pub fn create_default_sequencer_config(
min_soft_confirmations_per_commitment: u64,
min_soft_confirmations_per_commitment: Option<u64>,
test_mode: Option<bool>,
deposit_mempool_fetch_limit: usize,
deposit_mempool_fetch_limit: Option<usize>,
) -> SequencerConfig {
let min_soft_confirmations_per_commitment = min_soft_confirmations_per_commitment.unwrap_or(DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT);
let test_mode = test_mode.unwrap_or(false);
let deposit_mempool_fetch_limit = deposit_mempool_fetch_limit.unwrap_or(DEFAULT_DEPOSIT_MEMPOOL_FETCH_LIMIT);
SequencerConfig {
private_key: TEST_PRIVATE_KEY.to_string(),
min_soft_confirmations_per_commitment,
test_mode: test_mode.unwrap_or(false),
test_mode,
deposit_mempool_fetch_limit,
mempool_conf: Default::default(),
da_update_interval_ms: 500,
Expand Down