diff --git a/bin/citrea/src/main.rs b/bin/citrea/src/main.rs index 8b9af9eb3..a4c7bcdda 100644 --- a/bin/citrea/src/main.rs +++ b/bin/citrea/src/main.rs @@ -176,7 +176,7 @@ where match rollup_client { RollupClient::Sequencer(sequencer_config) => { let mut sequencer = rollup_blueprint - .create_new_sequencer( + .create_sequencer( genesis_config, rollup_config.clone(), sequencer_config, @@ -194,7 +194,7 @@ where } } RollupClient::BatchProver(batch_prover_config) => { - let mut prover = CitreaRollupBlueprint::create_new_batch_prover( + let mut prover = CitreaRollupBlueprint::create_batch_prover( &rollup_blueprint, genesis_config, rollup_config, @@ -214,7 +214,7 @@ where } } RollupClient::LightClientProver(light_client_prover_config) => { - let mut prover = CitreaRollupBlueprint::create_new_light_client_prover( + let mut prover = CitreaRollupBlueprint::create_light_client_prover( &rollup_blueprint, rollup_config, light_client_prover_config, @@ -231,7 +231,7 @@ where } } _ => { - let mut rollup = CitreaRollupBlueprint::create_new_rollup( + let mut rollup = CitreaRollupBlueprint::create_rollup( &rollup_blueprint, genesis_config, rollup_config, diff --git a/bin/citrea/src/rollup/mod.rs b/bin/citrea/src/rollup/mod.rs index 1f72a84d4..bd736857c 100644 --- a/bin/citrea/src/rollup/mod.rs +++ b/bin/citrea/src/rollup/mod.rs @@ -1,31 +1,39 @@ +use std::collections::HashMap; use std::sync::Arc; use anyhow::{anyhow, Result}; use async_trait::async_trait; +use citrea_batch_prover::da_block_handler::L1BlockHandler; use citrea_batch_prover::CitreaBatchProver; +use citrea_common::cache::L1BlockCache; use citrea_common::tasks::manager::TaskManager; -use citrea_common::{BatchProverConfig, FullNodeConfig, LightClientProverConfig, SequencerConfig}; +use citrea_common::{ + BatchProverConfig, FullNodeConfig, LightClientProverConfig, RollupPublicKeys, SequencerConfig, +}; +use citrea_fullnode::da_block_handler::L1BlockHandler as FullNodeL1BlockHandler; use citrea_fullnode::CitreaFullnode; use citrea_light_client_prover::runner::CitreaLightClientProver; use citrea_primitives::forks::get_forks; use citrea_sequencer::CitreaSequencer; +use jmt::RootHash; use jsonrpsee::RpcModule; use sov_db::ledger_db::migrations::{LedgerDBMigrator, Migrations}; use sov_db::ledger_db::{LedgerDB, SharedLedgerOps}; use sov_db::mmr_db::MmrDB; use sov_db::rocks_db_config::RocksdbConfig; use sov_db::schema::types::SoftConfirmationNumber; -use sov_modules_api::Spec; +use sov_modules_api::{Spec, Zkvm}; use sov_modules_rollup_blueprint::RollupBlueprint; use sov_modules_stf_blueprint::{ GenesisParams as StfGenesisParams, Runtime as RuntimeTrait, StfBlueprint, }; use sov_prover_storage_manager::{ProverStorageManager, SnapshotManager}; use sov_rollup_interface::fork::ForkManager; +use sov_rollup_interface::spec::SpecId; use sov_state::storage::NativeStorage; use sov_state::ProverStorage; use sov_stf_runner::InitVariant; -use tokio::sync::broadcast; +use tokio::sync::{broadcast, Mutex}; use tracing::{info, instrument}; mod bitcoin; @@ -124,7 +132,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { /// Creates a new sequencer #[instrument(level = "trace", skip_all)] - fn create_new_sequencer( + fn create_sequencer( &self, genesis_config: GenesisParams, rollup_config: FullNodeConfig, @@ -203,7 +211,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { /// Creates a new rollup. #[instrument(level = "trace", skip_all)] - async fn create_new_rollup( + async fn create_rollup( &self, genesis_config: GenesisParams, rollup_config: FullNodeConfig, @@ -291,7 +299,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { /// Creates a new prover #[instrument(level = "trace", skip_all)] - async fn create_new_batch_prover( + async fn create_batch_prover( &self, genesis_config: GenesisParams, rollup_config: FullNodeConfig, @@ -394,7 +402,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { /// Creates a new light client prover #[instrument(level = "trace", skip_all)] - async fn create_new_light_client_prover( + async fn create_light_client_prover( &self, rollup_config: FullNodeConfig, prover_config: LightClientProverConfig, @@ -459,6 +467,55 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { Ok(runner) } + fn create_rollup_l1_block_handler( + task_manager: &mut TaskManager<()>, + ledger_db: LedgerDB, + da_service: Arc<::DaService>, + public_keys: RollupPublicKeys, + code_commitments_by_spec: HashMap::CodeCommitment>, + start_l1_height: u64, + ) -> FullNodeL1BlockHandler + { + let l1_block_handler = FullNodeL1BlockHandler::new( + ledger_db, + da_service, + public_keys.sequencer_public_key, + public_keys.sequencer_da_pub_key, + public_keys.prover_da_pub_key, + code_commitments_by_spec, + Arc::new(Mutex::new(L1BlockCache::new())), + ); + + task_manager.spawn(move |cancellation_token| async move { + l1_block_handler + .run(start_l1_height, cancellation_token) + .await + }); + } + + fn create_batch_prover_l1_block_handler() -> L1BlockHandler { + let l1_block_handler = L1BlockHandler::< + Vm, + Da, + Ps, + DB, + StfStateRoot, + StfWitness, + StfTransaction, + >::new( + prover_config, + prover_service, + ledger_db, + da_service, + sequencer_pub_key, + sequencer_da_pub_key, + code_commitments_by_spec, + elfs_by_spec, + skip_submission_until_l1, + l1_block_cache.clone(), + ); + } + /// Run Ledger DB migrations fn run_ledger_migrations( &self, diff --git a/crates/batch-prover/src/da_block_handler.rs b/crates/batch-prover/src/da_block_handler.rs index 21359c158..a191cff0d 100644 --- a/crates/batch-prover/src/da_block_handler.rs +++ b/crates/batch-prover/src/da_block_handler.rs @@ -41,7 +41,7 @@ type CommitmentStateTransitionData<'txs, Witness, Da, Tx> = ( VecDeque::Spec as DaSpec>::BlockHeader>>, ); -pub(crate) struct L1BlockHandler +pub struct L1BlockHandler where Da: DaService, Vm: ZkvmHost + Zkvm, diff --git a/crates/batch-prover/src/lib.rs b/crates/batch-prover/src/lib.rs index a590dcd15..716db7af6 100644 --- a/crates/batch-prover/src/lib.rs +++ b/crates/batch-prover/src/lib.rs @@ -1,4 +1,4 @@ -mod da_block_handler; +pub mod da_block_handler; pub mod db_migrations; mod errors; mod runner; diff --git a/crates/fullnode/src/da_block_handler.rs b/crates/fullnode/src/da_block_handler.rs index 6d80da8b7..570ca12c1 100644 --- a/crates/fullnode/src/da_block_handler.rs +++ b/crates/fullnode/src/da_block_handler.rs @@ -34,7 +34,7 @@ use tracing::{error, info, warn}; use crate::metrics::FULLNODE_METRICS; -pub(crate) struct L1BlockHandler +pub struct L1BlockHandler where C: Context, Da: DaService, diff --git a/crates/fullnode/src/lib.rs b/crates/fullnode/src/lib.rs index 28406da97..ba1fdc902 100644 --- a/crates/fullnode/src/lib.rs +++ b/crates/fullnode/src/lib.rs @@ -1,6 +1,6 @@ pub use runner::*; -mod da_block_handler; +pub mod da_block_handler; pub mod db_migrations; mod metrics; mod runner;