mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-08 03:01:12 -04:00
feat(node): --minimal flag (#20960)
This commit is contained in:
@@ -78,7 +78,7 @@ pub use era::{DefaultEraHost, EraArgs, EraSourceArgs};
|
||||
|
||||
/// `StaticFilesArgs` for configuring static files.
|
||||
mod static_files;
|
||||
pub use static_files::StaticFilesArgs;
|
||||
pub use static_files::{StaticFilesArgs, MINIMAL_BLOCKS_PER_FILE};
|
||||
|
||||
mod error;
|
||||
pub mod types;
|
||||
|
||||
@@ -16,9 +16,18 @@ use std::{collections::BTreeMap, ops::Not};
|
||||
#[command(next_help_heading = "Pruning")]
|
||||
pub struct PruningArgs {
|
||||
/// Run full node. Only the most recent [`MINIMUM_PRUNING_DISTANCE`] block states are stored.
|
||||
#[arg(long, default_value_t = false)]
|
||||
#[arg(long, default_value_t = false, conflicts_with = "minimal")]
|
||||
pub full: bool,
|
||||
|
||||
/// Run minimal storage mode with maximum pruning and smaller static files.
|
||||
///
|
||||
/// This mode configures the node to use minimal disk space by:
|
||||
/// - Fully pruning sender recovery, transaction lookup, receipts
|
||||
/// - Leaving 10,064 blocks for account, storage history and block bodies
|
||||
/// - Using 10,000 blocks per static file segment
|
||||
#[arg(long, default_value_t = false, conflicts_with = "full")]
|
||||
pub minimal: bool,
|
||||
|
||||
/// Minimum pruning interval measured in blocks.
|
||||
#[arg(long = "prune.block-interval", alias = "block-interval", value_parser = RangedU64ValueParser::<u64>::new().range(1..))]
|
||||
pub block_interval: Option<u64>,
|
||||
@@ -140,6 +149,23 @@ impl PruningArgs {
|
||||
}
|
||||
}
|
||||
|
||||
// If --minimal is set, use minimal storage mode with aggressive pruning.
|
||||
if self.minimal {
|
||||
config = PruneConfig {
|
||||
block_interval: config.block_interval,
|
||||
segments: PruneModes {
|
||||
sender_recovery: Some(PruneMode::Full),
|
||||
transaction_lookup: Some(PruneMode::Full),
|
||||
receipts: Some(PruneMode::Full),
|
||||
account_history: Some(PruneMode::Distance(10064)),
|
||||
storage_history: Some(PruneMode::Distance(10064)),
|
||||
bodies_history: Some(PruneMode::Distance(10064)),
|
||||
merkle_changesets: PruneMode::Distance(MERKLE_CHANGESETS_RETENTION_BLOCKS),
|
||||
receipts_log_filter: Default::default(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Override with any explicitly set prune.* flags.
|
||||
if let Some(block_interval) = self.block_interval {
|
||||
config.block_interval = block_interval as usize;
|
||||
|
||||
@@ -4,6 +4,11 @@ use clap::Args;
|
||||
use reth_config::config::{BlocksPerFileConfig, StaticFilesConfig};
|
||||
use reth_provider::StorageSettings;
|
||||
|
||||
/// Blocks per static file when running in `--minimal` node.
|
||||
///
|
||||
/// 10000 blocks per static file allows us to prune all history every 10k blocks.
|
||||
pub const MINIMAL_BLOCKS_PER_FILE: u64 = 10000;
|
||||
|
||||
/// Parameters for static files configuration
|
||||
#[derive(Debug, Args, PartialEq, Eq, Default, Clone, Copy)]
|
||||
#[command(next_help_heading = "Static Files")]
|
||||
@@ -61,14 +66,25 @@ pub struct StaticFilesArgs {
|
||||
impl StaticFilesArgs {
|
||||
/// Merges the CLI arguments with an existing [`StaticFilesConfig`], giving priority to CLI
|
||||
/// args.
|
||||
pub fn merge_with_config(&self, config: StaticFilesConfig) -> StaticFilesConfig {
|
||||
///
|
||||
/// If `minimal` is true, uses [`MINIMAL_BLOCKS_PER_FILE`] blocks per file as the default for
|
||||
/// headers, transactions, and receipts segments.
|
||||
pub fn merge_with_config(&self, config: StaticFilesConfig, minimal: bool) -> StaticFilesConfig {
|
||||
let minimal_blocks_per_file = minimal.then_some(MINIMAL_BLOCKS_PER_FILE);
|
||||
StaticFilesConfig {
|
||||
blocks_per_file: BlocksPerFileConfig {
|
||||
headers: self.blocks_per_file_headers.or(config.blocks_per_file.headers),
|
||||
headers: self
|
||||
.blocks_per_file_headers
|
||||
.or(minimal_blocks_per_file)
|
||||
.or(config.blocks_per_file.headers),
|
||||
transactions: self
|
||||
.blocks_per_file_transactions
|
||||
.or(minimal_blocks_per_file)
|
||||
.or(config.blocks_per_file.transactions),
|
||||
receipts: self.blocks_per_file_receipts.or(config.blocks_per_file.receipts),
|
||||
receipts: self
|
||||
.blocks_per_file_receipts
|
||||
.or(minimal_blocks_per_file)
|
||||
.or(config.blocks_per_file.receipts),
|
||||
transaction_senders: self
|
||||
.blocks_per_file_transaction_senders
|
||||
.or(config.blocks_per_file.transaction_senders),
|
||||
|
||||
Reference in New Issue
Block a user