diff --git a/Cargo.lock b/Cargo.lock index a2375940284d..c94fcd909149 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5542,6 +5542,7 @@ dependencies = [ "proptest-derive", "rand 0.8.5", "reth-codecs", + "reth-discv4", "reth-ecies", "reth-metrics", "reth-primitives", @@ -5738,6 +5739,7 @@ name = "reth-network-api" version = "0.1.0-alpha.7" dependencies = [ "async-trait", + "reth-discv4", "reth-eth-wire", "reth-primitives", "reth-rpc-types", diff --git a/crates/net/discv4/src/lib.rs b/crates/net/discv4/src/lib.rs index 20b729330e9d..fa7077bc3122 100644 --- a/crates/net/discv4/src/lib.rs +++ b/crates/net/discv4/src/lib.rs @@ -2178,7 +2178,7 @@ mod tests { let v4: Ipv4Addr = "0.0.0.0".parse().unwrap(); let v6 = v4.to_ipv6_mapped(); - let addr: SocketAddr = (v6, 30303).into(); + let addr: SocketAddr = (v6, DEFAULT_DISCOVERY_PORT).into(); let ping = Ping { from: rng_endpoint(&mut rng), @@ -2210,7 +2210,7 @@ mod tests { let v4: Ipv4Addr = "0.0.0.0".parse().unwrap(); let v6 = v4.to_ipv6_mapped(); - let addr: SocketAddr = (v6, 30303).into(); + let addr: SocketAddr = (v6, DEFAULT_DISCOVERY_PORT).into(); let ping = Ping { from: rng_endpoint(&mut rng), diff --git a/crates/net/discv4/src/proto.rs b/crates/net/discv4/src/proto.rs index 88b3bb93644d..b02082f9e86d 100644 --- a/crates/net/discv4/src/proto.rs +++ b/crates/net/discv4/src/proto.rs @@ -496,7 +496,7 @@ mod tests { use super::*; use crate::{ test_utils::{rng_endpoint, rng_ipv4_record, rng_ipv6_record, rng_message}, - SAFE_MAX_DATAGRAM_NEIGHBOUR_RECORDS, + DEFAULT_DISCOVERY_PORT, SAFE_MAX_DATAGRAM_NEIGHBOUR_RECORDS, }; use enr::{EnrBuilder, EnrPublicKey}; use rand::{thread_rng, Rng, RngCore}; @@ -773,7 +773,7 @@ mod tests { assert_eq!(enr.0.ip4(), Some(Ipv4Addr::new(127, 0, 0, 1))); assert_eq!(enr.0.id(), Some(String::from("v4"))); - assert_eq!(enr.0.udp4(), Some(30303)); + assert_eq!(enr.0.udp4(), Some(DEFAULT_DISCOVERY_PORT)); assert_eq!(enr.0.tcp4(), None); assert_eq!(enr.0.signature(), &signature[..]); assert_eq!(pubkey.to_vec(), expected_pubkey); @@ -808,7 +808,7 @@ mod tests { assert_eq!(enr.0.ip4(), Some(Ipv4Addr::new(127, 0, 0, 1))); assert_eq!(enr.0.id(), Some(String::from("v4"))); - assert_eq!(enr.0.udp4(), Some(30303)); + assert_eq!(enr.0.udp4(), Some(DEFAULT_DISCOVERY_PORT)); assert_eq!(enr.0.tcp4(), None); assert_eq!(enr.0.signature(), &signature[..]); assert_eq!(pubkey.to_vec(), expected_pubkey); diff --git a/crates/net/eth-wire/Cargo.toml b/crates/net/eth-wire/Cargo.toml index 84e62184f882..e6d865246732 100644 --- a/crates/net/eth-wire/Cargo.toml +++ b/crates/net/eth-wire/Cargo.toml @@ -24,6 +24,7 @@ reth-rlp = { workspace = true, features = [ "ethereum-types", "smol_str", ] } +reth-discv4 = {path = "../discv4" } # metrics reth-metrics.workspace = true diff --git a/crates/net/eth-wire/src/builder.rs b/crates/net/eth-wire/src/builder.rs index 23da3bce69a4..3b5866bdeff0 100644 --- a/crates/net/eth-wire/src/builder.rs +++ b/crates/net/eth-wire/src/builder.rs @@ -4,6 +4,7 @@ use crate::{ capability::Capability, hello::HelloMessage, p2pstream::ProtocolVersion, EthVersion, Status, }; +use reth_discv4::DEFAULT_DISCOVERY_PORT; use reth_primitives::{Chain, ForkId, PeerId, H256, U256}; /// Builder for [`Status`](crate::types::Status) messages. @@ -100,7 +101,7 @@ impl HelloBuilder { client_version: "Ethereum/1.0.0".to_string(), capabilities: vec![EthVersion::Eth68.into()], // TODO: default port config - port: 30303, + port: DEFAULT_DISCOVERY_PORT, id: pubkey, }, } diff --git a/crates/net/eth-wire/src/ethstream.rs b/crates/net/eth-wire/src/ethstream.rs index ae5d60edf3e9..70472e9e9fbd 100644 --- a/crates/net/eth-wire/src/ethstream.rs +++ b/crates/net/eth-wire/src/ethstream.rs @@ -323,6 +323,7 @@ mod tests { }; use ethers_core::types::Chain; use futures::{SinkExt, StreamExt}; + use reth_discv4::DEFAULT_DISCOVERY_PORT; use reth_ecies::{stream::ECIESStream, util::pk2id}; use reth_primitives::{ForkFilter, Head, H256, U256}; use secp256k1::{SecretKey, SECP256K1}; @@ -591,7 +592,7 @@ mod tests { protocol_version: ProtocolVersion::V5, client_version: "bitcoind/1.0.0".to_string(), capabilities: vec![Capability::new("eth".into(), EthVersion::Eth67 as usize)], - port: 30303, + port: DEFAULT_DISCOVERY_PORT, id: pk2id(&server_key.public_key(SECP256K1)), }; @@ -619,7 +620,7 @@ mod tests { protocol_version: ProtocolVersion::V5, client_version: "bitcoind/1.0.0".to_string(), capabilities: vec![Capability::new("eth".into(), EthVersion::Eth67 as usize)], - port: 30303, + port: DEFAULT_DISCOVERY_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 c14759fd40ba..acbb2c4337d9 100644 --- a/crates/net/eth-wire/src/hello.rs +++ b/crates/net/eth-wire/src/hello.rs @@ -1,5 +1,6 @@ use crate::{capability::Capability, EthVersion, ProtocolVersion}; use reth_codecs::derive_arbitrary; +use reth_discv4::DEFAULT_DISCOVERY_PORT; use reth_primitives::{constants::RETH_CLIENT_VERSION, PeerId}; use reth_rlp::{RlpDecodable, RlpEncodable}; @@ -99,7 +100,7 @@ impl HelloMessageBuilder { capabilities: capabilities.unwrap_or_else(|| { vec![EthVersion::Eth68.into(), EthVersion::Eth67.into(), EthVersion::Eth66.into()] }), - port: port.unwrap_or(30303), + port: port.unwrap_or(DEFAULT_DISCOVERY_PORT), id, } } @@ -107,6 +108,7 @@ impl HelloMessageBuilder { #[cfg(test)] mod tests { + use reth_discv4::DEFAULT_DISCOVERY_PORT; use reth_ecies::util::pk2id; use reth_rlp::{Decodable, Encodable, EMPTY_STRING_CODE}; use secp256k1::{SecretKey, SECP256K1}; @@ -123,7 +125,7 @@ mod tests { protocol_version: ProtocolVersion::V5, client_version: "reth/0.1.0".to_string(), capabilities: vec![Capability::new("eth".into(), EthVersion::Eth67 as usize)], - port: 30303, + port: DEFAULT_DISCOVERY_PORT, id, }); @@ -143,7 +145,7 @@ mod tests { protocol_version: ProtocolVersion::V5, client_version: "reth/0.1.0".to_string(), capabilities: vec![Capability::new("eth".into(), EthVersion::Eth67 as usize)], - port: 30303, + port: DEFAULT_DISCOVERY_PORT, id, }); @@ -162,7 +164,7 @@ mod tests { protocol_version: ProtocolVersion::V5, client_version: "reth/0.1.0".to_string(), capabilities: vec![Capability::new("eth".into(), EthVersion::Eth67 as usize)], - port: 30303, + port: DEFAULT_DISCOVERY_PORT, id, }); diff --git a/crates/net/eth-wire/src/p2pstream.rs b/crates/net/eth-wire/src/p2pstream.rs index 8b2b9e0fac45..b46d3ecd6a35 100644 --- a/crates/net/eth-wire/src/p2pstream.rs +++ b/crates/net/eth-wire/src/p2pstream.rs @@ -827,6 +827,7 @@ impl Decodable for ProtocolVersion { mod tests { use super::*; use crate::{DisconnectReason, EthVersion}; + use reth_discv4::DEFAULT_DISCOVERY_PORT; use reth_ecies::util::pk2id; use secp256k1::{SecretKey, SECP256K1}; use tokio::net::{TcpListener, TcpStream}; @@ -839,7 +840,7 @@ mod tests { protocol_version: ProtocolVersion::V5, client_version: "bitcoind/1.0.0".to_string(), capabilities: vec![EthVersion::Eth67.into()], - port: 30303, + port: DEFAULT_DISCOVERY_PORT, id: pk2id(&server_key.public_key(SECP256K1)), }; (hello, server_key) diff --git a/crates/net/network-api/Cargo.toml b/crates/net/network-api/Cargo.toml index acd433d78521..8ae24e40fb57 100644 --- a/crates/net/network-api/Cargo.toml +++ b/crates/net/network-api/Cargo.toml @@ -13,6 +13,7 @@ description = "Network interfaces" reth-primitives.workspace = true reth-eth-wire = { path = "../eth-wire" } reth-rpc-types.workspace = true +reth-discv4 = { path = "../discv4" } # io serde = { workspace = true, features = ["derive"], optional = true } diff --git a/crates/net/network-api/src/noop.rs b/crates/net/network-api/src/noop.rs index dc1ef17a93ca..2b453b4c4e7f 100644 --- a/crates/net/network-api/src/noop.rs +++ b/crates/net/network-api/src/noop.rs @@ -7,6 +7,7 @@ use crate::{ NetworkError, NetworkInfo, PeerKind, Peers, PeersInfo, Reputation, ReputationChangeKind, }; use async_trait::async_trait; +use reth_discv4::DEFAULT_DISCOVERY_PORT; use reth_eth_wire::{DisconnectReason, ProtocolVersion}; use reth_primitives::{Chain, NodeRecord, PeerId}; use reth_rpc_types::{EthProtocolInfo, NetworkStatus}; @@ -22,7 +23,7 @@ pub struct NoopNetwork; #[async_trait] impl NetworkInfo for NoopNetwork { fn local_addr(&self) -> SocketAddr { - (IpAddr::from(std::net::Ipv4Addr::UNSPECIFIED), 30303).into() + (IpAddr::from(std::net::Ipv4Addr::UNSPECIFIED), DEFAULT_DISCOVERY_PORT).into() } async fn network_status(&self) -> Result {