reth_prune_types/
pruner.rsuse crate::{PruneCheckpoint, PruneMode, PruneSegment};
use alloy_primitives::{BlockNumber, TxNumber};
use derive_more::Display;
#[derive(Debug)]
pub struct PrunerOutput {
pub progress: PruneProgress,
pub segments: Vec<(PruneSegment, SegmentOutput)>,
}
impl From<PruneProgress> for PrunerOutput {
fn from(progress: PruneProgress) -> Self {
Self { progress, segments: Vec::new() }
}
}
#[derive(Debug, Clone, PartialEq, Eq, Display)]
#[display("(table={segment}, pruned={pruned}, status={progress})")]
pub struct PrunedSegmentInfo {
pub segment: PruneSegment,
pub pruned: usize,
pub progress: PruneProgress,
}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct SegmentOutput {
pub progress: PruneProgress,
pub pruned: usize,
pub checkpoint: Option<SegmentOutputCheckpoint>,
}
impl SegmentOutput {
pub const fn done() -> Self {
Self { progress: PruneProgress::Finished, pruned: 0, checkpoint: None }
}
pub const fn not_done(
reason: PruneInterruptReason,
checkpoint: Option<SegmentOutputCheckpoint>,
) -> Self {
Self { progress: PruneProgress::HasMoreData(reason), pruned: 0, checkpoint }
}
}
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq)]
pub struct SegmentOutputCheckpoint {
pub block_number: Option<BlockNumber>,
pub tx_number: Option<TxNumber>,
}
impl SegmentOutputCheckpoint {
pub const fn from_prune_checkpoint(checkpoint: PruneCheckpoint) -> Self {
Self { block_number: checkpoint.block_number, tx_number: checkpoint.tx_number }
}
pub const fn as_prune_checkpoint(&self, prune_mode: PruneMode) -> PruneCheckpoint {
PruneCheckpoint { block_number: self.block_number, tx_number: self.tx_number, prune_mode }
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy, Display)]
pub enum PruneProgress {
#[display("HasMoreData({_0})")]
HasMoreData(PruneInterruptReason),
#[display("Finished")]
Finished,
}
#[derive(Debug, PartialEq, Eq, Clone, Copy, Display)]
pub enum PruneInterruptReason {
Timeout,
DeletedEntriesLimitReached,
Unknown,
}
impl PruneInterruptReason {
pub const fn is_timeout(&self) -> bool {
matches!(self, Self::Timeout)
}
pub const fn is_entries_limit_reached(&self) -> bool {
matches!(self, Self::DeletedEntriesLimitReached)
}
}
impl PruneProgress {
pub const fn is_finished(&self) -> bool {
matches!(self, Self::Finished)
}
}