reth_prune_types/
segment.rs1use crate::MINIMUM_PRUNING_DISTANCE;
2use derive_more::Display;
3use thiserror::Error;
4
5#[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
7#[cfg_attr(test, derive(arbitrary::Arbitrary))]
8#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
9#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
10#[cfg_attr(any(test, feature = "serde"), derive(serde::Serialize, serde::Deserialize))]
11pub enum PruneSegment {
12 SenderRecovery,
14 TransactionLookup,
16 Receipts,
18 ContractLogs,
20 AccountHistory,
22 StorageHistory,
24 Headers,
27 Transactions,
29}
30
31#[cfg(test)]
32#[allow(clippy::derivable_impls)]
33impl Default for PruneSegment {
34 fn default() -> Self {
35 Self::SenderRecovery
36 }
37}
38
39impl PruneSegment {
40 pub const fn min_blocks(&self, purpose: PrunePurpose) -> u64 {
42 match self {
43 Self::SenderRecovery | Self::TransactionLookup | Self::Headers | Self::Transactions => {
44 0
45 }
46 Self::Receipts if purpose.is_static_file() => 0,
47 Self::ContractLogs | Self::AccountHistory | Self::StorageHistory => {
48 MINIMUM_PRUNING_DISTANCE
49 }
50 Self::Receipts => MINIMUM_PRUNING_DISTANCE,
51 }
52 }
53
54 pub const fn is_account_history(&self) -> bool {
56 matches!(self, Self::AccountHistory)
57 }
58
59 pub const fn is_storage_history(&self) -> bool {
61 matches!(self, Self::StorageHistory)
62 }
63}
64
65#[derive(Debug, Clone, Copy)]
67pub enum PrunePurpose {
68 User,
70 StaticFile,
72}
73
74impl PrunePurpose {
75 pub const fn is_user(self) -> bool {
77 matches!(self, Self::User)
78 }
79
80 pub const fn is_static_file(self) -> bool {
82 matches!(self, Self::StaticFile)
83 }
84}
85
86#[derive(Debug, Error, PartialEq, Eq, Clone)]
88pub enum PruneSegmentError {
89 #[error("the configuration provided for {0} is invalid")]
91 Configuration(PruneSegment),
92}