Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ members = [
"crates/net/nat/",
"crates/net/network-api/",
"crates/net/network/",
"crates/net/p2p/",
"crates/net/types/",
"crates/node-core/",
"crates/node/api/",
Expand Down Expand Up @@ -249,6 +250,7 @@ reth-net-nat = { path = "crates/net/nat" }
reth-network = { path = "crates/net/network" }
reth-network-api = { path = "crates/net/network-api" }
reth-network-types = { path = "crates/net/types" }
reth-network-p2p = { path = "crates/net/p2p" }
reth-nippy-jar = { path = "crates/storage/nippy-jar" }
reth-node-api = { path = "crates/node/api" }
reth-node-builder = { path = "crates/node/builder" }
Expand Down
1 change: 0 additions & 1 deletion bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ min-trace-logs = ["tracing/release_max_level_trace"]

optimism = [
"reth-primitives/optimism",
"reth-interfaces/optimism",
"reth-rpc/optimism",
"reth-provider/optimism",
"reth-beacon-consensus/optimism",
Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain-tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ assert_matches.workspace = true

[features]
test-utils = []
optimism = ["reth-primitives/optimism", "reth-interfaces/optimism", "reth-provider/optimism"]
optimism = ["reth-primitives/optimism", "reth-provider/optimism"]
1 change: 0 additions & 1 deletion crates/consensus/beacon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ assert_matches.workspace = true
[features]
optimism = [
"reth-primitives/optimism",
"reth-interfaces/optimism",
"reth-provider/optimism",
"reth-blockchain-tree/optimism",
"reth-ethereum-consensus/optimism",
Expand Down
27 changes: 3 additions & 24 deletions crates/interfaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,15 @@ workspace = true
reth-primitives.workspace = true
reth-fs-util.workspace = true
reth-network-api.workspace = true
reth-eth-wire-types.workspace = true
reth-consensus.workspace = true
reth-network-types.workspace = true
reth-storage-errors.workspace = true

# async
futures.workspace = true
tokio = { workspace = true, features = ["sync"] }
reth-network-p2p.workspace = true

# misc
auto_impl.workspace = true
thiserror.workspace = true
tracing.workspace = true
secp256k1 = { workspace = true, default-features = false, features = [
"alloc",
"recovery",
"rand",
], optional = true }
parking_lot = { workspace = true, optional = true }
rand = { workspace = true, optional = true }

[dev-dependencies]
reth-consensus = { workspace = true, features = ["test-utils"] }

parking_lot.workspace = true
rand.workspace = true
tokio = { workspace = true, features = ["full"] }
secp256k1 = { workspace = true, features = ["alloc", "recovery", "rand"] }

[features]
test-utils = ["reth-consensus/test-utils", "secp256k1", "rand", "parking_lot"]
clap = ["reth-storage-errors/clap"]
optimism = ["reth-eth-wire-types/optimism"]
test-utils = ["reth-consensus/test-utils", "reth-network-p2p/test-utils"]
clap = ["reth-storage-errors/clap"]
6 changes: 3 additions & 3 deletions crates/interfaces/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod error;
pub use error::{RethError, RethResult};

/// P2P traits.
pub mod p2p;
pub use reth_network_p2p as p2p;

/// Trie error
pub mod trie;
Expand All @@ -34,6 +34,6 @@ pub mod sync;
/// BlockchainTree related traits.
pub mod blockchain_tree;

#[cfg(any(test, feature = "test-utils"))]
/// Common test helpers for mocking out Consensus, Downloaders and Header Clients.
pub mod test_utils;
#[cfg(feature = "test-utils")]
pub use reth_network_p2p::test_utils;
2 changes: 1 addition & 1 deletion crates/net/network-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Reth network interface definitions.
//! Reth interface definitions and commonly used types for the reth-network crate.
//!
//! Provides abstractions for the reth-network crate.
//!
Expand Down
48 changes: 48 additions & 0 deletions crates/net/p2p/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[package]
name = "reth-network-p2p"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
description = "traits and commonly used types for p2p and network communication"

[lints]
workspace = true

[dependencies]
reth-primitives.workspace = true
reth-network-api.workspace = true
reth-eth-wire-types.workspace = true
reth-consensus.workspace = true
reth-network-types.workspace = true
reth-storage-errors.workspace = true

# async
futures.workspace = true
tokio = { workspace = true, features = ["sync"] }

# misc
auto_impl.workspace = true
thiserror.workspace = true
tracing.workspace = true

secp256k1 = { workspace = true, default-features = false, features = [
"alloc",
"recovery",
"rand",
], optional = true }
parking_lot = { workspace = true, optional = true }
rand = { workspace = true, optional = true }

[dev-dependencies]
reth-consensus = { workspace = true, features = ["test-utils"] }

parking_lot.workspace = true
rand.workspace = true
tokio = { workspace = true, features = ["full"] }
secp256k1 = { workspace = true, features = ["alloc", "recovery", "rand"] }

[features]
test-utils = ["reth-consensus/test-utils", "secp256k1", "rand", "parking_lot"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
task::{ready, Context, Poll},
};

use crate::p2p::{download::DownloadClient, error::PeerRequestResult, priority::Priority};
use crate::{download::DownloadClient, error::PeerRequestResult, priority::Priority};
use futures::{Future, FutureExt};
use reth_primitives::{BlockBody, B256};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::response::BlockResponse;
use crate::p2p::error::DownloadResult;
use crate::error::DownloadResult;
use futures::Stream;
use reth_primitives::BlockNumber;
use std::ops::RangeInclusive;
Expand All @@ -10,7 +10,7 @@ pub type BodyDownloaderResult = DownloadResult<Vec<BlockResponse>>;
/// A downloader capable of fetching and yielding block bodies from block headers.
///
/// A downloader represents a distinct strategy for submitting requests to download block bodies,
/// while a [BodiesClient][crate::p2p::bodies::client::BodiesClient] represents a client capable of
/// while a [BodiesClient][crate::bodies::client::BodiesClient] represents a client capable of
/// fulfilling these requests.
pub trait BodyDownloader: Send + Sync + Stream<Item = BodyDownloaderResult> + Unpin {
/// Method for setting the download range.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Support for different download types.

use crate::p2p::{
use crate::{
bodies::client::BodiesClient,
download::DownloadClient,
headers::client::{HeadersClient, HeadersRequest},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::headers::client::HeadersRequest;
use crate::{db::DatabaseError, provider::ProviderError};
use reth_consensus::ConsensusError;
use reth_network_api::ReputationChangeKind;
use reth_network_types::WithPeerId;
use reth_primitives::{
BlockHashOrNumber, BlockNumber, GotExpected, GotExpectedBoxed, Header, B256,
};
use reth_storage_errors::{db::DatabaseError, provider::ProviderError};
use std::ops::RangeInclusive;
use thiserror::Error;
use tokio::sync::{mpsc, oneshot};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::headers::client::HeadersRequest;
use crate::p2p::{
use crate::{
bodies::client::{BodiesClient, SingleBodyRequest},
error::PeerRequestResult,
headers::client::{HeadersClient, SingleHeaderRequest},
Expand Down Expand Up @@ -727,11 +727,10 @@ enum RangeResponseResult {

#[cfg(test)]
mod tests {
use std::ops::Range;

use super::*;
use crate::test_utils::TestFullBlockClient;
use futures::StreamExt;
use std::ops::Range;

#[tokio::test]
async fn download_single_full_block() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::p2p::{download::DownloadClient, error::PeerRequestResult, priority::Priority};
use crate::{download::DownloadClient, error::PeerRequestResult, priority::Priority};
use futures::{Future, FutureExt};
pub use reth_eth_wire_types::BlockHeaders;
use reth_primitives::{BlockHashOrNumber, Header, HeadersDirection};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::error::HeadersDownloaderResult;
use crate::p2p::error::{DownloadError, DownloadResult};
use crate::error::{DownloadError, DownloadResult};
use futures::Stream;
use reth_consensus::Consensus;
use reth_primitives::{BlockHashOrNumber, SealedHeader, B256};
/// A downloader capable of fetching and yielding block headers.
///
/// A downloader represents a distinct strategy for submitting requests to download block headers,
/// while a [HeadersClient][crate::p2p::headers::client::HeadersClient] represents a client capable
/// while a [HeadersClient][crate::headers::client::HeadersClient] represents a client capable
/// of fulfilling these requests.
///
/// A [HeaderDownloader] is a [Stream] that returns batches of headers.
Expand Down
19 changes: 18 additions & 1 deletion crates/interfaces/src/p2p/mod.rs → crates/net/p2p/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
//! Provides abstractions and commonly used types for p2p.
//!
//! ## Feature Flags
//!
//! - `test-utils`: Export utilities for testing
#![doc(
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

/// Shared abstractions for downloader implementations.
pub mod download;

Expand All @@ -15,7 +28,7 @@ pub mod full_block;
/// [`HeadersClient`].
///
/// [`Consensus`]: reth_consensus::Consensus
/// [`HeadersClient`]: crate::p2p::headers::client::HeadersClient
/// [`HeadersClient`]: crate::headers::client::HeadersClient
pub mod headers;

/// Error types broadly used by p2p interfaces for any operation which may produce an error when
Expand All @@ -24,3 +37,7 @@ pub mod error;

/// Priority enum for BlockHeader and BlockBody requests
pub mod priority;

/// Common test helpers for mocking out Consensus, Downloaders and Header Clients.
#[cfg(any(test, feature = "test-utils"))]
pub mod test_utils;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::p2p::{
use crate::{
bodies::client::{BodiesClient, BodiesFut},
download::DownloadClient,
error::PeerRequestResult,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::p2p::{
use crate::{
bodies::client::BodiesClient,
download::DownloadClient,
error::PeerRequestResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ use std::{
ops::{Range, RangeInclusive},
};

// TODO(onbjerg): Maybe we should split this off to its own crate, or move the helpers to the
// relevant crates?

/// Returns a random number generator that can be seeded using the `SEED` environment variable.
///
/// If `SEED` is not set, a random seed is used.
Expand Down Expand Up @@ -353,6 +350,7 @@ pub fn random_receipt<R: Rng>(
) -> Receipt {
let success = rng.gen::<bool>();
let logs_count = logs_count.unwrap_or_else(|| rng.gen::<u8>());
#[allow(clippy::needless_update)] // side-effect of optimism fields
Receipt {
tx_type: transaction.tx_type(),
success,
Expand All @@ -362,10 +360,7 @@ pub fn random_receipt<R: Rng>(
} else {
vec![]
},
#[cfg(feature = "optimism")]
deposit_nonce: None,
#[cfg(feature = "optimism")]
deposit_receipt_version: None,
..Default::default()
}
}

Expand Down
Loading