diff --git a/bin/reth/src/args/pruning_args.rs b/bin/reth/src/args/pruning_args.rs index b9a783798901..4b288a4e45e1 100644 --- a/bin/reth/src/args/pruning_args.rs +++ b/bin/reth/src/args/pruning_args.rs @@ -3,7 +3,7 @@ use clap::Args; use reth_config::config::PruneConfig; use reth_primitives::{ - ChainSpec, ContractLogsPruneConfig, PruneMode, PruneModes, MINIMUM_PRUNING_DISTANCE, + ChainSpec, PruneMode, PruneModes, ReceiptsLogPruneConfig, MINIMUM_PRUNING_DISTANCE, }; use std::sync::Arc; @@ -35,7 +35,7 @@ impl PruningArgs { .map(|contract| PruneMode::Before(contract.block)), account_history: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)), storage_history: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)), - contract_logs_filter: ContractLogsPruneConfig( + receipts_log_filter: ReceiptsLogPruneConfig( _chain_spec .deposit_contract .as_ref() diff --git a/book/run/config.md b/book/run/config.md index 3d5c6ce5d6b9..e432055f9a42 100644 --- a/book/run/config.md +++ b/book/run/config.md @@ -27,6 +27,7 @@ The configuration file contains the following sections: - [`reputation_weights`](#reputation_weights) - [`backoff_durations`](#backoff_durations) - [`[sessions]`](#the-sessions-section) +- [`[prune]`](#the-prune-section) ## The `[stages]` section @@ -330,4 +331,56 @@ secs = 120 nanos = 0 ``` +## The `[prune]` section + +The prune section configures the pruning configuration. + +You can configure the pruning of different parts of the data independently of others. +For any unspecified parts, the default setting is no pruning. + +### Default config + +No pruning, run as archive node. + +### Example of the custom pruning configuration + +This configuration will: +- Run pruning every 5 blocks +- Continuously prune all transaction senders, account history and storage history before the block `head-128`, i.e. keep the data for the last 129 blocks +- Prune all receipts before the block 1920000, i.e. keep receipts from the block 1920000 + +```toml +[prune] +# Minimum pruning interval measured in blocks +block_interval = 5 + +[prune.parts] +# Sender Recovery pruning configuration +sender_recovery = { distance = 128 } # Prune all transaction senders before the block `head-128`, i.e. keep transaction senders for the last 129 blocks + +# Transaction Lookup pruning configuration +transaction_lookup = "full" # Prune all TxNumber => TxHash mappings + +# Receipts pruning configuration. This setting overrides `receipts_log_filter`. +receipts = { before = 1920000 } # Prune all receipts from transactions before the block 1920000, i.e. keep receipts from the block 1920000 + +# Account History pruning configuration +account_history = { distance = 128 } # Prune all historical account states before the block `head-128` + +# Storage History pruning configuration +storage_history = { distance = 128 } # Prune all historical storage states before the block `head-128` +``` + +We can also prune receipts more granular, using the logs filtering: +```toml +# Receipts pruning configuration by retaining only those receipts that contain logs emitted +# by the specified addresses, discarding all others. This setting is overridden by `receipts`. +[prune.parts.receipts_log_filter] +# Prune all receipts, leaving only those which: +# - Contain logs from address `0x7ea2be2df7ba6e54b1a9c70676f668455e329d29`, starting from the block 17000000 +# - Contain logs from address `0xdac17f958d2ee523a2206206994597c13d831ec7` in the last 1001 blocks +"0x7ea2be2df7ba6e54b1a9c70676f668455e329d29" = { before = 17000000 } +"0xdac17f958d2ee523a2206206994597c13d831ec7" = { distance = 1000 } +``` + [TOML]: https://toml.io/ diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index b2ff09300f43..898ccc40af8b 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -81,7 +81,7 @@ pub use net::{ }; pub use peer::{PeerId, WithPeerId}; pub use prune::{ - ContractLogsPruneConfig, PruneCheckpoint, PruneMode, PruneModes, PrunePart, PrunePartError, + PruneCheckpoint, PruneMode, PruneModes, PrunePart, PrunePartError, ReceiptsLogPruneConfig, MINIMUM_PRUNING_DISTANCE, }; pub use receipt::{Receipt, ReceiptWithBloom, ReceiptWithBloomRef}; diff --git a/crates/primitives/src/prune/mod.rs b/crates/primitives/src/prune/mod.rs index 5359c3d9c72f..9f8cab504fc4 100644 --- a/crates/primitives/src/prune/mod.rs +++ b/crates/primitives/src/prune/mod.rs @@ -13,9 +13,9 @@ pub use target::{PruneModes, MINIMUM_PRUNING_DISTANCE}; /// Configuration for pruning receipts not associated with logs emitted by the specified contracts. #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] -pub struct ContractLogsPruneConfig(pub BTreeMap); +pub struct ReceiptsLogPruneConfig(pub BTreeMap); -impl ContractLogsPruneConfig { +impl ReceiptsLogPruneConfig { /// Checks if the configuration is empty pub fn is_empty(&self) -> bool { self.0.is_empty() diff --git a/crates/primitives/src/prune/target.rs b/crates/primitives/src/prune/target.rs index 9620569760e2..8789b0cf8f55 100644 --- a/crates/primitives/src/prune/target.rs +++ b/crates/primitives/src/prune/target.rs @@ -1,6 +1,6 @@ use crate::{ prune::PrunePartError, serde_helper::deserialize_opt_prune_mode_with_min_blocks, BlockNumber, - ContractLogsPruneConfig, PruneMode, PrunePart, + PruneMode, PrunePart, ReceiptsLogPruneConfig, }; use paste::paste; use serde::{Deserialize, Serialize}; @@ -23,8 +23,8 @@ pub struct PruneModes { /// Transaction Lookup pruning configuration. #[serde(skip_serializing_if = "Option::is_none")] pub transaction_lookup: Option, - /// Configuration for pruning of receipts. This setting overrides - /// `PruneModes::contract_logs_filter` and offers improved performance. + /// Receipts pruning configuration. This setting overrides `receipts_log_filter` + /// and offers improved performance. #[serde( skip_serializing_if = "Option::is_none", deserialize_with = "deserialize_opt_prune_mode_with_min_blocks::<64, _>" @@ -42,12 +42,12 @@ pub struct PruneModes { deserialize_with = "deserialize_opt_prune_mode_with_min_blocks::<64, _>" )] pub storage_history: Option, - /// Retains only those receipts that contain logs emitted by the specified addresses, - /// discarding all others. Note that this setting is overridden by `PruneModes::receipts`. + /// Receipts pruning configuration by retaining only those receipts that contain logs emitted + /// by the specified addresses, discarding others. This setting is overridden by `receipts`. /// /// The [`BlockNumber`] represents the starting block from which point onwards the receipts are /// preserved. - pub contract_logs_filter: ContractLogsPruneConfig, + pub receipts_log_filter: ReceiptsLogPruneConfig, } macro_rules! impl_prune_parts { @@ -90,7 +90,7 @@ macro_rules! impl_prune_parts { $( $part: Some(PruneMode::Full), )+ - contract_logs_filter: Default::default() + receipts_log_filter: Default::default() } } diff --git a/crates/prune/src/pruner.rs b/crates/prune/src/pruner.rs index 9b082d4a08fb..eebd6bab0bd8 100644 --- a/crates/prune/src/pruner.rs +++ b/crates/prune/src/pruner.rs @@ -103,7 +103,7 @@ impl Pruner { .record(part_start.elapsed()) } - if !self.modes.contract_logs_filter.is_empty() { + if !self.modes.receipts_log_filter.is_empty() { let part_start = Instant::now(); self.prune_receipts_by_logs(&provider, tip_block_number)?; self.metrics @@ -305,7 +305,7 @@ impl Pruner { .map(|checkpoint| checkpoint.block_number); let address_filter = - self.modes.contract_logs_filter.group_by_block(tip_block_number, pruned)?; + self.modes.receipts_log_filter.group_by_block(tip_block_number, pruned)?; // Splits all transactions in different block ranges. Each block range will have its own // filter address list and will check it while going through the table @@ -411,7 +411,7 @@ impl Pruner { // one using `get_next_tx_num_range_from_checkpoint`. let checkpoint_block = self .modes - .contract_logs_filter + .receipts_log_filter .lowest_block_with_distance(tip_block_number, pruned)? .unwrap_or(to_block); diff --git a/crates/storage/provider/src/post_state/mod.rs b/crates/storage/provider/src/post_state/mod.rs index aa1cb7489d37..fc1d74af8f80 100644 --- a/crates/storage/provider/src/post_state/mod.rs +++ b/crates/storage/provider/src/post_state/mod.rs @@ -661,7 +661,7 @@ impl PostState { let contract_log_pruner = self .prune_modes - .contract_logs_filter + .receipts_log_filter .group_by_block(tip, None) .map_err(|e| Error::Custom(e.to_string()))?;