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