reth_prune_types/
pruner.rs1use crate::{PruneCheckpoint, PruneMode, PruneSegment};
2use alloc::vec::Vec;
3use alloy_primitives::{BlockNumber, TxNumber};
4use derive_more::Display;
5
6#[derive(Debug)]
8pub struct PrunerOutput {
9    pub progress: PruneProgress,
11    pub segments: Vec<(PruneSegment, SegmentOutput)>,
13}
14
15impl From<PruneProgress> for PrunerOutput {
16    fn from(progress: PruneProgress) -> Self {
17        Self { progress, segments: Vec::new() }
18    }
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Display)]
23#[display("(table={segment}, pruned={pruned}, status={progress})")]
24pub struct PrunedSegmentInfo {
25    pub segment: PruneSegment,
27    pub pruned: usize,
29    pub progress: PruneProgress,
31}
32
33#[derive(Debug, Clone, Copy, Eq, PartialEq)]
35pub struct SegmentOutput {
36    pub progress: PruneProgress,
38    pub pruned: usize,
40    pub checkpoint: Option<SegmentOutputCheckpoint>,
42}
43
44impl SegmentOutput {
45    pub const fn done() -> Self {
48        Self { progress: PruneProgress::Finished, pruned: 0, checkpoint: None }
49    }
50
51    pub const fn not_done(
54        reason: PruneInterruptReason,
55        checkpoint: Option<SegmentOutputCheckpoint>,
56    ) -> Self {
57        Self { progress: PruneProgress::HasMoreData(reason), pruned: 0, checkpoint }
58    }
59}
60
61#[derive(Debug, Clone, Copy, Default, Eq, PartialEq)]
63pub struct SegmentOutputCheckpoint {
64    pub block_number: Option<BlockNumber>,
66    pub tx_number: Option<TxNumber>,
68}
69
70impl SegmentOutputCheckpoint {
71    pub const fn from_prune_checkpoint(checkpoint: PruneCheckpoint) -> Self {
73        Self { block_number: checkpoint.block_number, tx_number: checkpoint.tx_number }
74    }
75
76    pub const fn as_prune_checkpoint(&self, prune_mode: PruneMode) -> PruneCheckpoint {
78        PruneCheckpoint { block_number: self.block_number, tx_number: self.tx_number, prune_mode }
79    }
80}
81
82#[derive(Debug, PartialEq, Eq, Clone, Copy, Display)]
84pub enum PruneProgress {
85    #[display("HasMoreData({_0})")]
87    HasMoreData(PruneInterruptReason),
88    #[display("Finished")]
90    Finished,
91}
92
93#[derive(Debug, PartialEq, Eq, Clone, Copy, Display)]
95pub enum PruneInterruptReason {
96    Timeout,
98    DeletedEntriesLimitReached,
100    Unknown,
102}
103
104impl PruneInterruptReason {
105    pub const fn is_timeout(&self) -> bool {
107        matches!(self, Self::Timeout)
108    }
109
110    pub const fn is_entries_limit_reached(&self) -> bool {
112        matches!(self, Self::DeletedEntriesLimitReached)
113    }
114}
115
116impl PruneProgress {
117    pub const fn is_finished(&self) -> bool {
119        matches!(self, Self::Finished)
120    }
121}