Skip to content

Commit 0574e68

Browse files
committed
refactor(prune): derive EnumIter instead of explicit array of segments (#19465)
1 parent 4219741 commit 0574e68

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/prune/types/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ reth-codecs = { workspace = true, optional = true }
1616

1717
alloy-primitives.workspace = true
1818
derive_more.workspace = true
19+
strum = { workspace = true, features = ["derive"] }
1920
thiserror.workspace = true
2021

2122
modular-bitfield = { workspace = true, optional = true }
@@ -43,6 +44,7 @@ std = [
4344
"serde?/std",
4445
"serde_json/std",
4546
"thiserror/std",
47+
"strum/std",
4648
]
4749
test-utils = [
4850
"std",

crates/prune/types/src/segment.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::MINIMUM_PRUNING_DISTANCE;
22
use derive_more::Display;
3+
use strum::{EnumIter, IntoEnumIterator};
34
use thiserror::Error;
45

56
/// Segment of the data that can be pruned.
6-
#[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
7+
#[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, EnumIter)]
78
#[cfg_attr(test, derive(arbitrary::Arbitrary))]
89
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
910
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
@@ -37,6 +38,14 @@ impl Default for PruneSegment {
3738
}
3839

3940
impl PruneSegment {
41+
/// Returns an iterator over all variants of [`PruneSegment`].
42+
///
43+
/// Excludes deprecated variants that are no longer used, but can still be found in the
44+
/// database.
45+
pub fn variants() -> impl Iterator<Item = Self> {
46+
Self::iter()
47+
}
48+
4049
/// Returns minimum number of blocks to keep in the database for this segment.
4150
pub const fn min_blocks(&self, purpose: PrunePurpose) -> u64 {
4251
match self {

crates/storage/provider/src/providers/database/provider.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,10 +3005,13 @@ impl<TX: DbTx + 'static, N: NodeTypes> PruneCheckpointReader for DatabaseProvide
30053005
}
30063006

30073007
fn get_prune_checkpoints(&self) -> ProviderResult<Vec<(PruneSegment, PruneCheckpoint)>> {
3008-
Ok(self
3009-
.tx
3010-
.cursor_read::<tables::PruneCheckpoints>()?
3011-
.walk(None)?
3008+
Ok(PruneSegment::variants()
3009+
.filter_map(|segment| {
3010+
self.tx
3011+
.get::<tables::PruneCheckpoints>(segment)
3012+
.transpose()
3013+
.map(|chk| chk.map(|chk| (segment, chk)))
3014+
})
30123015
.collect::<Result<_, _>>()?)
30133016
}
30143017
}

0 commit comments

Comments
 (0)