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