From 2df1e548be4d8e3b4c2687d7d9821b34855057ff Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Fri, 15 Dec 2023 11:39:47 +0200 Subject: [PATCH] fix(cli): allow no PHF or compression in snapshots (#5765) --- bin/reth/src/db/snapshots/headers.rs | 4 ++-- bin/reth/src/db/snapshots/mod.rs | 25 +++++++++++++---------- bin/reth/src/db/snapshots/receipts.rs | 4 ++-- bin/reth/src/db/snapshots/transactions.rs | 4 ++-- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/bin/reth/src/db/snapshots/headers.rs b/bin/reth/src/db/snapshots/headers.rs index 5253601e3a..b3f60e156a 100644 --- a/bin/reth/src/db/snapshots/headers.rs +++ b/bin/reth/src/db/snapshots/headers.rs @@ -26,7 +26,7 @@ impl Command { chain: Arc, compression: Compression, inclusion_filter: InclusionFilter, - phf: PerfectHashingFunction, + phf: Option, ) -> eyre::Result<()> { let factory = ProviderFactory::new(open_db_read_only(db_path, log_level)?, chain.clone()); let provider = factory.provider()?; @@ -34,7 +34,7 @@ impl Command { let block_range = self.block_ranges(tip).first().expect("has been generated before").clone(); - let filters = if self.with_filters { + let filters = if let Some(phf) = self.with_filters.then_some(phf).flatten() { Filters::WithFilters(inclusion_filter, phf) } else { Filters::WithoutFilters diff --git a/bin/reth/src/db/snapshots/mod.rs b/bin/reth/src/db/snapshots/mod.rs index 7e6980bf3b..faefb750e7 100644 --- a/bin/reth/src/db/snapshots/mod.rs +++ b/bin/reth/src/db/snapshots/mod.rs @@ -59,7 +59,7 @@ pub struct Command { only_bench: bool, /// Compression algorithms to use. - #[arg(long, short, value_delimiter = ',', default_value = "lz4")] + #[arg(long, short, value_delimiter = ',', default_value = "uncompressed")] compression: Vec, /// Flag to enable inclusion list filters and PHFs. @@ -79,11 +79,14 @@ impl Command { log_level: Option, chain: Arc, ) -> eyre::Result<()> { - let all_combinations = self - .segments - .iter() - .cartesian_product(self.compression.iter()) - .cartesian_product(self.phf.iter()); + let all_combinations = + self.segments.iter().cartesian_product(self.compression.iter()).cartesian_product( + if self.phf.is_empty() { + vec![None] + } else { + self.phf.iter().copied().map(Some).collect::>() + }, + ); { let db = open_db_read_only(db_path, None)?; @@ -91,8 +94,8 @@ impl Command { if !self.only_bench { for ((mode, compression), phf) in all_combinations.clone() { - let filters = if self.with_filters { - Filters::WithFilters(InclusionFilter::Cuckoo, *phf) + let filters = if let Some(phf) = self.with_filters.then_some(phf).flatten() { + Filters::WithFilters(InclusionFilter::Cuckoo, phf) } else { Filters::WithoutFilters }; @@ -124,7 +127,7 @@ impl Command { chain.clone(), *compression, InclusionFilter::Cuckoo, - *phf, + phf, )?, SnapshotSegment::Transactions => self.bench_transactions_snapshot( db_path, @@ -132,7 +135,7 @@ impl Command { chain.clone(), *compression, InclusionFilter::Cuckoo, - *phf, + phf, )?, SnapshotSegment::Receipts => self.bench_receipts_snapshot( db_path, @@ -140,7 +143,7 @@ impl Command { chain.clone(), *compression, InclusionFilter::Cuckoo, - *phf, + phf, )?, } } diff --git a/bin/reth/src/db/snapshots/receipts.rs b/bin/reth/src/db/snapshots/receipts.rs index ce028f79b8..91a28c25ae 100644 --- a/bin/reth/src/db/snapshots/receipts.rs +++ b/bin/reth/src/db/snapshots/receipts.rs @@ -27,7 +27,7 @@ impl Command { chain: Arc, compression: Compression, inclusion_filter: InclusionFilter, - phf: PerfectHashingFunction, + phf: Option, ) -> eyre::Result<()> { let factory = ProviderFactory::new(open_db_read_only(db_path, log_level)?, chain.clone()); let provider = factory.provider()?; @@ -35,7 +35,7 @@ impl Command { let block_range = self.block_ranges(tip).first().expect("has been generated before").clone(); - let filters = if self.with_filters { + let filters = if let Some(phf) = self.with_filters.then_some(phf).flatten() { Filters::WithFilters(inclusion_filter, phf) } else { Filters::WithoutFilters diff --git a/bin/reth/src/db/snapshots/transactions.rs b/bin/reth/src/db/snapshots/transactions.rs index 690ca45b24..6fd38ed588 100644 --- a/bin/reth/src/db/snapshots/transactions.rs +++ b/bin/reth/src/db/snapshots/transactions.rs @@ -27,7 +27,7 @@ impl Command { chain: Arc, compression: Compression, inclusion_filter: InclusionFilter, - phf: PerfectHashingFunction, + phf: Option, ) -> eyre::Result<()> { let factory = ProviderFactory::new(open_db_read_only(db_path, log_level)?, chain.clone()); let provider = factory.provider()?; @@ -35,7 +35,7 @@ impl Command { let block_range = self.block_ranges(tip).first().expect("has been generated before").clone(); - let filters = if self.with_filters { + let filters = if let Some(phf) = self.with_filters.then_some(phf).flatten() { Filters::WithFilters(inclusion_filter, phf) } else { Filters::WithoutFilters