reth_network_p2p/lib.rs
1//! Provides abstractions and commonly used types for p2p.
2//!
3//! ## Feature Flags
4//!
5//! - `test-utils`: Export utilities for testing
6#![doc(
7 html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
8 html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
9 issue_tracker_base_url = "https://github.com/SeismicSystems/seismic-reth/issues/"
10)]
11#![cfg_attr(not(test), warn(unused_crate_dependencies))]
12#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
13
14/// Shared abstractions for downloader implementations.
15pub mod download;
16
17/// Traits for implementing P2P block body clients.
18pub mod bodies;
19
20/// A downloader that combines two different downloaders/client implementations.
21pub mod either;
22
23/// An implementation that uses headers and bodies traits to download full blocks
24pub mod full_block;
25pub use full_block::{FullBlockClient, NoopFullBlockClient};
26
27/// Traits for implementing P2P Header Clients. Also includes implementations
28/// of a Linear and a Parallel downloader generic over the [`Consensus`] and
29/// [`HeadersClient`].
30///
31/// [`Consensus`]: reth_consensus::Consensus
32/// [`HeadersClient`]: crate::headers::client::HeadersClient
33pub mod headers;
34
35/// Error types broadly used by p2p interfaces for any operation which may produce an error when
36/// interacting with the network implementation
37pub mod error;
38
39/// Priority enum for `BlockHeader` and `BlockBody` requests
40pub mod priority;
41
42/// Syncing related traits.
43pub mod sync;
44
45/// Snap related traits.
46pub mod snap;
47
48/// Common test helpers for mocking out Consensus, Downloaders and Header Clients.
49#[cfg(any(test, feature = "test-utils"))]
50pub mod test_utils;
51
52pub use bodies::client::BodiesClient;
53pub use headers::client::HeadersClient;
54use reth_primitives_traits::Block;
55
56/// Helper trait that unifies network behaviour needed for fetching entire blocks.
57pub trait BlockClient:
58 HeadersClient<Header = <Self::Block as Block>::Header>
59 + BodiesClient<Body = <Self::Block as Block>::Body>
60 + Unpin
61 + Clone
62{
63 /// The Block type that this client fetches.
64 type Block: Block;
65}
66
67/// The [`BlockClient`] providing Ethereum block parts.
68pub trait EthBlockClient: BlockClient<Block = reth_ethereum_primitives::Block> {}
69
70impl<T> EthBlockClient for T where T: BlockClient<Block = reth_ethereum_primitives::Block> {}