reth_prune_types/
segment.rs1#![allow(deprecated)] use crate::MINIMUM_PRUNING_DISTANCE;
4use derive_more::Display;
5use strum::{EnumIter, IntoEnumIterator};
6use thiserror::Error;
7
8#[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, EnumIter)]
14#[cfg_attr(test, derive(arbitrary::Arbitrary))]
15#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
16#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
17#[cfg_attr(any(test, feature = "serde"), derive(serde::Serialize, serde::Deserialize))]
18pub enum PruneSegment {
19 SenderRecovery,
21 TransactionLookup,
23 Receipts,
25 ContractLogs,
27 AccountHistory,
29 StorageHistory,
31 #[deprecated = "Variant indexes cannot be changed"]
32 #[strum(disabled)]
33 Headers,
35 #[deprecated = "Variant indexes cannot be changed"]
36 #[strum(disabled)]
37 Transactions,
39 #[deprecated = "Variant indexes cannot be changed"]
40 #[strum(disabled)]
41 MerkleChangeSets,
44 Bodies,
46}
47
48#[cfg(test)]
49#[allow(clippy::derivable_impls)]
50impl Default for PruneSegment {
51 fn default() -> Self {
52 Self::SenderRecovery
53 }
54}
55
56impl PruneSegment {
57 pub fn variants() -> impl Iterator<Item = Self> {
62 Self::iter()
63 }
64
65 pub const fn min_blocks(&self) -> u64 {
67 match self {
68 Self::SenderRecovery | Self::TransactionLookup | Self::Receipts | Self::Bodies => 0,
69 Self::ContractLogs | Self::AccountHistory | Self::StorageHistory => {
70 MINIMUM_PRUNING_DISTANCE
71 }
72 #[expect(deprecated)]
73 #[expect(clippy::match_same_arms)]
74 Self::Headers | Self::Transactions | Self::MerkleChangeSets => 0,
75 }
76 }
77
78 pub const fn is_account_history(&self) -> bool {
80 matches!(self, Self::AccountHistory)
81 }
82
83 pub const fn is_storage_history(&self) -> bool {
85 matches!(self, Self::StorageHistory)
86 }
87}
88
89#[derive(Debug, Clone, Copy)]
91pub enum PrunePurpose {
92 User,
94 StaticFile,
96}
97
98impl PrunePurpose {
99 pub const fn is_user(self) -> bool {
101 matches!(self, Self::User)
102 }
103
104 pub const fn is_static_file(self) -> bool {
106 matches!(self, Self::StaticFile)
107 }
108}
109
110#[derive(Debug, Error, PartialEq, Eq, Clone)]
112pub enum PruneSegmentError {
113 #[error("the configuration provided for {0} is invalid")]
115 Configuration(PruneSegment),
116}
117
118#[cfg(test)]
119mod tests {
120 use super::*;
121
122 #[test]
123 fn test_prune_segment_iter_excludes_deprecated() {
124 let segments: Vec<PruneSegment> = PruneSegment::variants().collect();
125
126 #[expect(deprecated)]
128 {
129 assert!(!segments.contains(&PruneSegment::Headers));
130 assert!(!segments.contains(&PruneSegment::Transactions));
131 assert!(!segments.contains(&PruneSegment::MerkleChangeSets));
132 }
133 }
134}