reth_prune/
builder.rs
1use crate::{segments::SegmentSet, Pruner};
2use alloy_eips::eip2718::Encodable2718;
3use reth_chainspec::MAINNET_PRUNE_DELETE_LIMIT;
4use reth_config::PruneConfig;
5use reth_db_api::{table::Value, transaction::DbTxMut};
6use reth_exex_types::FinishedExExHeight;
7use reth_primitives_traits::NodePrimitives;
8use reth_provider::{
9 providers::StaticFileProvider, BlockReader, DBProvider, DatabaseProviderFactory,
10 NodePrimitivesProvider, PruneCheckpointWriter, StaticFileProviderFactory,
11};
12use reth_prune_types::PruneModes;
13use std::time::Duration;
14use tokio::sync::watch;
15
16#[derive(Debug, Clone)]
18pub struct PrunerBuilder {
19 block_interval: usize,
21 segments: PruneModes,
23 delete_limit: usize,
25 timeout: Option<Duration>,
27 finished_exex_height: watch::Receiver<FinishedExExHeight>,
29}
30
31impl PrunerBuilder {
32 pub const DEFAULT_TIMEOUT: Duration = Duration::from_millis(100);
34
35 pub fn new(pruner_config: PruneConfig) -> Self {
37 Self::default()
38 .block_interval(pruner_config.block_interval)
39 .segments(pruner_config.segments)
40 }
41
42 pub const fn block_interval(mut self, block_interval: usize) -> Self {
44 self.block_interval = block_interval;
45 self
46 }
47
48 pub fn segments(mut self, segments: PruneModes) -> Self {
50 self.segments = segments;
51 self
52 }
53
54 pub const fn delete_limit(mut self, prune_delete_limit: usize) -> Self {
56 self.delete_limit = prune_delete_limit;
57 self
58 }
59
60 pub const fn timeout(mut self, timeout: Duration) -> Self {
65 self.timeout = Some(timeout);
66 self
67 }
68
69 pub fn finished_exex_height(
71 mut self,
72 finished_exex_height: watch::Receiver<FinishedExExHeight>,
73 ) -> Self {
74 self.finished_exex_height = finished_exex_height;
75 self
76 }
77
78 pub fn build_with_provider_factory<PF>(self, provider_factory: PF) -> Pruner<PF::ProviderRW, PF>
80 where
81 PF: DatabaseProviderFactory<
82 ProviderRW: PruneCheckpointWriter
83 + BlockReader<Transaction: Encodable2718>
84 + StaticFileProviderFactory<
85 Primitives: NodePrimitives<SignedTx: Value, Receipt: Value>,
86 >,
87 > + StaticFileProviderFactory<
88 Primitives = <PF::ProviderRW as NodePrimitivesProvider>::Primitives,
89 >,
90 {
91 let segments =
92 SegmentSet::from_components(provider_factory.static_file_provider(), self.segments);
93
94 Pruner::new_with_factory(
95 provider_factory,
96 segments.into_vec(),
97 self.block_interval,
98 self.delete_limit,
99 self.timeout,
100 self.finished_exex_height,
101 )
102 }
103
104 pub fn build<Provider>(
106 self,
107 static_file_provider: StaticFileProvider<Provider::Primitives>,
108 ) -> Pruner<Provider, ()>
109 where
110 Provider: StaticFileProviderFactory<Primitives: NodePrimitives<SignedTx: Value, Receipt: Value>>
111 + DBProvider<Tx: DbTxMut>
112 + BlockReader<Transaction: Encodable2718>
113 + PruneCheckpointWriter,
114 {
115 let segments = SegmentSet::<Provider>::from_components(static_file_provider, self.segments);
116
117 Pruner::new(
118 segments.into_vec(),
119 self.block_interval,
120 self.delete_limit,
121 self.timeout,
122 self.finished_exex_height,
123 )
124 }
125}
126
127impl Default for PrunerBuilder {
128 fn default() -> Self {
129 Self {
130 block_interval: 5,
131 segments: PruneModes::none(),
132 delete_limit: MAINNET_PRUNE_DELETE_LIMIT,
133 timeout: None,
134 finished_exex_height: watch::channel(FinishedExExHeight::NoExExs).1,
135 }
136 }
137}