Skip to content

Commit

Permalink
chore: use DEFAULT_DISCOVERY_PORT constant (paradigmxyz#4356)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatStiles authored Aug 25, 2023
1 parent 50ba828 commit 6d0b00a
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/net/discv4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions crates/net/discv4/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions crates/net/eth-wire/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ reth-rlp = { workspace = true, features = [
"ethereum-types",
"smol_str",
] }
reth-discv4 = {path = "../discv4" }

# metrics
reth-metrics.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion crates/net/eth-wire/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
},
}
Expand Down
5 changes: 3 additions & 2 deletions crates/net/eth-wire/src/ethstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)),
};

Expand Down Expand Up @@ -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)),
};

Expand Down
10 changes: 6 additions & 4 deletions crates/net/eth-wire/src/hello.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -99,14 +100,15 @@ 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,
}
}
}

#[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};
Expand All @@ -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,
});

Expand All @@ -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,
});

Expand All @@ -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,
});

Expand Down
3 changes: 2 additions & 1 deletion crates/net/eth-wire/src/p2pstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions crates/net/network-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 2 additions & 1 deletion crates/net/network-api/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<NetworkStatus, NetworkError> {
Expand Down

0 comments on commit 6d0b00a

Please sign in to comment.