From b5926073945a18012fbdc1863f04042b56de7233 Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Mon, 5 Aug 2024 00:22:14 +0800 Subject: [PATCH] Move reth_eth_wire::ProtocolVersion and reth_eth_wire::Capabilities to reth-eth-wire-types (#10071) Co-authored-by: Emilia Hane --- Cargo.lock | 2 +- crates/net/eth-wire-types/src/capability.rs | 174 +++++++++++++++++++ crates/net/eth-wire-types/src/lib.rs | 5 +- crates/net/eth-wire-types/src/version.rs | 44 ++++- crates/net/eth-wire/src/capability.rs | 175 +------------------- crates/net/eth-wire/src/ethstream.rs | 5 +- crates/net/eth-wire/src/hello.rs | 6 +- crates/net/eth-wire/src/lib.rs | 4 +- crates/net/eth-wire/src/multiplex.rs | 4 +- crates/net/eth-wire/src/p2pstream.rs | 43 +---- crates/net/eth-wire/src/protocol.rs | 2 +- crates/net/eth-wire/src/test_utils.rs | 2 +- crates/net/network-api/Cargo.toml | 2 +- crates/net/network-api/src/lib.rs | 2 +- crates/net/network-api/src/noop.rs | 2 +- crates/net/network/src/manager.rs | 3 +- crates/net/network/src/session/active.rs | 3 +- crates/net/network/src/session/handle.rs | 5 +- crates/net/network/src/session/mod.rs | 8 +- crates/net/network/src/state.rs | 9 +- crates/net/network/src/swarm.rs | 4 +- crates/net/network/tests/it/multiplex.rs | 2 +- 22 files changed, 252 insertions(+), 254 deletions(-) create mode 100644 crates/net/eth-wire-types/src/capability.rs diff --git a/Cargo.lock b/Cargo.lock index 352923cc3..15070dd47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7562,7 +7562,7 @@ dependencies = [ "auto_impl", "enr", "futures", - "reth-eth-wire", + "reth-eth-wire-types", "reth-network-p2p", "reth-network-peers", "reth-network-types", diff --git a/crates/net/eth-wire-types/src/capability.rs b/crates/net/eth-wire-types/src/capability.rs new file mode 100644 index 000000000..5302c9f43 --- /dev/null +++ b/crates/net/eth-wire-types/src/capability.rs @@ -0,0 +1,174 @@ +//! All capability related types + +use crate::EthVersion; +use alloy_rlp::{Decodable, Encodable, RlpDecodable, RlpEncodable}; +use bytes::BufMut; +use reth_codecs_derive::add_arbitrary_tests; +use std::{borrow::Cow, fmt}; + +/// A message indicating a supported capability and capability version. +#[add_arbitrary_tests(rlp)] +#[derive(Clone, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable, Default, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Capability { + /// The name of the subprotocol + pub name: Cow<'static, str>, + /// The version of the subprotocol + pub version: usize, +} + +impl Capability { + /// Create a new `Capability` with the given name and version. + pub const fn new(name: String, version: usize) -> Self { + Self { name: Cow::Owned(name), version } + } + + /// Create a new `Capability` with the given static name and version. + pub const fn new_static(name: &'static str, version: usize) -> Self { + Self { name: Cow::Borrowed(name), version } + } + + /// Returns the corresponding eth capability for the given version. + pub const fn eth(version: EthVersion) -> Self { + Self::new_static("eth", version as usize) + } + + /// Returns the [`EthVersion::Eth66`] capability. + pub const fn eth_66() -> Self { + Self::eth(EthVersion::Eth66) + } + + /// Returns the [`EthVersion::Eth67`] capability. + pub const fn eth_67() -> Self { + Self::eth(EthVersion::Eth67) + } + + /// Returns the [`EthVersion::Eth68`] capability. + pub const fn eth_68() -> Self { + Self::eth(EthVersion::Eth68) + } + + /// Whether this is eth v66 protocol. + #[inline] + pub fn is_eth_v66(&self) -> bool { + self.name == "eth" && self.version == 66 + } + + /// Whether this is eth v67. + #[inline] + pub fn is_eth_v67(&self) -> bool { + self.name == "eth" && self.version == 67 + } + + /// Whether this is eth v68. + #[inline] + pub fn is_eth_v68(&self) -> bool { + self.name == "eth" && self.version == 68 + } + + /// Whether this is any eth version. + #[inline] + pub fn is_eth(&self) -> bool { + self.is_eth_v66() || self.is_eth_v67() || self.is_eth_v68() + } +} + +impl fmt::Display for Capability { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}/{}", self.name, self.version) + } +} + +impl From for Capability { + #[inline] + fn from(value: EthVersion) -> Self { + Self::eth(value) + } +} + +#[cfg(any(test, feature = "arbitrary"))] +impl<'a> arbitrary::Arbitrary<'a> for Capability { + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + let version = u.int_in_range(0..=32)?; // TODO: What's the max? + let name = String::arbitrary(u)?; // TODO: what possible values? + Ok(Self::new(name, version)) + } +} + +/// Represents all capabilities of a node. +#[derive(Debug, Clone, Eq, PartialEq)] +pub struct Capabilities { + /// All Capabilities and their versions + inner: Vec, + eth_66: bool, + eth_67: bool, + eth_68: bool, +} + +impl Capabilities { + /// Returns all capabilities. + #[inline] + pub fn capabilities(&self) -> &[Capability] { + &self.inner + } + + /// Consumes the type and returns the all capabilities. + #[inline] + pub fn into_inner(self) -> Vec { + self.inner + } + + /// Whether the peer supports `eth` sub-protocol. + #[inline] + pub const fn supports_eth(&self) -> bool { + self.eth_68 || self.eth_67 || self.eth_66 + } + + /// Whether this peer supports eth v66 protocol. + #[inline] + pub const fn supports_eth_v66(&self) -> bool { + self.eth_66 + } + + /// Whether this peer supports eth v67 protocol. + #[inline] + pub const fn supports_eth_v67(&self) -> bool { + self.eth_67 + } + + /// Whether this peer supports eth v68 protocol. + #[inline] + pub const fn supports_eth_v68(&self) -> bool { + self.eth_68 + } +} + +impl From> for Capabilities { + fn from(value: Vec) -> Self { + Self { + eth_66: value.iter().any(Capability::is_eth_v66), + eth_67: value.iter().any(Capability::is_eth_v67), + eth_68: value.iter().any(Capability::is_eth_v68), + inner: value, + } + } +} + +impl Encodable for Capabilities { + fn encode(&self, out: &mut dyn BufMut) { + self.inner.encode(out) + } +} + +impl Decodable for Capabilities { + fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { + let inner = Vec::::decode(buf)?; + + Ok(Self { + eth_66: inner.iter().any(Capability::is_eth_v66), + eth_67: inner.iter().any(Capability::is_eth_v67), + eth_68: inner.iter().any(Capability::is_eth_v68), + inner, + }) + } +} diff --git a/crates/net/eth-wire-types/src/lib.rs b/crates/net/eth-wire-types/src/lib.rs index dc4197f1e..0e8fd5df9 100644 --- a/crates/net/eth-wire-types/src/lib.rs +++ b/crates/net/eth-wire-types/src/lib.rs @@ -12,7 +12,7 @@ mod status; pub use status::{Status, StatusBuilder}; pub mod version; -pub use version::EthVersion; +pub use version::{EthVersion, ProtocolVersion}; pub mod message; pub use message::{EthMessage, EthMessageID, ProtocolMessage}; @@ -37,3 +37,6 @@ pub use receipts::*; pub mod disconnect_reason; pub use disconnect_reason::*; + +pub mod capability; +pub use capability::*; diff --git a/crates/net/eth-wire-types/src/version.rs b/crates/net/eth-wire-types/src/version.rs index add1ab378..8ccb08d6a 100644 --- a/crates/net/eth-wire-types/src/version.rs +++ b/crates/net/eth-wire-types/src/version.rs @@ -1,8 +1,11 @@ //! Support for representing the version of the `eth` -use std::str::FromStr; +use std::{fmt, str::FromStr}; +use alloy_rlp::{Decodable, Encodable, Error as RlpError}; +use bytes::BufMut; use derive_more::Display; +use reth_codecs_derive::derive_arbitrary; /// Error thrown when failed to parse a valid [`EthVersion`]. #[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] @@ -127,6 +130,45 @@ impl From for &'static str { } } +/// RLPx `p2p` protocol version +#[derive_arbitrary(rlp)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum ProtocolVersion { + /// `p2p` version 4 + V4 = 4, + /// `p2p` version 5 + #[default] + V5 = 5, +} + +impl fmt::Display for ProtocolVersion { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "v{}", *self as u8) + } +} + +impl Encodable for ProtocolVersion { + fn encode(&self, out: &mut dyn BufMut) { + (*self as u8).encode(out) + } + fn length(&self) -> usize { + // the version should be a single byte + (*self as u8).length() + } +} + +impl Decodable for ProtocolVersion { + fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { + let version = u8::decode(buf)?; + match version { + 4 => Ok(Self::V4), + 5 => Ok(Self::V5), + _ => Err(RlpError::Custom("unknown p2p protocol version")), + } + } +} + #[cfg(test)] mod tests { use super::{EthVersion, ParseVersionError}; diff --git a/crates/net/eth-wire/src/capability.rs b/crates/net/eth-wire/src/capability.rs index 776cc375f..041400948 100644 --- a/crates/net/eth-wire/src/capability.rs +++ b/crates/net/eth-wire/src/capability.rs @@ -5,18 +5,15 @@ use crate::{ p2pstream::MAX_RESERVED_MESSAGE_ID, protocol::{ProtoVersion, Protocol}, version::ParseVersionError, - EthMessage, EthMessageID, EthVersion, + Capability, EthMessage, EthMessageID, EthVersion, }; -use alloy_rlp::{Decodable, Encodable, RlpDecodable, RlpEncodable}; use derive_more::{Deref, DerefMut}; -use reth_codecs::add_arbitrary_tests; -use reth_primitives::bytes::{BufMut, Bytes}; +use reth_primitives::bytes::Bytes; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; use std::{ borrow::Cow, collections::{BTreeSet, HashMap}, - fmt, }; /// A Capability message consisting of the message-id and the payload @@ -40,173 +37,6 @@ pub enum CapabilityMessage { Other(RawCapabilityMessage), } -/// A message indicating a supported capability and capability version. -#[add_arbitrary_tests(rlp)] -#[derive(Clone, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable, Default, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct Capability { - /// The name of the subprotocol - pub name: Cow<'static, str>, - /// The version of the subprotocol - pub version: usize, -} - -impl Capability { - /// Create a new `Capability` with the given name and version. - pub const fn new(name: String, version: usize) -> Self { - Self { name: Cow::Owned(name), version } - } - - /// Create a new `Capability` with the given static name and version. - pub const fn new_static(name: &'static str, version: usize) -> Self { - Self { name: Cow::Borrowed(name), version } - } - - /// Returns the corresponding eth capability for the given version. - pub const fn eth(version: EthVersion) -> Self { - Self::new_static("eth", version as usize) - } - - /// Returns the [`EthVersion::Eth66`] capability. - pub const fn eth_66() -> Self { - Self::eth(EthVersion::Eth66) - } - - /// Returns the [`EthVersion::Eth67`] capability. - pub const fn eth_67() -> Self { - Self::eth(EthVersion::Eth67) - } - - /// Returns the [`EthVersion::Eth68`] capability. - pub const fn eth_68() -> Self { - Self::eth(EthVersion::Eth68) - } - - /// Whether this is eth v66 protocol. - #[inline] - pub fn is_eth_v66(&self) -> bool { - self.name == "eth" && self.version == 66 - } - - /// Whether this is eth v67. - #[inline] - pub fn is_eth_v67(&self) -> bool { - self.name == "eth" && self.version == 67 - } - - /// Whether this is eth v68. - #[inline] - pub fn is_eth_v68(&self) -> bool { - self.name == "eth" && self.version == 68 - } - - /// Whether this is any eth version. - #[inline] - pub fn is_eth(&self) -> bool { - self.is_eth_v66() || self.is_eth_v67() || self.is_eth_v68() - } -} - -impl fmt::Display for Capability { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}/{}", self.name, self.version) - } -} - -impl From for Capability { - #[inline] - fn from(value: EthVersion) -> Self { - Self::eth(value) - } -} - -#[cfg(any(test, feature = "arbitrary"))] -impl<'a> arbitrary::Arbitrary<'a> for Capability { - fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { - let version = u.int_in_range(0..=32)?; // TODO: What's the max? - let name = String::arbitrary(u)?; // TODO: what possible values? - Ok(Self::new(name, version)) - } -} - -/// Represents all capabilities of a node. -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct Capabilities { - /// All Capabilities and their versions - inner: Vec, - eth_66: bool, - eth_67: bool, - eth_68: bool, -} - -impl Capabilities { - /// Returns all capabilities. - #[inline] - pub fn capabilities(&self) -> &[Capability] { - &self.inner - } - - /// Consumes the type and returns the all capabilities. - #[inline] - pub fn into_inner(self) -> Vec { - self.inner - } - - /// Whether the peer supports `eth` sub-protocol. - #[inline] - pub const fn supports_eth(&self) -> bool { - self.eth_68 || self.eth_67 || self.eth_66 - } - - /// Whether this peer supports eth v66 protocol. - #[inline] - pub const fn supports_eth_v66(&self) -> bool { - self.eth_66 - } - - /// Whether this peer supports eth v67 protocol. - #[inline] - pub const fn supports_eth_v67(&self) -> bool { - self.eth_67 - } - - /// Whether this peer supports eth v68 protocol. - #[inline] - pub const fn supports_eth_v68(&self) -> bool { - self.eth_68 - } -} - -impl From> for Capabilities { - fn from(value: Vec) -> Self { - Self { - eth_66: value.iter().any(Capability::is_eth_v66), - eth_67: value.iter().any(Capability::is_eth_v67), - eth_68: value.iter().any(Capability::is_eth_v68), - inner: value, - } - } -} - -impl Encodable for Capabilities { - fn encode(&self, out: &mut dyn BufMut) { - self.inner.encode(out) - } -} - -impl Decodable for Capabilities { - fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { - let inner = Vec::::decode(buf)?; - - Ok(Self { - eth_66: inner.iter().any(Capability::is_eth_v66), - eth_67: inner.iter().any(Capability::is_eth_v67), - eth_68: inner.iter().any(Capability::is_eth_v68), - inner, - }) - } -} - /// This represents a shared capability, its version, and its message id offset. /// /// The [offset](SharedCapability::message_id_offset) is the message ID offset for this shared @@ -549,6 +379,7 @@ pub struct UnsupportedCapabilityError { #[cfg(test)] mod tests { use super::*; + use crate::{Capabilities, Capability}; #[test] fn from_eth_68() { diff --git a/crates/net/eth-wire/src/ethstream.rs b/crates/net/eth-wire/src/ethstream.rs index 3979a822a..33ca14e38 100644 --- a/crates/net/eth-wire/src/ethstream.rs +++ b/crates/net/eth-wire/src/ethstream.rs @@ -349,8 +349,9 @@ mod tests { broadcast::BlockHashNumber, errors::{EthHandshakeError, EthStreamError}, hello::DEFAULT_TCP_PORT, - p2pstream::{ProtocolVersion, UnauthedP2PStream}, - EthMessage, EthStream, EthVersion, HelloMessageWithProtocols, PassthroughCodec, Status, + p2pstream::UnauthedP2PStream, + EthMessage, EthStream, EthVersion, HelloMessageWithProtocols, PassthroughCodec, + ProtocolVersion, Status, }; use futures::{SinkExt, StreamExt}; use reth_chainspec::NamedChain; diff --git a/crates/net/eth-wire/src/hello.rs b/crates/net/eth-wire/src/hello.rs index 2e95e2c7e..a88e19c08 100644 --- a/crates/net/eth-wire/src/hello.rs +++ b/crates/net/eth-wire/src/hello.rs @@ -1,4 +1,4 @@ -use crate::{capability::Capability, EthVersion, ProtocolVersion}; +use crate::{Capability, EthVersion, ProtocolVersion}; use alloy_rlp::{RlpDecodable, RlpEncodable}; use reth_codecs::derive_arbitrary; use reth_network_peers::PeerId; @@ -214,9 +214,7 @@ impl HelloMessageBuilder { #[cfg(test)] mod tests { - use crate::{ - capability::Capability, p2pstream::P2PMessage, EthVersion, HelloMessage, ProtocolVersion, - }; + use crate::{p2pstream::P2PMessage, Capability, EthVersion, HelloMessage, ProtocolVersion}; use alloy_rlp::{Decodable, Encodable, EMPTY_STRING_CODE}; use reth_network_peers::pk2id; use secp256k1::{SecretKey, SECP256K1}; diff --git a/crates/net/eth-wire/src/lib.rs b/crates/net/eth-wire/src/lib.rs index e672bc5b3..1fd68951a 100644 --- a/crates/net/eth-wire/src/lib.rs +++ b/crates/net/eth-wire/src/lib.rs @@ -32,14 +32,14 @@ pub use tokio_util::codec::{ }; pub use crate::{ - capability::Capability, disconnect::CanDisconnect, ethstream::{EthStream, UnauthedEthStream, MAX_MESSAGE_SIZE}, hello::{HelloMessage, HelloMessageBuilder, HelloMessageWithProtocols}, p2pstream::{ - DisconnectP2P, P2PMessage, P2PMessageID, P2PStream, ProtocolVersion, UnauthedP2PStream, + DisconnectP2P, P2PMessage, P2PMessageID, P2PStream, UnauthedP2PStream, MAX_RESERVED_MESSAGE_ID, }, + Capability, ProtocolVersion, }; // Re-export wire types diff --git a/crates/net/eth-wire/src/multiplex.rs b/crates/net/eth-wire/src/multiplex.rs index 08e281f1a..d1d977aba 100644 --- a/crates/net/eth-wire/src/multiplex.rs +++ b/crates/net/eth-wire/src/multiplex.rs @@ -17,10 +17,10 @@ use std::{ }; use crate::{ - capability::{Capability, SharedCapabilities, SharedCapability, UnsupportedCapabilityError}, + capability::{SharedCapabilities, SharedCapability, UnsupportedCapabilityError}, errors::{EthStreamError, P2PStreamError}, p2pstream::DisconnectP2P, - CanDisconnect, DisconnectReason, EthStream, P2PStream, Status, UnauthedEthStream, + CanDisconnect, Capability, DisconnectReason, EthStream, P2PStream, Status, UnauthedEthStream, }; use bytes::{Bytes, BytesMut}; use futures::{Sink, SinkExt, Stream, StreamExt, TryStream, TryStreamExt}; diff --git a/crates/net/eth-wire/src/p2pstream.rs b/crates/net/eth-wire/src/p2pstream.rs index 01394e864..60289ac6b 100644 --- a/crates/net/eth-wire/src/p2pstream.rs +++ b/crates/net/eth-wire/src/p2pstream.rs @@ -16,7 +16,7 @@ use reth_primitives::{ }; use std::{ collections::VecDeque, - fmt, io, + io, pin::Pin, task::{ready, Context, Poll}, time::Duration, @@ -788,49 +788,10 @@ impl TryFrom for P2PMessageID { } } -/// RLPx `p2p` protocol version -#[derive_arbitrary(rlp)] -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum ProtocolVersion { - /// `p2p` version 4 - V4 = 4, - /// `p2p` version 5 - #[default] - V5 = 5, -} - -impl fmt::Display for ProtocolVersion { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "v{}", *self as u8) - } -} - -impl Encodable for ProtocolVersion { - fn encode(&self, out: &mut dyn BufMut) { - (*self as u8).encode(out) - } - fn length(&self) -> usize { - // the version should be a single byte - (*self as u8).length() - } -} - -impl Decodable for ProtocolVersion { - fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { - let version = u8::decode(buf)?; - match version { - 4 => Ok(Self::V4), - 5 => Ok(Self::V5), - _ => Err(RlpError::Custom("unknown p2p protocol version")), - } - } -} - #[cfg(test)] mod tests { use super::*; - use crate::{capability::SharedCapability, test_utils::eth_hello, EthVersion}; + use crate::{capability::SharedCapability, test_utils::eth_hello, EthVersion, ProtocolVersion}; use tokio::net::{TcpListener, TcpStream}; use tokio_util::codec::Decoder; diff --git a/crates/net/eth-wire/src/protocol.rs b/crates/net/eth-wire/src/protocol.rs index 26b7d6d1b..b9d2eed61 100644 --- a/crates/net/eth-wire/src/protocol.rs +++ b/crates/net/eth-wire/src/protocol.rs @@ -1,6 +1,6 @@ //! A Protocol defines a P2P subprotocol in a `RLPx` connection -use crate::{capability::Capability, EthMessageID, EthVersion}; +use crate::{Capability, EthMessageID, EthVersion}; /// Type that represents a [Capability] and the number of messages it uses. /// diff --git a/crates/net/eth-wire/src/test_utils.rs b/crates/net/eth-wire/src/test_utils.rs index 2d74cd184..5dfd8d74b 100644 --- a/crates/net/eth-wire/src/test_utils.rs +++ b/crates/net/eth-wire/src/test_utils.rs @@ -60,7 +60,7 @@ pub async fn connect_passthrough( /// A Rplx subprotocol for testing pub mod proto { use super::*; - use crate::{capability::Capability, protocol::Protocol}; + use crate::{protocol::Protocol, Capability}; use bytes::{Buf, BufMut, BytesMut}; /// Returns a new testing `HelloMessage` with eth and the test protocol diff --git a/crates/net/network-api/Cargo.toml b/crates/net/network-api/Cargo.toml index 37c6b5282..cc8318b35 100644 --- a/crates/net/network-api/Cargo.toml +++ b/crates/net/network-api/Cargo.toml @@ -13,7 +13,7 @@ workspace = true [dependencies] # reth -reth-eth-wire.workspace = true +reth-eth-wire-types.workspace = true alloy-rpc-types-admin.workspace = true reth-network-peers.workspace = true reth-network-types.workspace = true diff --git a/crates/net/network-api/src/lib.rs b/crates/net/network-api/src/lib.rs index ca687da5b..b3fd06afd 100644 --- a/crates/net/network-api/src/lib.rs +++ b/crates/net/network-api/src/lib.rs @@ -28,7 +28,7 @@ pub use error::NetworkError; use std::{future::Future, net::SocketAddr, sync::Arc, time::Instant}; -use reth_eth_wire::{capability::Capabilities, DisconnectReason, EthVersion, Status}; +use reth_eth_wire_types::{capability::Capabilities, DisconnectReason, EthVersion, Status}; use reth_network_peers::NodeRecord; /// The `PeerId` type. diff --git a/crates/net/network-api/src/noop.rs b/crates/net/network-api/src/noop.rs index 1dd748448..3f4faf147 100644 --- a/crates/net/network-api/src/noop.rs +++ b/crates/net/network-api/src/noop.rs @@ -7,7 +7,7 @@ use std::net::{IpAddr, SocketAddr}; use alloy_rpc_types_admin::EthProtocolInfo; use enr::{secp256k1::SecretKey, Enr}; -use reth_eth_wire::{DisconnectReason, ProtocolVersion}; +use reth_eth_wire_types::{DisconnectReason, ProtocolVersion}; use reth_network_peers::NodeRecord; use reth_network_types::{PeerKind, Reputation, ReputationChangeKind}; diff --git a/crates/net/network/src/manager.rs b/crates/net/network/src/manager.rs index 603feca5d..2dd534d22 100644 --- a/crates/net/network/src/manager.rs +++ b/crates/net/network/src/manager.rs @@ -30,8 +30,7 @@ use std::{ use futures::{Future, StreamExt}; use parking_lot::Mutex; use reth_eth_wire::{ - capability::{Capabilities, CapabilityMessage}, - DisconnectReason, EthVersion, Status, + capability::CapabilityMessage, Capabilities, DisconnectReason, EthVersion, Status, }; use reth_fs_util::{self as fs, FsPathError}; use reth_metrics::common::mpsc::UnboundedMeteredSender; diff --git a/crates/net/network/src/session/active.rs b/crates/net/network/src/session/active.rs index 1aa1e6c26..873825f25 100644 --- a/crates/net/network/src/session/active.rs +++ b/crates/net/network/src/session/active.rs @@ -13,10 +13,9 @@ use std::{ use futures::{stream::Fuse, SinkExt, StreamExt}; use reth_eth_wire::{ - capability::Capabilities, errors::{EthHandshakeError, EthStreamError, P2PStreamError}, message::{EthBroadcastMessage, RequestPair}, - DisconnectP2P, DisconnectReason, EthMessage, + Capabilities, DisconnectP2P, DisconnectReason, EthMessage, }; use reth_metrics::common::mpsc::MeteredPollSender; use reth_network_p2p::error::RequestError; diff --git a/crates/net/network/src/session/handle.rs b/crates/net/network/src/session/handle.rs index ad9c491a2..a022e6704 100644 --- a/crates/net/network/src/session/handle.rs +++ b/crates/net/network/src/session/handle.rs @@ -4,9 +4,8 @@ use std::{io, net::SocketAddr, sync::Arc, time::Instant}; use reth_ecies::ECIESError; use reth_eth_wire::{ - capability::{Capabilities, CapabilityMessage}, - errors::EthStreamError, - DisconnectReason, EthVersion, Status, + capability::CapabilityMessage, errors::EthStreamError, Capabilities, DisconnectReason, + EthVersion, Status, }; use reth_network_api::PeerInfo; use reth_network_peers::{NodeRecord, PeerId}; diff --git a/crates/net/network/src/session/mod.rs b/crates/net/network/src/session/mod.rs index 1dfb9a4ea..ab07f3875 100644 --- a/crates/net/network/src/session/mod.rs +++ b/crates/net/network/src/session/mod.rs @@ -28,11 +28,9 @@ use counter::SessionCounter; use futures::{future::Either, io, FutureExt, StreamExt}; use reth_ecies::{stream::ECIESStream, ECIESError}; use reth_eth_wire::{ - capability::{Capabilities, CapabilityMessage}, - errors::EthStreamError, - multiplex::RlpxProtocolMultiplexer, - DisconnectReason, EthVersion, HelloMessageWithProtocols, Status, UnauthedEthStream, - UnauthedP2PStream, + capability::CapabilityMessage, errors::EthStreamError, multiplex::RlpxProtocolMultiplexer, + Capabilities, DisconnectReason, EthVersion, HelloMessageWithProtocols, Status, + UnauthedEthStream, UnauthedP2PStream, }; use reth_metrics::common::mpsc::MeteredPollSender; use reth_network_peers::PeerId; diff --git a/crates/net/network/src/state.rs b/crates/net/network/src/state.rs index 8038deed5..86b982936 100644 --- a/crates/net/network/src/state.rs +++ b/crates/net/network/src/state.rs @@ -13,9 +13,7 @@ use std::{ }; use rand::seq::SliceRandom; -use reth_eth_wire::{ - capability::Capabilities, BlockHashNumber, DisconnectReason, NewBlockHashes, Status, -}; +use reth_eth_wire::{BlockHashNumber, Capabilities, DisconnectReason, NewBlockHashes, Status}; use reth_network_peers::PeerId; use reth_network_types::{PeerAddr, PeerKind}; use reth_primitives::{ForkId, B256}; @@ -553,10 +551,7 @@ mod tests { state::{BlockNumReader, NetworkState}, PeerRequest, }; - use reth_eth_wire::{ - capability::{Capabilities, Capability}, - BlockBodies, EthVersion, - }; + use reth_eth_wire::{BlockBodies, Capabilities, Capability, EthVersion}; use reth_network_p2p::{bodies::client::BodiesClient, error::RequestError}; use reth_network_peers::PeerId; use reth_primitives::{BlockBody, Header, B256}; diff --git a/crates/net/network/src/swarm.rs b/crates/net/network/src/swarm.rs index b2c93dc42..4a2d1450f 100644 --- a/crates/net/network/src/swarm.rs +++ b/crates/net/network/src/swarm.rs @@ -8,9 +8,7 @@ use std::{ use futures::Stream; use reth_eth_wire::{ - capability::{Capabilities, CapabilityMessage}, - errors::EthStreamError, - EthVersion, Status, + capability::CapabilityMessage, errors::EthStreamError, Capabilities, EthVersion, Status, }; use reth_network_peers::PeerId; use tracing::trace; diff --git a/crates/net/network/tests/it/multiplex.rs b/crates/net/network/tests/it/multiplex.rs index 5e3e8f40c..9c3fce7c5 100644 --- a/crates/net/network/tests/it/multiplex.rs +++ b/crates/net/network/tests/it/multiplex.rs @@ -26,7 +26,7 @@ use crate::multiplex::proto::{PingPongProtoMessage, PingPongProtoMessageKind}; /// A simple Rlpx subprotocol that sends pings and pongs mod proto { use super::*; - use reth_eth_wire::capability::Capability; + use reth_eth_wire::Capability; use reth_primitives::{Buf, BufMut}; #[repr(u8)]