use crate::BackfillJob; use std::ops::RangeInclusive; use reth_node_api::FullNodeComponents; use reth_primitives::BlockNumber; use reth_prune_types::PruneModes; use reth_stages_api::ExecutionStageThresholds; use super::stream::DEFAULT_PARALLELISM; /// Factory for creating new backfill jobs. #[derive(Debug, Clone)] pub struct BackfillJobFactory { executor: E, provider: P, prune_modes: PruneModes, thresholds: ExecutionStageThresholds, stream_parallelism: usize, } impl BackfillJobFactory { /// Creates a new [`BackfillJobFactory`]. pub fn new(executor: E, provider: P) -> Self { Self { executor, provider, prune_modes: PruneModes::none(), thresholds: ExecutionStageThresholds::default(), stream_parallelism: DEFAULT_PARALLELISM, } } /// Sets the prune modes pub fn with_prune_modes(mut self, prune_modes: PruneModes) -> Self { self.prune_modes = prune_modes; self } /// Sets the thresholds pub const fn with_thresholds(mut self, thresholds: ExecutionStageThresholds) -> Self { self.thresholds = thresholds; self } /// Sets the stream parallelism. /// /// Configures the [`StreamBackfillJob`](super::stream::StreamBackfillJob) created via /// [`BackfillJob::into_stream`]. pub const fn with_stream_parallelism(mut self, stream_parallelism: usize) -> Self { self.stream_parallelism = stream_parallelism; self } } impl BackfillJobFactory { /// Creates a new backfill job for the given range. pub fn backfill(&self, range: RangeInclusive) -> BackfillJob { BackfillJob { executor: self.executor.clone(), provider: self.provider.clone(), prune_modes: self.prune_modes.clone(), range, thresholds: self.thresholds.clone(), stream_parallelism: self.stream_parallelism, } } } impl BackfillJobFactory<(), ()> { /// Creates a new [`BackfillJobFactory`] from [`FullNodeComponents`]. pub fn new_from_components( components: Node, ) -> BackfillJobFactory { BackfillJobFactory::<_, _>::new( components.block_executor().clone(), components.provider().clone(), ) } }