mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(cli): reth prune (#9055)
This commit is contained in:
@ -66,7 +66,7 @@ reth-node-builder.workspace = true
|
||||
reth-node-events.workspace = true
|
||||
reth-consensus.workspace = true
|
||||
reth-optimism-primitives.workspace = true
|
||||
reth-prune-types.workspace = true
|
||||
reth-prune.workspace = true
|
||||
|
||||
# crypto
|
||||
alloy-rlp.workspace = true
|
||||
|
||||
@ -8,7 +8,7 @@ use crate::{
|
||||
commands::{
|
||||
config_cmd, db, debug_cmd, dump_genesis, import, init_cmd, init_state,
|
||||
node::{self, NoArgs},
|
||||
p2p, recover, stage, test_vectors,
|
||||
p2p, prune, recover, stage, test_vectors,
|
||||
},
|
||||
version::{LONG_VERSION, SHORT_VERSION},
|
||||
};
|
||||
@ -164,6 +164,7 @@ impl<Ext: clap::Args + fmt::Debug> Cli<Ext> {
|
||||
Commands::Config(command) => runner.run_until_ctrl_c(command.execute()),
|
||||
Commands::Debug(command) => runner.run_command_until_exit(|ctx| command.execute(ctx)),
|
||||
Commands::Recover(command) => runner.run_command_until_exit(|ctx| command.execute(ctx)),
|
||||
Commands::Prune(command) => runner.run_until_ctrl_c(command.execute()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,6 +224,9 @@ pub enum Commands<Ext: clap::Args + fmt::Debug = NoArgs> {
|
||||
/// Scripts for node recovery
|
||||
#[command(name = "recover")]
|
||||
Recover(recover::Command),
|
||||
/// Prune according to the configuration without any limits
|
||||
#[command(name = "prune")]
|
||||
Prune(prune::PruneCommand),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@ -26,7 +26,7 @@ use reth_primitives::{BlockHashOrNumber, BlockNumber, B256};
|
||||
use reth_provider::{
|
||||
BlockExecutionWriter, ChainSpecProvider, ProviderFactory, StageCheckpointReader,
|
||||
};
|
||||
use reth_prune_types::PruneModes;
|
||||
use reth_prune::PruneModes;
|
||||
use reth_stages::{
|
||||
sets::DefaultStages,
|
||||
stages::{ExecutionStage, ExecutionStageThresholds},
|
||||
|
||||
@ -23,7 +23,7 @@ use reth_provider::{
|
||||
BlockNumReader, BlockWriter, ChainSpecProvider, HeaderProvider, LatestStateProviderRef,
|
||||
OriginalValuesKnown, ProviderError, ProviderFactory, StateWriter,
|
||||
};
|
||||
use reth_prune_types::PruneModes;
|
||||
use reth_prune::PruneModes;
|
||||
use reth_revm::database::StateProviderDatabase;
|
||||
use reth_stages::{
|
||||
stages::{AccountHashingStage, MerkleStage, StorageHashingStage},
|
||||
|
||||
@ -22,7 +22,7 @@ use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
||||
use reth_provider::{
|
||||
providers::BlockchainProvider, CanonStateSubscriptions, ChainSpecProvider, ProviderFactory,
|
||||
};
|
||||
use reth_prune_types::PruneModes;
|
||||
use reth_prune::PruneModes;
|
||||
use reth_stages::Pipeline;
|
||||
use reth_static_file::StaticFileProducer;
|
||||
use reth_tasks::TaskExecutor;
|
||||
|
||||
@ -27,7 +27,7 @@ use reth_provider::{
|
||||
BlockNumReader, ChainSpecProvider, HeaderProvider, ProviderError, ProviderFactory,
|
||||
StageCheckpointReader,
|
||||
};
|
||||
use reth_prune_types::PruneModes;
|
||||
use reth_prune::PruneModes;
|
||||
use reth_stages::{prelude::*, Pipeline, StageId, StageSet};
|
||||
use reth_static_file::StaticFileProducer;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
@ -17,7 +17,7 @@ use reth_downloaders::file_client::{
|
||||
};
|
||||
use reth_optimism_primitives::bedrock_import::is_dup_tx;
|
||||
use reth_provider::StageCheckpointReader;
|
||||
use reth_prune_types::PruneModes;
|
||||
use reth_prune::PruneModes;
|
||||
use reth_stages::StageId;
|
||||
use reth_static_file::StaticFileProducer;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
@ -7,12 +7,11 @@ pub mod dump_genesis;
|
||||
pub mod import;
|
||||
pub mod import_op;
|
||||
pub mod import_receipts_op;
|
||||
|
||||
pub mod init_cmd;
|
||||
pub mod init_state;
|
||||
|
||||
pub mod node;
|
||||
pub mod p2p;
|
||||
pub mod prune;
|
||||
pub mod recover;
|
||||
pub mod stage;
|
||||
pub mod test_vectors;
|
||||
|
||||
43
bin/reth/src/commands/prune.rs
Normal file
43
bin/reth/src/commands/prune.rs
Normal file
@ -0,0 +1,43 @@
|
||||
//! Command that runs pruning without any limits.
|
||||
|
||||
use crate::commands::common::{AccessRights, Environment, EnvironmentArgs};
|
||||
use clap::Parser;
|
||||
use reth_prune::PrunerBuilder;
|
||||
use reth_static_file::StaticFileProducer;
|
||||
use tracing::info;
|
||||
|
||||
/// Prunes according to the configuration without any limits
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct PruneCommand {
|
||||
#[command(flatten)]
|
||||
env: EnvironmentArgs,
|
||||
}
|
||||
|
||||
impl PruneCommand {
|
||||
/// Execute the `prune` command
|
||||
pub async fn execute(self) -> eyre::Result<()> {
|
||||
let Environment { config, provider_factory, .. } = self.env.init(AccessRights::RW)?;
|
||||
let prune_config = config.prune.unwrap_or_default();
|
||||
|
||||
// Copy data from database to static files
|
||||
info!(target: "reth::cli", "Copying data from database to static files...");
|
||||
let static_file_producer =
|
||||
StaticFileProducer::new(provider_factory.clone(), prune_config.segments.clone());
|
||||
let lowest_static_file_height = static_file_producer.lock().copy_to_static_files()?.min();
|
||||
info!(target: "reth::cli", ?lowest_static_file_height, "Copied data from database to static files");
|
||||
|
||||
// Delete data which has been copied to static files.
|
||||
if let Some(prune_tip) = lowest_static_file_height {
|
||||
info!(target: "reth::cli", ?prune_tip, ?prune_config, "Pruning data from database...");
|
||||
// Run the pruner according to the configuration, and don't enforce any limits on it
|
||||
let mut pruner = PrunerBuilder::new(prune_config)
|
||||
.prune_delete_limit(usize::MAX)
|
||||
.build(provider_factory);
|
||||
|
||||
pruner.run(prune_tip)?;
|
||||
info!(target: "reth::cli", "Pruned data from database");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -9,7 +9,7 @@ use reth_exex::ExExManagerHandle;
|
||||
use reth_node_core::dirs::{ChainPath, DataDirPath};
|
||||
use reth_primitives::BlockNumber;
|
||||
use reth_provider::{providers::StaticFileProvider, ProviderFactory};
|
||||
use reth_prune_types::PruneModes;
|
||||
use reth_prune::PruneModes;
|
||||
use reth_stages::{
|
||||
stages::{
|
||||
AccountHashingStage, ExecutionStage, ExecutionStageThresholds, MerkleStage,
|
||||
|
||||
@ -13,7 +13,7 @@ use reth_provider::{
|
||||
BlockExecutionWriter, BlockNumReader, ChainSpecProvider, FinalizedBlockReader,
|
||||
FinalizedBlockWriter, ProviderFactory, StaticFileProviderFactory,
|
||||
};
|
||||
use reth_prune_types::PruneModes;
|
||||
use reth_prune::PruneModes;
|
||||
use reth_stages::{
|
||||
sets::{DefaultStages, OfflineStages},
|
||||
stages::{ExecutionStage, ExecutionStageThresholds},
|
||||
|
||||
Reference in New Issue
Block a user