chore(deps): rm discv4 dep from eth-wire (#9344)

This commit is contained in:
Matthias Seitz
2024-07-06 19:51:38 +02:00
committed by GitHub
parent 98b755b98a
commit b94d8324cf
6 changed files with 22 additions and 20 deletions

View File

@ -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

View File

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

View File

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

View File

@ -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)