diff --git a/Cargo.lock b/Cargo.lock index eca95cdbb..6bf33c0e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1889,7 +1889,10 @@ dependencies = [ "citrea-pruning", "clap", "sov-db", + "sov-prover-storage-manager", "tokio", + "tracing", + "tracing-subscriber 0.3.19", ] [[package]] diff --git a/bin/cli/Cargo.toml b/bin/cli/Cargo.toml index 852d4c96d..c06bc5b7d 100644 --- a/bin/cli/Cargo.toml +++ b/bin/cli/Cargo.toml @@ -16,11 +16,14 @@ citrea-pruning = { path = "../../crates/pruning" } # Sovereign-SDK deps sov-db = { path = "../../crates/sovereign-sdk/full-node/db/sov-db" } +sov-prover-storage-manager = { path = "../../crates/sovereign-sdk/full-node/sov-prover-storage-manager" } # 3rd-party deps anyhow = { workspace = true } clap = { workspace = true } tokio = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } [[bin]] name = "citrea-cli" diff --git a/bin/cli/src/commands/mod.rs b/bin/cli/src/commands/mod.rs index b337405f7..a889556ce 100644 --- a/bin/cli/src/commands/mod.rs +++ b/bin/cli/src/commands/mod.rs @@ -1 +1,3 @@ mod prune; + +pub(crate) use prune::*; diff --git a/bin/cli/src/commands/prune.rs b/bin/cli/src/commands/prune.rs index 2e6031fbb..532bfb6a4 100644 --- a/bin/cli/src/commands/prune.rs +++ b/bin/cli/src/commands/prune.rs @@ -1,17 +1,36 @@ use std::path::PathBuf; +use std::sync::Arc; use citrea_pruning::{Pruner, PruningConfig}; use sov_db::ledger_db::{LedgerDB, SharedLedgerOps}; +use sov_db::native_db::NativeDB; use sov_db::rocks_db_config::RocksdbConfig; +use sov_prover_storage_manager::SnapshotManager; +use tracing::{debug, info}; -pub(crate) fn prune(db_path: PathBuf, distance: u64) -> anyhow::Result<()> { +pub(crate) async fn prune(db_path: PathBuf, distance: u64) -> anyhow::Result<()> { + info!( + "Pruning DB at {} with pruning distance of {}", + db_path.display(), + distance + ); let config = PruningConfig { distance }; let rocksdb_config = RocksdbConfig::new(&db_path, None, None); let ledger_db = LedgerDB::with_config(&rocksdb_config)?; + let native_db = NativeDB::::setup_schema_db(&rocksdb_config)?; - let last_pruned_block = ledger_db.get_last_pruned_l2_height()?.unwrap_or(0); - let pruner = Pruner::new(config, last_pruned_block, l2_receiver, ledger_db)?; + let Some((soft_confirmation_number, _)) = ledger_db.get_head_soft_confirmation()? else { + return Ok(()); + }; + + debug!( + "Pruning up to latest soft confirmation number: {}, taking into consideration the configured distance of {}", + soft_confirmation_number.0, distance + ); + + let pruner = Pruner::new(config, ledger_db, Arc::new(native_db)); + pruner.prune(soft_confirmation_number.0).await; Ok(()) } diff --git a/bin/cli/src/main.rs b/bin/cli/src/main.rs index af5c690ab..d99f0dd21 100644 --- a/bin/cli/src/main.rs +++ b/bin/cli/src/main.rs @@ -1,6 +1,9 @@ use std::path::PathBuf; use clap::{Parser, Subcommand}; +use tracing_subscriber::fmt; +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; mod commands; @@ -36,16 +39,20 @@ enum Commands { #[tokio::main] async fn main() -> anyhow::Result<()> { + tracing_subscriber::registry().with(fmt::layer()).init(); + let cli = Cli::parse(); // You can check for the existence of subcommands, and if found use their // matches just as you would the top level cmd match &cli.command { Commands::Prune { db_path, distance } => { - println!("Pruning stuff: {:?}, distance: {}", db_path, distance); + commands::prune(db_path.clone(), *distance).await?; } Commands::Rollback { db_path, blocks } => { println!("Rolling back stuff: {:?}, blocks: {}", db_path, blocks); } } + + Ok(()) }