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/paradigmxyz/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;
25
26/// Traits for implementing P2P Header Clients. Also includes implementations
27/// of a Linear and a Parallel downloader generic over the [`Consensus`] and
28/// [`HeadersClient`].
29///
30/// [`Consensus`]: reth_consensus::Consensus
31/// [`HeadersClient`]: crate::headers::client::HeadersClient
32pub mod headers;
33
34/// Error types broadly used by p2p interfaces for any operation which may produce an error when
35/// interacting with the network implementation
36pub mod error;
37
38/// Priority enum for `BlockHeader` and `BlockBody` requests
39pub mod priority;
40
41/// Syncing related traits.
42pub mod sync;
43
44/// Snap related traits.
45pub mod snap;
46
47/// Common test helpers for mocking out Consensus, Downloaders and Header Clients.
48#[cfg(any(test, feature = "test-utils"))]
49pub mod test_utils;
50
51pub use bodies::client::BodiesClient;
52pub use headers::client::HeadersClient;
53use reth_primitives_traits::Block;
54
55/// Helper trait that unifies network behaviour needed for fetching entire blocks.
56pub trait BlockClient:
57 HeadersClient<Header = <Self::Block as Block>::Header>
58 + BodiesClient<Body = <Self::Block as Block>::Body>
59 + Unpin
60 + Clone
61{
62 /// The Block type that this client fetches.
63 type Block: Block;
64}
65
66/// The [`BlockClient`] providing Ethereum block parts.
67pub trait EthBlockClient: BlockClient<Block = reth_ethereum_primitives::Block> {}
68
69impl<T> EthBlockClient for T where T: BlockClient<Block = reth_ethereum_primitives::Block> {}