mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(net): create enr to peerid helper (#533)
* set network enr dev-dep to 0.7.0 instead of git - ethers and each other crate uses 0.7.0 and not git
This commit is contained in:
27
Cargo.lock
generated
27
Cargo.lock
generated
@ -1172,25 +1172,6 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enr"
|
||||
version = "0.7.0"
|
||||
source = "git+https://github.com/sigp/enr#e59dcb45ea07e423a7091d2a6ede4ad6d8ef2840"
|
||||
dependencies = [
|
||||
"base64 0.13.1",
|
||||
"bs58",
|
||||
"bytes",
|
||||
"hex",
|
||||
"k256",
|
||||
"log",
|
||||
"rand 0.8.5",
|
||||
"rlp",
|
||||
"secp256k1",
|
||||
"serde",
|
||||
"sha3",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enum-as-inner"
|
||||
version = "0.3.4"
|
||||
@ -1319,7 +1300,7 @@ dependencies = [
|
||||
"async-trait",
|
||||
"auto_impl",
|
||||
"base64 0.20.0",
|
||||
"enr 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"enr 0.7.0",
|
||||
"ethers-core",
|
||||
"futures-core",
|
||||
"futures-timer",
|
||||
@ -3405,7 +3386,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"discv5",
|
||||
"enr 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"enr 0.7.0",
|
||||
"generic-array",
|
||||
"hex",
|
||||
"public-ip",
|
||||
@ -3613,7 +3594,7 @@ dependencies = [
|
||||
"async-trait",
|
||||
"bytes",
|
||||
"either",
|
||||
"enr 0.7.0 (git+https://github.com/sigp/enr)",
|
||||
"enr 0.7.0",
|
||||
"ethers-core",
|
||||
"ethers-providers",
|
||||
"fnv",
|
||||
@ -3709,7 +3690,7 @@ dependencies = [
|
||||
"auto_impl",
|
||||
"bytes",
|
||||
"criterion",
|
||||
"enr 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"enr 0.7.0",
|
||||
"ethereum-types",
|
||||
"ethnum",
|
||||
"hex-literal",
|
||||
|
||||
@ -54,7 +54,7 @@ reth-tracing = { path = "../../tracing" }
|
||||
ethers-core = { git = "https://github.com/gakonst/ethers-rs", default-features = false }
|
||||
ethers-providers = { git = "https://github.com/gakonst/ethers-rs", default-features = false }
|
||||
|
||||
enr = { git = "https://github.com/sigp/enr", features = ["serde", "rust-secp256k1"] }
|
||||
enr = { version = "0.7.0", features = ["serde", "rust-secp256k1"] }
|
||||
|
||||
# misc
|
||||
hex = "0.4"
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
use crate::NetworkEventStream;
|
||||
|
||||
use super::testnet::Testnet;
|
||||
use enr::EnrPublicKey;
|
||||
use enr::{k256::ecdsa::SigningKey, Enr, EnrPublicKey};
|
||||
use ethers_core::utils::Geth;
|
||||
use ethers_providers::{Http, Middleware, Provider};
|
||||
use futures::StreamExt;
|
||||
@ -19,6 +19,14 @@ use tokio::task;
|
||||
// The timeout for tests that create a GethInstance
|
||||
const GETH_TIMEOUT: Duration = Duration::from_secs(60);
|
||||
|
||||
/// Obtains a PeerId from an ENR. In this case, the PeerId represents the public key contained in
|
||||
/// the ENR.
|
||||
fn enr_to_peer_id(enr: Enr<SigningKey>) -> PeerId {
|
||||
// In the following tests, methods which accept a public key expect it to contain the public
|
||||
// key in its 64-byte encoded (uncompressed) form.
|
||||
enr.public_key().encode_uncompressed().into()
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_establish_connections() {
|
||||
reth_tracing::init_tracing();
|
||||
@ -141,8 +149,7 @@ async fn test_incoming_node_id_blacklist() {
|
||||
let provider = Provider::<Http>::try_from(format!("http://{geth_endpoint}")).unwrap();
|
||||
|
||||
// get the peer id we should be expecting
|
||||
let geth_peer_id: PeerId =
|
||||
provider.node_info().await.unwrap().enr.public_key().encode_uncompressed().into();
|
||||
let geth_peer_id = enr_to_peer_id(provider.node_info().await.unwrap().enr);
|
||||
|
||||
let ban_list = BanList::new(vec![geth_peer_id], HashSet::new());
|
||||
let peer_config = PeersConfig::default().with_ban_list(ban_list);
|
||||
@ -195,8 +202,7 @@ async fn test_incoming_connect_with_single_geth() {
|
||||
let provider = Provider::<Http>::try_from(format!("http://{geth_endpoint}")).unwrap();
|
||||
|
||||
// get the peer id we should be expecting
|
||||
let geth_peer_id: PeerId =
|
||||
provider.node_info().await.unwrap().enr.public_key().encode_uncompressed().into();
|
||||
let geth_peer_id = enr_to_peer_id(provider.node_info().await.unwrap().enr);
|
||||
|
||||
let reth_p2p_socket = SocketAddr::new([127, 0, 0, 1].into(), 30305);
|
||||
let reth_disc_socket = SocketAddr::new([127, 0, 0, 1].into(), 30306);
|
||||
|
||||
Reference in New Issue
Block a user