mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-09 15:28:01 -05:00
refactor(prune): derive EnumIter instead of explicit array of segments (#19465)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -9820,6 +9820,7 @@ dependencies = [
|
||||
"reth-codecs",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"strum 0.27.2",
|
||||
"test-fuzz",
|
||||
"thiserror 2.0.16",
|
||||
"toml",
|
||||
|
||||
@@ -16,6 +16,7 @@ reth-codecs = { workspace = true, optional = true }
|
||||
|
||||
alloy-primitives.workspace = true
|
||||
derive_more.workspace = true
|
||||
strum = { workspace = true, features = ["derive"] }
|
||||
thiserror.workspace = true
|
||||
|
||||
modular-bitfield = { workspace = true, optional = true }
|
||||
@@ -43,6 +44,7 @@ std = [
|
||||
"serde?/std",
|
||||
"serde_json/std",
|
||||
"thiserror/std",
|
||||
"strum/std",
|
||||
]
|
||||
test-utils = [
|
||||
"std",
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use crate::MINIMUM_PRUNING_DISTANCE;
|
||||
use derive_more::Display;
|
||||
use strum::{EnumIter, IntoEnumIterator};
|
||||
use thiserror::Error;
|
||||
|
||||
/// Segment of the data that can be pruned.
|
||||
#[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
#[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, EnumIter)]
|
||||
#[cfg_attr(test, derive(arbitrary::Arbitrary))]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
||||
@@ -37,6 +38,14 @@ impl Default for PruneSegment {
|
||||
}
|
||||
|
||||
impl PruneSegment {
|
||||
/// Returns an iterator over all variants of [`PruneSegment`].
|
||||
///
|
||||
/// Excludes deprecated variants that are no longer used, but can still be found in the
|
||||
/// database.
|
||||
pub fn variants() -> impl Iterator<Item = Self> {
|
||||
Self::iter()
|
||||
}
|
||||
|
||||
/// Returns minimum number of blocks to keep in the database for this segment.
|
||||
pub const fn min_blocks(&self, purpose: PrunePurpose) -> u64 {
|
||||
match self {
|
||||
|
||||
@@ -3005,10 +3005,13 @@ impl<TX: DbTx + 'static, N: NodeTypes> PruneCheckpointReader for DatabaseProvide
|
||||
}
|
||||
|
||||
fn get_prune_checkpoints(&self) -> ProviderResult<Vec<(PruneSegment, PruneCheckpoint)>> {
|
||||
Ok(self
|
||||
.tx
|
||||
.cursor_read::<tables::PruneCheckpoints>()?
|
||||
.walk(None)?
|
||||
Ok(PruneSegment::variants()
|
||||
.filter_map(|segment| {
|
||||
self.tx
|
||||
.get::<tables::PruneCheckpoints>(segment)
|
||||
.transpose()
|
||||
.map(|chk| chk.map(|chk| (segment, chk)))
|
||||
})
|
||||
.collect::<Result<_, _>>()?)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user