reth_prune_types/
segment.rs1#![allow(deprecated)] use crate::MINIMUM_PRUNING_DISTANCE;
4use derive_more::Display;
5use thiserror::Error;
6
7#[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
13#[cfg_attr(test, derive(arbitrary::Arbitrary))]
14#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
15#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
16#[cfg_attr(any(test, feature = "serde"), derive(serde::Serialize, serde::Deserialize))]
17pub enum PruneSegment {
18 SenderRecovery,
20 TransactionLookup,
22 Receipts,
24 ContractLogs,
26 AccountHistory,
28 StorageHistory,
30 #[deprecated = "Variant indexes cannot be changed"]
31 Headers,
33 #[deprecated = "Variant indexes cannot be changed"]
34 Transactions,
36 MerkleChangeSets,
39 Bodies,
41}
42
43pub const PRUNE_SEGMENTS: [PruneSegment; 8] = [
45 PruneSegment::SenderRecovery,
46 PruneSegment::TransactionLookup,
47 PruneSegment::Receipts,
48 PruneSegment::ContractLogs,
49 PruneSegment::AccountHistory,
50 PruneSegment::StorageHistory,
51 PruneSegment::MerkleChangeSets,
52 PruneSegment::Bodies,
53];
54
55#[cfg(test)]
56#[allow(clippy::derivable_impls)]
57impl Default for PruneSegment {
58 fn default() -> Self {
59 Self::SenderRecovery
60 }
61}
62
63impl PruneSegment {
64 pub const fn min_blocks(&self, purpose: PrunePurpose) -> u64 {
66 match self {
67 Self::SenderRecovery | Self::TransactionLookup => 0,
68 Self::Receipts if purpose.is_static_file() => 0,
69 Self::ContractLogs |
70 Self::AccountHistory |
71 Self::StorageHistory |
72 Self::MerkleChangeSets |
73 Self::Bodies |
74 Self::Receipts => MINIMUM_PRUNING_DISTANCE,
75 #[expect(deprecated)]
76 #[expect(clippy::match_same_arms)]
77 Self::Headers | Self::Transactions => 0,
78 }
79 }
80
81 pub const fn is_account_history(&self) -> bool {
83 matches!(self, Self::AccountHistory)
84 }
85
86 pub const fn is_storage_history(&self) -> bool {
88 matches!(self, Self::StorageHistory)
89 }
90}
91
92#[derive(Debug, Clone, Copy)]
94pub enum PrunePurpose {
95 User,
97 StaticFile,
99}
100
101impl PrunePurpose {
102 pub const fn is_user(self) -> bool {
104 matches!(self, Self::User)
105 }
106
107 pub const fn is_static_file(self) -> bool {
109 matches!(self, Self::StaticFile)
110 }
111}
112
113#[derive(Debug, Error, PartialEq, Eq, Clone)]
115pub enum PruneSegmentError {
116 #[error("the configuration provided for {0} is invalid")]
118 Configuration(PruneSegment),
119}