Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/nightly' into rakanalh/prune-ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
rakanalh committed Feb 14, 2025
2 parents 21aacf7 + 490bc8f commit 7a75002
Show file tree
Hide file tree
Showing 41 changed files with 1,116 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions bin/citrea/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ pub(crate) enum NodeType {
LightClientProver(LightClientProverConfig),
}

impl std::fmt::Display for NodeType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
NodeType::Sequencer(_) => {
write!(f, "sequencer")
}
NodeType::FullNode => {
write!(f, "fullnode")
}
NodeType::BatchProver(_) => {
write!(f, "batch-prover")
}
NodeType::LightClientProver(_) => {
write!(f, "light-client-prover")
}
}
}
}

pub(crate) fn node_type_from_args(args: &Args) -> anyhow::Result<NodeType> {
let sequencer_config = match &args.sequencer {
Some(Some(path)) => Some(
Expand Down
15 changes: 14 additions & 1 deletion bin/citrea/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use core::fmt::Debug as DebugTrait;
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;

use anyhow::{anyhow, Context as _};
use bitcoin_da::service::BitcoinServiceConfig;
use citrea::{
initialize_logging, BitcoinRollup, CitreaRollupBlueprint, Dependencies, MockDemoRollup, Storage,
};
use citrea_common::backup::BackupManager;
use citrea_common::da::get_start_l1_height;
use citrea_common::rpc::server::start_rpc_server;
use citrea_common::{from_toml_path, FromEnv, FullNodeConfig};
Expand Down Expand Up @@ -131,6 +133,12 @@ where

let rollup_blueprint = S::new(network);

let backup_manager = Arc::new(BackupManager::new(
node_type.to_string(),
rollup_config.storage.backup_path.clone(),
Default::default(),
));

// Based on the node's type, execute migrations before constructing an instance of LedgerDB
// so that avoid locking the DB.
let (tables, migrations) = match node_type {
Expand Down Expand Up @@ -179,7 +187,7 @@ where
ledger_db,
storage_manager,
prover_storage,
} = rollup_blueprint.setup_storage(&rollup_config, &rocksdb_config)?;
} = rollup_blueprint.setup_storage(&rollup_config, &rocksdb_config, &backup_manager)?;

let Dependencies {
da_service,
Expand Down Expand Up @@ -210,6 +218,7 @@ where
da_service.clone(),
sequencer_client_url,
soft_confirmation_rx,
&backup_manager,
)?;

match node_type {
Expand All @@ -225,6 +234,7 @@ where
prover_storage,
soft_confirmation_channel.0,
rpc_module,
backup_manager,
)
.expect("Could not start sequencer");

Expand Down Expand Up @@ -254,6 +264,7 @@ where
prover_storage,
soft_confirmation_channel.0,
rpc_module,
backup_manager,
)
.await
.expect("Could not start batch prover");
Expand Down Expand Up @@ -299,6 +310,7 @@ where
da_service,
ledger_db,
rpc_module,
backup_manager,
)
.await
.expect("Could not start light client prover");
Expand Down Expand Up @@ -333,6 +345,7 @@ where
storage_manager,
prover_storage,
soft_confirmation_channel.0,
backup_manager,
)
.await
.expect("Could not start full-node");
Expand Down
5 changes: 5 additions & 0 deletions bin/citrea/src/rollup/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use bitcoin_da::rpc::create_rpc_module as create_da_rpc_module;
use bitcoin_da::service::{BitcoinService, BitcoinServiceConfig, TxidWrapper};
use bitcoin_da::spec::{BitcoinSpec, RollupParams};
use bitcoin_da::verifier::BitcoinVerifier;
use citrea_common::backup::{create_backup_rpc_module, BackupManager};
use citrea_common::config::ProverGuestRunConfig;
use citrea_common::rpc::register_healthcheck_rpc;
use citrea_common::tasks::manager::TaskManager;
Expand Down Expand Up @@ -64,6 +65,7 @@ impl RollupBlueprint for BitcoinRollup {
da_service: &Arc<Self::DaService>,
sequencer_client_url: Option<String>,
soft_confirmation_rx: Option<broadcast::Receiver<u64>>,
backup_manager: &Arc<BackupManager>,
) -> Result<jsonrpsee::RpcModule<()>, anyhow::Error> {
// unused inside register RPC
let sov_sequencer = Address::new([0; 32]);
Expand All @@ -85,6 +87,9 @@ impl RollupBlueprint for BitcoinRollup {

register_healthcheck_rpc(&mut rpc_methods, ledger_db.clone())?;

let backup_methods = create_backup_rpc_module(ledger_db.clone(), backup_manager.clone());
rpc_methods.merge(backup_methods)?;

let da_methods = create_da_rpc_module(da_service.clone());
rpc_methods.merge(da_methods)?;

Expand Down
4 changes: 4 additions & 0 deletions bin/citrea/src/rollup/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::sync::Arc;

use async_trait::async_trait;
use citrea_common::backup::{create_backup_rpc_module, BackupManager};
use citrea_common::config::ProverGuestRunConfig;
use citrea_common::rpc::register_healthcheck_rpc;
use citrea_common::tasks::manager::TaskManager;
Expand Down Expand Up @@ -50,6 +51,7 @@ impl RollupBlueprint for MockDemoRollup {
da_service: &Arc<Self::DaService>,
sequencer_client_url: Option<String>,
soft_confirmation_rx: Option<broadcast::Receiver<u64>>,
backup_manager: &Arc<BackupManager>,
) -> Result<jsonrpsee::RpcModule<()>, anyhow::Error> {
// TODO set the sequencer address
let sequencer = Address::new([0; 32]);
Expand All @@ -69,6 +71,8 @@ impl RollupBlueprint for MockDemoRollup {
)?;

register_healthcheck_rpc(&mut rpc_methods, ledger_db.clone())?;
let backup_methods = create_backup_rpc_module(ledger_db.clone(), backup_manager.clone());
rpc_methods.merge(backup_methods)?;

Ok(rpc_methods)
}
Expand Down
28 changes: 27 additions & 1 deletion bin/citrea/src/rollup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anyhow::{anyhow, Result};
use async_trait::async_trait;
use citrea_batch_prover::da_block_handler::L1BlockHandler as BatchProverL1BlockHandler;
use citrea_batch_prover::CitreaBatchProver;
use citrea_common::backup::BackupManager;
use citrea_common::tasks::manager::TaskManager;
use citrea_common::{
BatchProverConfig, FullNodeConfig, InitParams, LightClientProverConfig, SequencerConfig,
Expand All @@ -18,9 +19,11 @@ use citrea_stf::runtime::{CitreaRuntime, DefaultContext};
use citrea_storage_ops::pruning::PrunerService;
use jsonrpsee::RpcModule;
use sov_db::ledger_db::migrations::{LedgerDBMigrator, Migrations};
use sov_db::ledger_db::{LedgerDB, SharedLedgerOps};
use sov_db::ledger_db::{LedgerDB, SharedLedgerOps, LEDGER_DB_PATH_SUFFIX};
use sov_db::native_db::NativeDB;
use sov_db::rocks_db_config::RocksdbConfig;
use sov_db::schema::types::SoftConfirmationNumber;
use sov_db::state_db::StateDB;
use sov_modules_rollup_blueprint::RollupBlueprint;
use sov_modules_stf_blueprint::{
GenesisParams as StfGenesisParams, Runtime as RuntimeTrait, StfBlueprint,
Expand Down Expand Up @@ -98,11 +101,23 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
&self,
rollup_config: &FullNodeConfig<Self::DaConfig>,
rocksdb_config: &RocksdbConfig,
backup_manager: &Arc<BackupManager>,
) -> Result<Storage<Self>> {
let ledger_db = self.create_ledger_db(rocksdb_config);
let mut storage_manager = self.create_storage_manager(rollup_config)?;
let prover_storage = storage_manager.create_finalized_storage()?;

backup_manager
.register_database(LEDGER_DB_PATH_SUFFIX.to_string(), ledger_db.db_handle())?;
backup_manager.register_database(
StateDB::<()>::DB_PATH_SUFFIX.to_string(),
storage_manager.get_state_db_handle(),
)?;
backup_manager.register_database(
NativeDB::<()>::DB_PATH_SUFFIX.to_string(),
storage_manager.get_native_db_handle(),
)?;

Ok(Storage {
ledger_db,
storage_manager,
Expand All @@ -118,13 +133,15 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
da_service: Arc<<Self as RollupBlueprint>::DaService>,
sequencer_client_url: Option<String>,
soft_confirmation_rx: Option<broadcast::Receiver<u64>>,
backup_manager: &Arc<BackupManager>,
) -> Result<RpcModule<()>> {
self.create_rpc_methods(
prover_storage,
&ledger_db,
&da_service,
sequencer_client_url,
soft_confirmation_rx,
backup_manager,
)
}

Expand All @@ -142,6 +159,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
prover_storage: ProverStorage<SnapshotManager>,
soft_confirmation_tx: broadcast::Sender<u64>,
rpc_module: RpcModule<()>,
backup_manager: Arc<BackupManager>,
) -> Result<(CitreaSequencer<Self::DaService, LedgerDB>, RpcModule<()>)> {
let current_l2_height = ledger_db
.get_head_soft_confirmation()
Expand Down Expand Up @@ -173,6 +191,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
soft_confirmation_tx,
fork_manager,
rpc_module,
backup_manager,
)
}

Expand All @@ -188,6 +207,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
mut storage_manager: ProverStorageManager<<Self as RollupBlueprint>::DaSpec>,
prover_storage: ProverStorage<SnapshotManager>,
soft_confirmation_tx: broadcast::Sender<u64>,
backup_manager: Arc<BackupManager>,
) -> Result<(
CitreaFullnode<Self::DaService, LedgerDB>,
FullNodeL1BlockHandler<Self::Vm, Self::DaService, LedgerDB>,
Expand Down Expand Up @@ -226,6 +246,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
soft_confirmation_tx,
fork_manager,
code_commitments,
backup_manager,
)
}

Expand All @@ -243,6 +264,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
prover_storage: ProverStorage<SnapshotManager>,
soft_confirmation_tx: broadcast::Sender<u64>,
rpc_module: RpcModule<()>,
backup_manager: Arc<BackupManager>,
) -> Result<(
CitreaBatchProver<Self::DaService, LedgerDB>,
BatchProverL1BlockHandler<Self::Vm, Self::DaService, LedgerDB, ArrayWitness>,
Expand Down Expand Up @@ -295,12 +317,14 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
code_commitments,
elfs,
rpc_module,
backup_manager,
)
.await
}

/// Creates a new light client prover
#[instrument(level = "trace", skip_all)]
#[allow(clippy::type_complexity, clippy::too_many_arguments)]
async fn create_light_client_prover(
&self,
prover_config: LightClientProverConfig,
Expand All @@ -309,6 +333,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
da_service: Arc<<Self as RollupBlueprint>::DaService>,
ledger_db: LedgerDB,
rpc_module: RpcModule<()>,
backup_manager: Arc<BackupManager>,
) -> Result<(
CitreaLightClientProver,
LightClientProverL1BlockHandler<Self::Vm, Self::DaService, LedgerDB>,
Expand Down Expand Up @@ -352,6 +377,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
code_commitments,
elfs,
rpc_module,
backup_manager,
)
}

Expand Down
1 change: 1 addition & 0 deletions bin/citrea/src/test_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ fn test_helper(
batch_requests_limit: 50,
enable_subscriptions: true,
max_subscriptions_per_connection: 100,
api_key: None,
};

queries_test_runner(test_queries, rpc_config).await;
Expand Down
Loading

0 comments on commit 7a75002

Please sign in to comment.