reth_prune_types/
pruner.rs1use crate::{PruneCheckpoint, PruneMode, PruneSegment};
2use alloy_primitives::{BlockNumber, TxNumber};
3use derive_more::Display;
4
5#[derive(Debug)]
7pub struct PrunerOutput {
8 pub progress: PruneProgress,
10 pub segments: Vec<(PruneSegment, SegmentOutput)>,
12}
13
14impl From<PruneProgress> for PrunerOutput {
15 fn from(progress: PruneProgress) -> Self {
16 Self { progress, segments: Vec::new() }
17 }
18}
19
20#[derive(Debug, Clone, PartialEq, Eq, Display)]
22#[display("(table={segment}, pruned={pruned}, status={progress})")]
23pub struct PrunedSegmentInfo {
24 pub segment: PruneSegment,
26 pub pruned: usize,
28 pub progress: PruneProgress,
30}
31
32#[derive(Debug, Clone, Copy, Eq, PartialEq)]
34pub struct SegmentOutput {
35 pub progress: PruneProgress,
37 pub pruned: usize,
39 pub checkpoint: Option<SegmentOutputCheckpoint>,
41}
42
43impl SegmentOutput {
44 pub const fn done() -> Self {
47 Self { progress: PruneProgress::Finished, pruned: 0, checkpoint: None }
48 }
49
50 pub const fn not_done(
53 reason: PruneInterruptReason,
54 checkpoint: Option<SegmentOutputCheckpoint>,
55 ) -> Self {
56 Self { progress: PruneProgress::HasMoreData(reason), pruned: 0, checkpoint }
57 }
58}
59
60#[derive(Debug, Clone, Copy, Default, Eq, PartialEq)]
62pub struct SegmentOutputCheckpoint {
63 pub block_number: Option<BlockNumber>,
65 pub tx_number: Option<TxNumber>,
67}
68
69impl SegmentOutputCheckpoint {
70 pub const fn from_prune_checkpoint(checkpoint: PruneCheckpoint) -> Self {
72 Self { block_number: checkpoint.block_number, tx_number: checkpoint.tx_number }
73 }
74
75 pub const fn as_prune_checkpoint(&self, prune_mode: PruneMode) -> PruneCheckpoint {
77 PruneCheckpoint { block_number: self.block_number, tx_number: self.tx_number, prune_mode }
78 }
79}
80
81#[derive(Debug, PartialEq, Eq, Clone, Copy, Display)]
83pub enum PruneProgress {
84 #[display("HasMoreData({_0})")]
86 HasMoreData(PruneInterruptReason),
87 #[display("Finished")]
89 Finished,
90}
91
92#[derive(Debug, PartialEq, Eq, Clone, Copy, Display)]
94pub enum PruneInterruptReason {
95 Timeout,
97 DeletedEntriesLimitReached,
99 Unknown,
101}
102
103impl PruneInterruptReason {
104 pub const fn is_timeout(&self) -> bool {
106 matches!(self, Self::Timeout)
107 }
108
109 pub const fn is_entries_limit_reached(&self) -> bool {
111 matches!(self, Self::DeletedEntriesLimitReached)
112 }
113}
114
115impl PruneProgress {
116 pub const fn is_finished(&self) -> bool {
118 matches!(self, Self::Finished)
119 }
120}