mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: extract p2p types from interfaces (#8382)
This commit is contained in:
29
Cargo.lock
generated
29
Cargo.lock
generated
@ -7030,20 +7030,13 @@ name = "reth-interfaces"
|
||||
version = "0.2.0-beta.7"
|
||||
dependencies = [
|
||||
"auto_impl",
|
||||
"futures",
|
||||
"parking_lot 0.12.2",
|
||||
"rand 0.8.5",
|
||||
"reth-consensus",
|
||||
"reth-eth-wire-types",
|
||||
"reth-fs-util",
|
||||
"reth-network-api",
|
||||
"reth-network-types",
|
||||
"reth-network-p2p",
|
||||
"reth-primitives",
|
||||
"reth-storage-errors",
|
||||
"secp256k1 0.28.2",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -7218,6 +7211,26 @@ dependencies = [
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "reth-network-p2p"
|
||||
version = "0.2.0-beta.7"
|
||||
dependencies = [
|
||||
"auto_impl",
|
||||
"futures",
|
||||
"parking_lot 0.12.2",
|
||||
"rand 0.8.5",
|
||||
"reth-consensus",
|
||||
"reth-eth-wire-types",
|
||||
"reth-network-api",
|
||||
"reth-network-types",
|
||||
"reth-primitives",
|
||||
"reth-storage-errors",
|
||||
"secp256k1 0.28.2",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "reth-network-types"
|
||||
version = "0.2.0-beta.7"
|
||||
|
||||
@ -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/",
|
||||
@ -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" }
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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"]
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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"]
|
||||
test-utils = ["reth-consensus/test-utils", "reth-network-p2p/test-utils"]
|
||||
clap = ["reth-storage-errors/clap"]
|
||||
optimism = ["reth-eth-wire-types/optimism"]
|
||||
|
||||
@ -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;
|
||||
@ -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;
|
||||
|
||||
@ -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.
|
||||
//!
|
||||
|
||||
48
crates/net/p2p/Cargo.toml
Normal file
48
crates/net/p2p/Cargo.toml
Normal file
@ -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"]
|
||||
@ -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};
|
||||
|
||||
@ -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;
|
||||
@ -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.
|
||||
@ -1,6 +1,6 @@
|
||||
//! Support for different download types.
|
||||
|
||||
use crate::p2p::{
|
||||
use crate::{
|
||||
bodies::client::BodiesClient,
|
||||
download::DownloadClient,
|
||||
headers::client::{HeadersClient, HeadersRequest},
|
||||
@ -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};
|
||||
@ -1,5 +1,5 @@
|
||||
use super::headers::client::HeadersRequest;
|
||||
use crate::p2p::{
|
||||
use crate::{
|
||||
bodies::client::{BodiesClient, SingleBodyRequest},
|
||||
error::PeerRequestResult,
|
||||
headers::client::{HeadersClient, SingleHeaderRequest},
|
||||
@ -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() {
|
||||
@ -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};
|
||||
@ -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.
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
@ -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;
|
||||
@ -1,4 +1,4 @@
|
||||
use crate::p2p::{
|
||||
use crate::{
|
||||
bodies::client::{BodiesClient, BodiesFut},
|
||||
download::DownloadClient,
|
||||
error::PeerRequestResult,
|
||||
@ -1,4 +1,4 @@
|
||||
use crate::p2p::{
|
||||
use crate::{
|
||||
bodies::client::BodiesClient,
|
||||
download::DownloadClient,
|
||||
error::PeerRequestResult,
|
||||
@ -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.
|
||||
@ -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,
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,19 +1,6 @@
|
||||
//! Testing support for headers related interfaces.
|
||||
|
||||
use std::{
|
||||
fmt,
|
||||
pin::Pin,
|
||||
sync::{
|
||||
atomic::{AtomicU64, Ordering},
|
||||
Arc,
|
||||
},
|
||||
task::{ready, Context, Poll},
|
||||
};
|
||||
|
||||
use futures::{Future, FutureExt, Stream, StreamExt};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::p2p::{
|
||||
use crate::{
|
||||
download::DownloadClient,
|
||||
error::{DownloadError, DownloadResult, PeerRequestResult, RequestError},
|
||||
headers::{
|
||||
@ -23,9 +10,20 @@ use crate::p2p::{
|
||||
},
|
||||
priority::Priority,
|
||||
};
|
||||
use futures::{Future, FutureExt, Stream, StreamExt};
|
||||
use reth_consensus::{test_utils::TestConsensus, Consensus};
|
||||
use reth_network_types::{PeerId, WithPeerId};
|
||||
use reth_primitives::{Header, HeadersDirection, SealedHeader};
|
||||
use std::{
|
||||
fmt,
|
||||
pin::Pin,
|
||||
sync::{
|
||||
atomic::{AtomicU64, Ordering},
|
||||
Arc,
|
||||
},
|
||||
task::{ready, Context, Poll},
|
||||
};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
/// A test downloader which just returns the values that have been pushed to it.
|
||||
#[derive(Debug)]
|
||||
@ -104,7 +104,6 @@ assert_matches.workspace = true
|
||||
[features]
|
||||
optimism = [
|
||||
"reth-primitives/optimism",
|
||||
"reth-interfaces/optimism",
|
||||
"reth-rpc/optimism",
|
||||
"reth-rpc-engine-api/optimism",
|
||||
"reth-provider/optimism",
|
||||
|
||||
@ -37,7 +37,6 @@ reth-revm = { workspace = true, features = ["test-utils"] }
|
||||
optimism = [
|
||||
"reth-primitives/optimism",
|
||||
"reth-provider/optimism",
|
||||
"reth-interfaces/optimism",
|
||||
"revm-primitives/optimism",
|
||||
"reth-optimism-consensus/optimism",
|
||||
]
|
||||
|
||||
@ -65,4 +65,4 @@ rand.workspace = true
|
||||
|
||||
[features]
|
||||
test-utils = ["alloy-rlp", "reth-db/test-utils", "reth-nippy-jar/test-utils"]
|
||||
optimism = ["reth-primitives/optimism", "reth-interfaces/optimism"]
|
||||
optimism = ["reth-primitives/optimism"]
|
||||
|
||||
Reference in New Issue
Block a user