Skip to main content

reth_node_core/args/
static_files.rs

1//! clap [Args](clap::Args) for static files configuration
2
3use clap::Args;
4use reth_config::config::{BlocksPerFileConfig, StaticFilesConfig};
5
6/// Blocks per static file when running in `--minimal` node.
7///
8/// 10000 blocks per static file allows us to prune all history every 10k blocks.
9pub const MINIMAL_BLOCKS_PER_FILE: u64 = 10000;
10
11/// Parameters for static files configuration
12#[derive(Debug, Args, PartialEq, Eq, Clone, Copy, Default)]
13#[command(next_help_heading = "Static Files")]
14pub struct StaticFilesArgs {
15    /// Number of blocks per file for the headers segment.
16    #[arg(long = "static-files.blocks-per-file.headers")]
17    pub blocks_per_file_headers: Option<u64>,
18
19    /// Number of blocks per file for the transactions segment.
20    #[arg(long = "static-files.blocks-per-file.transactions")]
21    pub blocks_per_file_transactions: Option<u64>,
22
23    /// Number of blocks per file for the receipts segment.
24    #[arg(long = "static-files.blocks-per-file.receipts")]
25    pub blocks_per_file_receipts: Option<u64>,
26
27    /// Number of blocks per file for the transaction senders segment.
28    #[arg(long = "static-files.blocks-per-file.transaction-senders")]
29    pub blocks_per_file_transaction_senders: Option<u64>,
30
31    /// Number of blocks per file for the account changesets segment.
32    #[arg(long = "static-files.blocks-per-file.account-change-sets")]
33    pub blocks_per_file_account_change_sets: Option<u64>,
34
35    /// Number of blocks per file for the storage changesets segment.
36    #[arg(long = "static-files.blocks-per-file.storage-change-sets")]
37    pub blocks_per_file_storage_change_sets: Option<u64>,
38}
39
40impl StaticFilesArgs {
41    /// Merges the CLI arguments with an existing [`StaticFilesConfig`], giving priority to CLI
42    /// args.
43    ///
44    /// If `minimal` is true, uses [`MINIMAL_BLOCKS_PER_FILE`] blocks per file as the default for
45    /// all segments.
46    pub fn merge_with_config(&self, config: StaticFilesConfig, minimal: bool) -> StaticFilesConfig {
47        let minimal_blocks_per_file = minimal.then_some(MINIMAL_BLOCKS_PER_FILE);
48        StaticFilesConfig {
49            blocks_per_file: BlocksPerFileConfig {
50                headers: self
51                    .blocks_per_file_headers
52                    .or(minimal_blocks_per_file)
53                    .or(config.blocks_per_file.headers),
54                transactions: self
55                    .blocks_per_file_transactions
56                    .or(minimal_blocks_per_file)
57                    .or(config.blocks_per_file.transactions),
58                receipts: self
59                    .blocks_per_file_receipts
60                    .or(minimal_blocks_per_file)
61                    .or(config.blocks_per_file.receipts),
62                transaction_senders: self
63                    .blocks_per_file_transaction_senders
64                    .or(minimal_blocks_per_file)
65                    .or(config.blocks_per_file.transaction_senders),
66                account_change_sets: self
67                    .blocks_per_file_account_change_sets
68                    .or(minimal_blocks_per_file)
69                    .or(config.blocks_per_file.account_change_sets),
70                storage_change_sets: self
71                    .blocks_per_file_storage_change_sets
72                    .or(minimal_blocks_per_file)
73                    .or(config.blocks_per_file.storage_change_sets),
74            },
75        }
76    }
77}