reth_prune_types/
segment.rs
1use 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
31impl PruneSegment {
32 pub const fn min_blocks(&self, purpose: PrunePurpose) -> u64 {
34 match self {
35 Self::SenderRecovery | Self::TransactionLookup | Self::Headers | Self::Transactions => {
36 0
37 }
38 Self::Receipts if purpose.is_static_file() => 0,
39 Self::ContractLogs | Self::AccountHistory | Self::StorageHistory => {
40 MINIMUM_PRUNING_DISTANCE
41 }
42 Self::Receipts => MINIMUM_PRUNING_DISTANCE,
43 }
44 }
45}
46
47#[derive(Debug, Clone, Copy)]
49pub enum PrunePurpose {
50 User,
52 StaticFile,
54}
55
56impl PrunePurpose {
57 pub const fn is_user(self) -> bool {
59 matches!(self, Self::User)
60 }
61
62 pub const fn is_static_file(self) -> bool {
64 matches!(self, Self::StaticFile)
65 }
66}
67
68#[derive(Debug, Error, PartialEq, Eq, Clone)]
70pub enum PruneSegmentError {
71 #[error("the configuration provided for {0} is invalid")]
73 Configuration(PruneSegment),
74}
75
76#[cfg(test)]
77impl Default for PruneSegment {
78 fn default() -> Self {
79 Self::SenderRecovery
80 }
81}