diff --git a/Cargo.lock b/Cargo.lock index d7bc1dfa401..ae33eae4045 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7132,7 +7132,6 @@ dependencies = [ "rand 0.8.5", "reth-chainspec", "reth-codecs", - "reth-discv4", "reth-ecies", "reth-eth-wire-types", "reth-metrics", diff --git a/crates/net/downloaders/Cargo.toml b/crates/net/downloaders/Cargo.toml index 6f8e2a30926..f17ce036d15 100644 --- a/crates/net/downloaders/Cargo.toml +++ b/crates/net/downloaders/Cargo.toml @@ -33,7 +33,7 @@ alloy-rlp.workspace = true futures.workspace = true futures-util.workspace = true pin-project.workspace = true -tokio = { workspace = true, features = ["sync", "fs"] } +tokio = { workspace = true, features = ["sync", "fs", "io-util"] } tokio-stream.workspace = true tokio-util = { workspace = true, features = ["codec"] } diff --git a/crates/net/eth-wire/Cargo.toml b/crates/net/eth-wire/Cargo.toml index 1190a411dad..040b151437d 100644 --- a/crates/net/eth-wire/Cargo.toml +++ b/crates/net/eth-wire/Cargo.toml @@ -18,7 +18,6 @@ reth-codecs.workspace = true reth-primitives.workspace = true reth-ecies.workspace = true alloy-rlp = { workspace = true, features = ["derive"] } -reth-discv4.workspace = true reth-eth-wire-types.workspace = true reth-network-peers.workspace = true @@ -29,7 +28,7 @@ bytes.workspace = true derive_more.workspace = true thiserror.workspace = true serde = { workspace = true, optional = true } -tokio = { workspace = true, features = ["net", "sync", "time"] } +tokio = { workspace = true, features = ["macros", "net", "sync", "time"] } tokio-util = { workspace = true, features = ["io", "codec"] } futures.workspace = true tokio-stream.workspace = true diff --git a/crates/net/eth-wire/src/ethstream.rs b/crates/net/eth-wire/src/ethstream.rs index fac5e05495a..3979a822a92 100644 --- a/crates/net/eth-wire/src/ethstream.rs +++ b/crates/net/eth-wire/src/ethstream.rs @@ -348,12 +348,12 @@ mod tests { use crate::{ broadcast::BlockHashNumber, errors::{EthHandshakeError, EthStreamError}, + hello::DEFAULT_TCP_PORT, p2pstream::{ProtocolVersion, UnauthedP2PStream}, EthMessage, EthStream, EthVersion, HelloMessageWithProtocols, PassthroughCodec, Status, }; use futures::{SinkExt, StreamExt}; use reth_chainspec::NamedChain; - use reth_discv4::DEFAULT_DISCOVERY_PORT; use reth_ecies::stream::ECIESStream; use reth_network_peers::pk2id; use reth_primitives::{ForkFilter, Head, B256, U256}; @@ -624,7 +624,7 @@ mod tests { protocol_version: ProtocolVersion::V5, client_version: "bitcoind/1.0.0".to_string(), protocols: vec![EthVersion::Eth67.into()], - port: DEFAULT_DISCOVERY_PORT, + port: DEFAULT_TCP_PORT, id: pk2id(&server_key.public_key(SECP256K1)), }; @@ -652,7 +652,7 @@ mod tests { protocol_version: ProtocolVersion::V5, client_version: "bitcoind/1.0.0".to_string(), protocols: vec![EthVersion::Eth67.into()], - port: DEFAULT_DISCOVERY_PORT, + port: DEFAULT_TCP_PORT, id: pk2id(&client_key.public_key(SECP256K1)), }; diff --git a/crates/net/eth-wire/src/hello.rs b/crates/net/eth-wire/src/hello.rs index fbdffecec38..2e95e2c7e4e 100644 --- a/crates/net/eth-wire/src/hello.rs +++ b/crates/net/eth-wire/src/hello.rs @@ -1,10 +1,14 @@ use crate::{capability::Capability, EthVersion, ProtocolVersion}; use alloy_rlp::{RlpDecodable, RlpEncodable}; use reth_codecs::derive_arbitrary; -use reth_discv4::DEFAULT_DISCOVERY_PORT; use reth_network_peers::PeerId; use reth_primitives::constants::RETH_CLIENT_VERSION; +/// The default tcp port for p2p. +/// +/// Note: this is the same as discovery port: `DEFAULT_DISCOVERY_PORT` +pub(crate) const DEFAULT_TCP_PORT: u16 = 30303; + use crate::protocol::Protocol; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -29,6 +33,8 @@ pub struct HelloMessageWithProtocols { /// The list of supported capabilities and their versions. pub protocols: Vec, /// The port that the client is listening on, zero indicates the client is not listening. + /// + /// By default this is `30303` which is the same as the default discovery port. pub port: u16, /// The secp256k1 public key corresponding to the node's private key. pub id: PeerId, @@ -200,7 +206,7 @@ impl HelloMessageBuilder { protocols: protocols.unwrap_or_else(|| { vec![EthVersion::Eth68.into(), EthVersion::Eth67.into(), EthVersion::Eth66.into()] }), - port: port.unwrap_or(DEFAULT_DISCOVERY_PORT), + port: port.unwrap_or(DEFAULT_TCP_PORT), id, } } @@ -208,14 +214,12 @@ impl HelloMessageBuilder { #[cfg(test)] mod tests { - use alloy_rlp::{Decodable, Encodable, EMPTY_STRING_CODE}; - use reth_discv4::DEFAULT_DISCOVERY_PORT; - use reth_network_peers::pk2id; - use secp256k1::{SecretKey, SECP256K1}; - use crate::{ capability::Capability, p2pstream::P2PMessage, EthVersion, HelloMessage, ProtocolVersion, }; + use alloy_rlp::{Decodable, Encodable, EMPTY_STRING_CODE}; + use reth_network_peers::pk2id; + use secp256k1::{SecretKey, SECP256K1}; #[test] fn test_hello_encoding_round_trip() { @@ -225,7 +229,7 @@ mod tests { protocol_version: ProtocolVersion::V5, client_version: "reth/0.1.0".to_string(), capabilities: vec![Capability::new_static("eth", EthVersion::Eth67 as usize)], - port: DEFAULT_DISCOVERY_PORT, + port: 30303, id, }); @@ -245,7 +249,7 @@ mod tests { protocol_version: ProtocolVersion::V5, client_version: "reth/0.1.0".to_string(), capabilities: vec![Capability::new_static("eth", EthVersion::Eth67 as usize)], - port: DEFAULT_DISCOVERY_PORT, + port: 30303, id, }); @@ -264,7 +268,7 @@ mod tests { protocol_version: ProtocolVersion::V5, client_version: "reth/0.1.0".to_string(), capabilities: vec![Capability::new_static("eth", EthVersion::Eth67 as usize)], - port: DEFAULT_DISCOVERY_PORT, + port: 30303, id, }); diff --git a/crates/net/eth-wire/src/test_utils.rs b/crates/net/eth-wire/src/test_utils.rs index 466bc0f1cef..2d74cd18403 100644 --- a/crates/net/eth-wire/src/test_utils.rs +++ b/crates/net/eth-wire/src/test_utils.rs @@ -1,10 +1,10 @@ //! Utilities for testing p2p protocol. use crate::{ - EthVersion, HelloMessageWithProtocols, P2PStream, ProtocolVersion, Status, UnauthedP2PStream, + hello::DEFAULT_TCP_PORT, EthVersion, HelloMessageWithProtocols, P2PStream, ProtocolVersion, + Status, UnauthedP2PStream, }; use reth_chainspec::Chain; -use reth_discv4::DEFAULT_DISCOVERY_PORT; use reth_network_peers::pk2id; use reth_primitives::{ForkFilter, Head, B256, U256}; use secp256k1::{SecretKey, SECP256K1}; @@ -22,7 +22,7 @@ pub fn eth_hello() -> (HelloMessageWithProtocols, SecretKey) { protocol_version: ProtocolVersion::V5, client_version: "eth/1.0.0".to_string(), protocols, - port: DEFAULT_DISCOVERY_PORT, + port: DEFAULT_TCP_PORT, id: pk2id(&server_key.public_key(SECP256K1)), }; (hello, server_key)