reth_stages/
lib.rs

1//! Staged syncing primitives for reth.
2//!
3//! This crate contains the syncing primitives [`Pipeline`] and [`Stage`], as well as all stages
4//! that reth uses to sync.
5//!
6//! A pipeline can be configured using [`Pipeline::builder()`].
7//!
8//! For ease of use, this crate also exposes a set of [`StageSet`]s, which are collections of stages
9//! that perform specific functions during sync. Stage sets can be customized; it is possible to
10//! add, disable and replace stages in the set.
11//!
12//! # Examples
13//!
14//! ```
15//! # use std::sync::Arc;
16//! # use reth_downloaders::bodies::bodies::BodiesDownloaderBuilder;
17//! # use reth_downloaders::headers::reverse_headers::ReverseHeadersDownloaderBuilder;
18//! # use reth_network_p2p::test_utils::{TestBodiesClient, TestHeadersClient};
19//! # use reth_evm_ethereum::execute::EthExecutorProvider;
20//! # use alloy_primitives::B256;
21//! # use reth_chainspec::MAINNET;
22//! # use reth_prune_types::PruneModes;
23//! # use reth_network_peers::PeerId;
24//! # use reth_stages::Pipeline;
25//! # use reth_stages::sets::DefaultStages;
26//! # use tokio::sync::watch;
27//! # use reth_evm_ethereum::EthEvmConfig;
28//! # use reth_provider::ProviderFactory;
29//! # use reth_provider::StaticFileProviderFactory;
30//! # use reth_provider::test_utils::{create_test_provider_factory, MockNodeTypesWithDB};
31//! # use reth_static_file::StaticFileProducer;
32//! # use reth_config::config::StageConfig;
33//! # use reth_consensus::{Consensus, ConsensusError};
34//! # use reth_consensus::test_utils::TestConsensus;
35//! # use reth_consensus::FullConsensus;
36//! #
37//! # let chain_spec = MAINNET.clone();
38//! # let consensus: Arc<dyn FullConsensus<reth_ethereum_primitives::EthPrimitives, Error = ConsensusError>> = Arc::new(TestConsensus::default());
39//! # let headers_downloader = ReverseHeadersDownloaderBuilder::default().build(
40//! #    Arc::new(TestHeadersClient::default()),
41//! #    consensus.clone().as_header_validator()
42//! # );
43//! # let provider_factory = create_test_provider_factory();
44//! # let bodies_downloader = BodiesDownloaderBuilder::default().build(
45//! #    Arc::new(TestBodiesClient { responder: |_| Ok((PeerId::ZERO, vec![]).into()) }),
46//! #    consensus.clone().as_consensus(),
47//! #    provider_factory.clone()
48//! # );
49//! # let (tip_tx, tip_rx) = watch::channel(B256::default());
50//! # let executor_provider = EthExecutorProvider::mainnet();
51//! # let static_file_producer = StaticFileProducer::new(
52//! #    provider_factory.clone(),
53//! #    PruneModes::default()
54//! # );
55//! // Create a pipeline that can fully sync
56//! # let pipeline =
57//! Pipeline::<MockNodeTypesWithDB>::builder()
58//!     .with_tip_sender(tip_tx)
59//!     .add_stages(DefaultStages::new(
60//!         provider_factory.clone(),
61//!         tip_rx,
62//!         consensus,
63//!         headers_downloader,
64//!         bodies_downloader,
65//!         executor_provider,
66//!         StageConfig::default(),
67//!         PruneModes::default(),
68//!     ))
69//!     .build(provider_factory, static_file_producer);
70//! ```
71//!
72//! ## Feature Flags
73//!
74//! - `test-utils`: Export utilities for testing
75
76#![doc(
77    html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
78    html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
79    issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
80)]
81#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
82#![cfg_attr(not(test), warn(unused_crate_dependencies))]
83
84#[allow(missing_docs)]
85#[cfg(any(test, feature = "test-utils"))]
86pub mod test_utils;
87
88/// A re-export of common structs and traits.
89pub mod prelude;
90
91/// Implementations of stages.
92pub mod stages;
93
94pub mod sets;
95
96// re-export the stages API
97pub use reth_stages_api::*;