reth_node_builder/
sync.rs1use crate::components::NodeComponents;
4use reth_engine_tree::backfill::{BackfillSync, PipelineSync};
5use reth_network_api::BlockDownloaderProvider;
6use reth_provider::{providers::ProviderNodeTypes, ProviderFactory};
7use reth_stages::Pipeline;
8use reth_tasks::Runtime;
9
10pub trait BackfillSyncBuilder<N: ProviderNodeTypes, C>: Send {
15 type Backfill: BackfillSync + Unpin + 'static;
17
18 fn build(self, ctx: BackfillContext<N, C>) -> eyre::Result<Self::Backfill>;
20
21 fn recover(&mut self, _provider_factory: &ProviderFactory<N>) -> eyre::Result<()> {
25 Ok(())
26 }
27}
28
29#[derive(Debug)]
31pub struct BackfillContext<N: ProviderNodeTypes, C> {
32 pipeline: Pipeline<N>,
34 client: C,
36 provider_factory: ProviderFactory<N>,
37 runtime: Runtime,
38}
39
40impl<N: ProviderNodeTypes, C> BackfillContext<N, C> {
41 pub const fn new(
43 pipeline: Pipeline<N>,
44 client: C,
45 provider_factory: ProviderFactory<N>,
46 runtime: Runtime,
47 ) -> Self {
48 Self { pipeline, client, provider_factory, runtime }
49 }
50
51 pub const fn client(&self) -> &C {
53 &self.client
54 }
55
56 pub const fn provider_factory(&self) -> &ProviderFactory<N> {
58 &self.provider_factory
59 }
60
61 pub const fn runtime(&self) -> &Runtime {
63 &self.runtime
64 }
65
66 pub fn into_pipeline(self) -> Pipeline<N> {
68 self.pipeline
69 }
70}
71
72#[derive(Debug, Clone, Copy, Default)]
74pub struct PipelineBackfill;
75
76impl<N: ProviderNodeTypes, C> BackfillSyncBuilder<N, C> for PipelineBackfill {
77 type Backfill = PipelineSync<N>;
78
79 fn build(self, ctx: BackfillContext<N, C>) -> eyre::Result<Self::Backfill> {
80 let runtime = ctx.runtime().clone();
81 Ok(PipelineSync::new(ctx.into_pipeline(), runtime))
82 }
83}
84
85pub type BackfillClientFor<T, Components> =
87 <<Components as NodeComponents<T>>::Network as BlockDownloaderProvider>::Client;