-
Notifications
You must be signed in to change notification settings - Fork 2.2k
refactor(prune): remove receipts log filter segment #19184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
55e469d
refactor(prune): remove receipts log filter segment
shekhirin 1fd053b
fix: make config backward-compatible
shekhirin 4756b36
Merge remote-tracking branch 'origin/main' into alexey/receipts-log-f…
shekhirin a808c7e
update book
shekhirin 4d22770
serde skip
shekhirin d2c476c
Merge remote-tracking branch 'origin/main' into alexey/receipts-log-f…
shekhirin f34aa21
remove receipts by logs prune segment
shekhirin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| //! Pruning and full node arguments | ||
|
|
||
| use crate::{args::error::ReceiptsLogError, primitives::EthereumHardfork}; | ||
| use alloy_primitives::{Address, BlockNumber}; | ||
| use std::ops::Not; | ||
|
|
||
| use crate::primitives::EthereumHardfork; | ||
| use alloy_primitives::BlockNumber; | ||
| use clap::{builder::RangedU64ValueParser, Args}; | ||
| use reth_chainspec::EthereumHardforks; | ||
| use reth_config::config::PruneConfig; | ||
| use reth_prune_types::{PruneMode, PruneModes, ReceiptsLogPruneConfig, MINIMUM_PRUNING_DISTANCE}; | ||
| use std::{collections::BTreeMap, ops::Not}; | ||
| use reth_prune_types::{PruneMode, PruneModes, MINIMUM_PRUNING_DISTANCE}; | ||
|
|
||
| /// Parameters for pruning and full node | ||
| #[derive(Debug, Clone, Args, PartialEq, Eq, Default)] | ||
|
|
@@ -59,12 +60,10 @@ pub struct PruningArgs { | |
| /// Prune receipts before the specified block number. The specified block number is not pruned. | ||
| #[arg(long = "prune.receipts.before", value_name = "BLOCK_NUMBER", conflicts_with_all = &["receipts_full", "receipts_pre_merge", "receipts_distance"])] | ||
| pub receipts_before: Option<BlockNumber>, | ||
| // Receipts Log Filter | ||
| /// Configure receipts log filter. Format: | ||
| /// <`address`>:<`prune_mode`>... where <`prune_mode`> can be 'full', 'distance:<`blocks`>', or | ||
| /// 'before:<`block_number`>' | ||
| #[arg(long = "prune.receiptslogfilter", value_name = "FILTER_CONFIG", conflicts_with_all = &["receipts_full", "receipts_pre_merge", "receipts_distance", "receipts_before"], value_parser = parse_receipts_log_filter)] | ||
| pub receipts_log_filter: Option<ReceiptsLogPruneConfig>, | ||
| /// Receipts Log Filter | ||
| #[arg(long = "prune.receiptslogfilter", value_name = "FILTER_CONFIG", hide = true)] | ||
| #[deprecated] | ||
| pub receipts_log_filter: Option<String>, | ||
|
|
||
| // Account History | ||
| /// Prunes all account history. | ||
|
|
@@ -130,7 +129,8 @@ impl PruningArgs { | |
| // TODO: set default to pre-merge block if available | ||
| bodies_history: None, | ||
| merkle_changesets: PruneMode::Distance(MINIMUM_PRUNING_DISTANCE), | ||
| receipts_log_filter: Default::default(), | ||
| #[expect(deprecated)] | ||
| receipts_log_filter: (), | ||
| }, | ||
| } | ||
| } | ||
|
|
@@ -157,13 +157,14 @@ impl PruningArgs { | |
| if let Some(mode) = self.storage_history_prune_mode() { | ||
| config.segments.storage_history = Some(mode); | ||
| } | ||
| if let Some(receipt_logs) = | ||
| self.receipts_log_filter.as_ref().filter(|c| !c.is_empty()).cloned() | ||
| { | ||
| config.segments.receipts_log_filter = receipt_logs; | ||
| // need to remove the receipts segment filter entirely because that takes precedence | ||
| // over the logs filter | ||
| config.segments.receipts.take(); | ||
|
|
||
| // Log warning if receipts_log_filter is set (deprecated feature) | ||
| #[expect(deprecated)] | ||
| if self.receipts_log_filter.is_some() { | ||
| tracing::warn!( | ||
| target: "reth::cli", | ||
| "The --prune.receiptslogfilter flag is deprecated and has no effect. It will be removed in a future release." | ||
| ); | ||
|
Comment on lines
+163
to
+167
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah I see we keep it for this warn message, makes sense |
||
| } | ||
|
|
||
| config.is_default().not().then_some(config) | ||
|
|
@@ -251,141 +252,3 @@ impl PruningArgs { | |
| } | ||
| } | ||
| } | ||
|
|
||
| /// Parses `,` separated pruning info into [`ReceiptsLogPruneConfig`]. | ||
| pub(crate) fn parse_receipts_log_filter( | ||
| value: &str, | ||
| ) -> Result<ReceiptsLogPruneConfig, ReceiptsLogError> { | ||
| let mut config = BTreeMap::new(); | ||
| // Split out each of the filters. | ||
| let filters = value.split(','); | ||
| for filter in filters { | ||
| let parts: Vec<&str> = filter.split(':').collect(); | ||
| if parts.len() < 2 { | ||
| return Err(ReceiptsLogError::InvalidFilterFormat(filter.to_string())); | ||
| } | ||
| // Parse the address | ||
| let address = parts[0] | ||
| .parse::<Address>() | ||
| .map_err(|_| ReceiptsLogError::InvalidAddress(parts[0].to_string()))?; | ||
|
|
||
| // Parse the prune mode | ||
| let prune_mode = match parts[1] { | ||
| "full" => PruneMode::Full, | ||
| s if s.starts_with("distance") => { | ||
| if parts.len() < 3 { | ||
| return Err(ReceiptsLogError::InvalidFilterFormat(filter.to_string())); | ||
| } | ||
| let distance = | ||
| parts[2].parse::<u64>().map_err(ReceiptsLogError::InvalidDistance)?; | ||
| PruneMode::Distance(distance) | ||
| } | ||
| s if s.starts_with("before") => { | ||
| if parts.len() < 3 { | ||
| return Err(ReceiptsLogError::InvalidFilterFormat(filter.to_string())); | ||
| } | ||
| let block_number = | ||
| parts[2].parse::<u64>().map_err(ReceiptsLogError::InvalidBlockNumber)?; | ||
| PruneMode::Before(block_number) | ||
| } | ||
| _ => return Err(ReceiptsLogError::InvalidPruneMode(parts[1].to_string())), | ||
| }; | ||
| config.insert(address, prune_mode); | ||
| } | ||
| Ok(ReceiptsLogPruneConfig(config)) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use alloy_primitives::address; | ||
| use clap::Parser; | ||
|
|
||
| /// A helper type to parse Args more easily | ||
| #[derive(Parser)] | ||
| struct CommandParser<T: Args> { | ||
| #[command(flatten)] | ||
| args: T, | ||
| } | ||
|
|
||
| #[test] | ||
| fn pruning_args_sanity_check() { | ||
| let args = CommandParser::<PruningArgs>::parse_from([ | ||
| "reth", | ||
| "--prune.receiptslogfilter", | ||
| "0x0000000000000000000000000000000000000003:before:5000000", | ||
| ]) | ||
| .args; | ||
| let mut config = ReceiptsLogPruneConfig::default(); | ||
| config.0.insert( | ||
| address!("0x0000000000000000000000000000000000000003"), | ||
| PruneMode::Before(5000000), | ||
| ); | ||
| assert_eq!(args.receipts_log_filter, Some(config)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn parse_receiptslogfilter() { | ||
| let default_args = PruningArgs::default(); | ||
| let args = CommandParser::<PruningArgs>::parse_from(["reth"]).args; | ||
| assert_eq!(args, default_args); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_receipts_log_filter() { | ||
| let filter1 = "0x0000000000000000000000000000000000000001:full"; | ||
| let filter2 = "0x0000000000000000000000000000000000000002:distance:1000"; | ||
| let filter3 = "0x0000000000000000000000000000000000000003:before:5000000"; | ||
| let filters = [filter1, filter2, filter3].join(","); | ||
|
|
||
| // Args can be parsed. | ||
| let result = parse_receipts_log_filter(&filters); | ||
| assert!(result.is_ok()); | ||
| let config = result.unwrap(); | ||
| assert_eq!(config.0.len(), 3); | ||
|
|
||
| // Check that the args were parsed correctly. | ||
| let addr1: Address = "0x0000000000000000000000000000000000000001".parse().unwrap(); | ||
| let addr2: Address = "0x0000000000000000000000000000000000000002".parse().unwrap(); | ||
| let addr3: Address = "0x0000000000000000000000000000000000000003".parse().unwrap(); | ||
|
|
||
| assert_eq!(config.0.get(&addr1), Some(&PruneMode::Full)); | ||
| assert_eq!(config.0.get(&addr2), Some(&PruneMode::Distance(1000))); | ||
| assert_eq!(config.0.get(&addr3), Some(&PruneMode::Before(5000000))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_receipts_log_filter_invalid_filter_format() { | ||
| let result = parse_receipts_log_filter("invalid_format"); | ||
| assert!(matches!(result, Err(ReceiptsLogError::InvalidFilterFormat(_)))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_receipts_log_filter_invalid_address() { | ||
| let result = parse_receipts_log_filter("invalid_address:full"); | ||
| assert!(matches!(result, Err(ReceiptsLogError::InvalidAddress(_)))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_receipts_log_filter_invalid_prune_mode() { | ||
| let result = | ||
| parse_receipts_log_filter("0x0000000000000000000000000000000000000000:invalid_mode"); | ||
| assert!(matches!(result, Err(ReceiptsLogError::InvalidPruneMode(_)))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_receipts_log_filter_invalid_distance() { | ||
| let result = parse_receipts_log_filter( | ||
| "0x0000000000000000000000000000000000000000:distance:invalid_distance", | ||
| ); | ||
| assert!(matches!(result, Err(ReceiptsLogError::InvalidDistance(_)))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_receipts_log_filter_invalid_block_number() { | ||
| let result = parse_receipts_log_filter( | ||
| "0x0000000000000000000000000000000000000000:before:invalid_block", | ||
| ); | ||
| assert!(matches!(result, Err(ReceiptsLogError::InvalidBlockNumber(_)))); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we just yeet this entirely?