Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/net/downloaders/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
3 changes: 1 addition & 2 deletions crates/net/eth-wire/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions crates/net/eth-wire/src/ethstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)),
};

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

Expand Down
24 changes: 14 additions & 10 deletions crates/net/eth-wire/src/hello.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -29,6 +33,8 @@ pub struct HelloMessageWithProtocols {
/// The list of supported capabilities and their versions.
pub protocols: Vec<Protocol>,
/// 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,
Expand Down Expand Up @@ -200,22 +206,20 @@ 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,
}
}
}

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

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

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

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