From 24d1c40f1778b89713fb87f725a7035d560fe0ee Mon Sep 17 00:00:00 2001 From: Age Manning Date: Thu, 6 Aug 2020 12:33:02 +1000 Subject: [PATCH 1/9] Ensure disconnects --- beacon_node/eth2_libp2p/src/behaviour/handler/mod.rs | 7 +++---- beacon_node/eth2_libp2p/src/behaviour/mod.rs | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/beacon_node/eth2_libp2p/src/behaviour/handler/mod.rs b/beacon_node/eth2_libp2p/src/behaviour/handler/mod.rs index f74040d91a5..89a86a68411 100644 --- a/beacon_node/eth2_libp2p/src/behaviour/handler/mod.rs +++ b/beacon_node/eth2_libp2p/src/behaviour/handler/mod.rs @@ -77,7 +77,7 @@ impl ProtocolsHandler for BehaviourHandler { fn inject_event(&mut self, event: Self::InEvent) { match event { BehaviourHandlerIn::Delegate(delegated_ev) => self.delegate.inject_event(delegated_ev), - /* Events comming from the behaviour */ + /* Events coming from the behaviour */ BehaviourHandlerIn::Shutdown(last_message) => { self.shutting_down = true; self.delegate.rpc_mut().shutdown(last_message); @@ -113,10 +113,9 @@ impl ProtocolsHandler for BehaviourHandler { >, > { // Disconnect if the sub-handlers are ready. + // Currently we only respect the RPC handler. if self.shutting_down { - let rpc_keep_alive = self.delegate.rpc().connection_keep_alive(); - let identify_keep_alive = self.delegate.identify().connection_keep_alive(); - if KeepAlive::No == rpc_keep_alive.max(identify_keep_alive) { + if KeepAlive::No == self.delegate.rpc().connection_keep_alive() { return Poll::Ready(ProtocolsHandlerEvent::Close(DelegateError::Disconnected)); } } diff --git a/beacon_node/eth2_libp2p/src/behaviour/mod.rs b/beacon_node/eth2_libp2p/src/behaviour/mod.rs index adf391e0c80..336562f5925 100644 --- a/beacon_node/eth2_libp2p/src/behaviour/mod.rs +++ b/beacon_node/eth2_libp2p/src/behaviour/mod.rs @@ -741,6 +741,7 @@ impl NetworkBehaviour for Behaviour { }; if goodbye_reason.is_some() { + debug!(self.log, "Disconnecting newly connected peer"; "peer_id" => peer_id.to_string(), "reason" => goodbye_reason.as_ref().expect("Is some").to_string()); self.peers_to_dc .push_back((peer_id.clone(), goodbye_reason)); return; From 264d625310f0c10153f654d9bd4e081c1b25b25a Mon Sep 17 00:00:00 2001 From: Age Manning Date: Thu, 6 Aug 2020 12:40:10 +1000 Subject: [PATCH 2/9] Deactivated state forces disconnect --- beacon_node/eth2_libp2p/src/rpc/handler.rs | 23 +++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/beacon_node/eth2_libp2p/src/rpc/handler.rs b/beacon_node/eth2_libp2p/src/rpc/handler.rs index 4ea412a5021..9492942d7f5 100644 --- a/beacon_node/eth2_libp2p/src/rpc/handler.rs +++ b/beacon_node/eth2_libp2p/src/rpc/handler.rs @@ -348,15 +348,20 @@ where // Check that we don't have outbound items pending for dialing, nor dialing, nor // established. Also check that there are no established inbound substreams. // Errors and events need to be reported back, so check those too. - let should_shutdown = if let HandlerState::ShuttingDown(_) = self.state { - self.dial_queue.is_empty() - && self.outbound_substreams.is_empty() - && self.inbound_substreams.is_empty() - && self.pending_errors.is_empty() - && self.events_out.is_empty() - && self.dial_negotiated == 0 - } else { - false + let should_shutdown = match self.state { + HandlerState::ShuttingDown(_) => { + self.dial_queue.is_empty() + && self.outbound_substreams.is_empty() + && self.inbound_substreams.is_empty() + && self.pending_errors.is_empty() + && self.events_out.is_empty() + && self.dial_negotiated == 0 + } + HandlerState::Deactivated => { + // Regardless of events, the timeout has expired. Force the disconnect. + true + } + _ => false, }; match self.keep_alive { From a12e7337cc91c5327923fd9e3ea8f0d93e806777 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Fri, 7 Aug 2020 11:54:44 +1000 Subject: [PATCH 3/9] Update libp2p --- Cargo.lock | 161 ++++++++++------------------- beacon_node/eth2_libp2p/Cargo.toml | 6 +- 2 files changed, 59 insertions(+), 108 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bbd0d4c9acf..348ddce8255 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -379,7 +379,7 @@ dependencies = [ "lazy_static", "lighthouse_metrics", "log 0.4.11", - "lru", + "lru 0.5.3", "merkle_proof", "operation_pool", "parking_lot 0.11.0", @@ -1260,7 +1260,7 @@ dependencies = [ "hex 0.4.2", "hkdf", "lazy_static", - "libp2p-core 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core", "libsecp256k1", "log 0.4.11", "lru_time_cache", @@ -1547,7 +1547,7 @@ dependencies = [ "libp2p", "lighthouse_metrics", "lighthouse_version", - "lru", + "lru 0.5.3", "parking_lot 0.11.0", "rand 0.7.3", "serde", @@ -2191,12 +2191,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" -[[package]] -name = "hex_fmt" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b07f60793ff0a4d9cef0f18e63b5357e06209987153a64648c972c1e5aff336f" - [[package]] name = "hkdf" version = "0.8.0" @@ -2576,7 +2570,7 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" [[package]] name = "lcli" -version = "0.2.0" +version = "0.2.1" dependencies = [ "bls", "clap", @@ -2659,14 +2653,15 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" [[package]] name = "libp2p" -version = "0.22.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1ebb6c031584a5af181fe3a1e4b074af5d0b1a3b31663200f0251f4bcff6b5c" dependencies = [ "atomic", "bytes 0.5.6", "futures 0.3.5", "lazy_static", - "libp2p-core 0.20.1 (git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16)", + "libp2p-core", "libp2p-core-derive", "libp2p-dns", "libp2p-gossipsub", @@ -2679,46 +2674,13 @@ dependencies = [ "libp2p-websocket", "libp2p-yamux", "multihash", - "parity-multiaddr 0.9.1 (git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16)", + "parity-multiaddr", "parking_lot 0.10.2", "pin-project", "smallvec 1.4.1", "wasm-timer", ] -[[package]] -name = "libp2p-core" -version = "0.20.1" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" -dependencies = [ - "asn1_der", - "bs58", - "ed25519-dalek", - "either", - "fnv", - "futures 0.3.5", - "futures-timer", - "lazy_static", - "libsecp256k1", - "log 0.4.11", - "multihash", - "multistream-select 0.8.2 (git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16)", - "parity-multiaddr 0.9.1 (git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16)", - "parking_lot 0.10.2", - "pin-project", - "prost", - "prost-build", - "rand 0.7.3", - "ring", - "rw-stream-sink", - "sha2 0.8.2", - "smallvec 1.4.1", - "thiserror", - "unsigned-varint 0.4.0", - "void", - "zeroize", -] - [[package]] name = "libp2p-core" version = "0.20.1" @@ -2736,8 +2698,8 @@ dependencies = [ "libsecp256k1", "log 0.4.11", "multihash", - "multistream-select 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "multistream-select", + "parity-multiaddr", "parking_lot 0.10.2", "pin-project", "prost", @@ -2756,7 +2718,8 @@ dependencies = [ [[package]] name = "libp2p-core-derive" version = "0.20.2" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f753d9324cd3ec14bf04b8a8cd0d269c87f294153d6bf2a84497a63a5ad22213" dependencies = [ "quote", "syn", @@ -2765,17 +2728,19 @@ dependencies = [ [[package]] name = "libp2p-dns" version = "0.20.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f751924b6b98e350005e0b87a822beb246792a3fb878c684e088f866158120ac" dependencies = [ "futures 0.3.5", - "libp2p-core 0.20.1 (git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16)", + "libp2p-core", "log 0.4.11", ] [[package]] name = "libp2p-gossipsub" version = "0.20.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a70f76b6c53ae9c97c234498c799802e43f91766bcf4a2a1f94f9339617d713b" dependencies = [ "base64 0.11.0", "byteorder", @@ -2783,11 +2748,10 @@ dependencies = [ "fnv", "futures 0.3.5", "futures_codec", - "hex_fmt", - "libp2p-core 0.20.1 (git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16)", + "libp2p-core", "libp2p-swarm", "log 0.4.11", - "lru_time_cache", + "lru 0.4.3", "prost", "prost-build", "rand 0.7.3", @@ -2800,10 +2764,11 @@ dependencies = [ [[package]] name = "libp2p-identify" version = "0.20.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "912c00a7bf67e0e765daf0cc37e08f675ea26aba3d6d1fbfaee81f19a4c23049" dependencies = [ "futures 0.3.5", - "libp2p-core 0.20.1 (git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16)", + "libp2p-core", "libp2p-swarm", "log 0.4.11", "prost", @@ -2815,13 +2780,14 @@ dependencies = [ [[package]] name = "libp2p-mplex" version = "0.20.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14ae0ffacd30f073f96cd518b2c9cd2cb18ac27c3d136a4b23cf1af99f33e541" dependencies = [ "bytes 0.5.6", "fnv", "futures 0.3.5", "futures_codec", - "libp2p-core 0.20.1 (git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16)", + "libp2p-core", "log 0.4.11", "parking_lot 0.10.2", "unsigned-varint 0.4.0", @@ -2829,14 +2795,15 @@ dependencies = [ [[package]] name = "libp2p-noise" -version = "0.21.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e594f2de0c23c2b7ad14802c991a2e68e95315c6a6c7715e53801506f20135d" dependencies = [ "bytes 0.5.6", "curve25519-dalek", "futures 0.3.5", "lazy_static", - "libp2p-core 0.20.1 (git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16)", + "libp2p-core", "log 0.4.11", "prost", "prost-build", @@ -2851,7 +2818,8 @@ dependencies = [ [[package]] name = "libp2p-secio" version = "0.20.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ff43513c383f7cdab2736eb98465fc4c5dd5d1988df89749dc8a68950349d56" dependencies = [ "aes-ctr 0.3.0", "ctr 0.3.2", @@ -2859,7 +2827,7 @@ dependencies = [ "hmac 0.7.1", "js-sys", "lazy_static", - "libp2p-core 0.20.1 (git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16)", + "libp2p-core", "log 0.4.11", "parity-send-wrapper", "pin-project", @@ -2880,10 +2848,11 @@ dependencies = [ [[package]] name = "libp2p-swarm" version = "0.20.1" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f88d5e2a090a2aadf042cd33484e2f015c6dab212567406a59deece5dedbd133" dependencies = [ "futures 0.3.5", - "libp2p-core 0.20.1 (git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16)", + "libp2p-core", "log 0.4.11", "rand 0.7.3", "smallvec 1.4.1", @@ -2894,13 +2863,14 @@ dependencies = [ [[package]] name = "libp2p-tcp" version = "0.20.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b1fa2bbad054020cb875546a577a66a65a5bf42eff55ed5265f92ffee3cc052" dependencies = [ "futures 0.3.5", "futures-timer", "get_if_addrs", "ipnet", - "libp2p-core 0.20.1 (git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16)", + "libp2p-core", "log 0.4.11", "socket2", "tokio 0.2.22", @@ -2909,12 +2879,13 @@ dependencies = [ [[package]] name = "libp2p-websocket" version = "0.21.1" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "046a5201f6e471f22b22b394e4d084269ed1e28cf7300f7b49874385db84c7bd" dependencies = [ "async-tls", "either", "futures 0.3.5", - "libp2p-core 0.20.1 (git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16)", + "libp2p-core", "log 0.4.11", "quicksink", "rustls", @@ -2928,10 +2899,11 @@ dependencies = [ [[package]] name = "libp2p-yamux" version = "0.20.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46ae9bf2f7d8a4be9c7e9b61df9de9dc1bd66419d669098f22f81f8d9571029a" dependencies = [ "futures 0.3.5", - "libp2p-core 0.20.1 (git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16)", + "libp2p-core", "parking_lot 0.10.2", "thiserror", "yamux", @@ -2978,7 +2950,7 @@ dependencies = [ [[package]] name = "lighthouse" -version = "0.2.0" +version = "0.2.1" dependencies = [ "account_manager", "account_utils", @@ -3072,6 +3044,15 @@ dependencies = [ "slog-term", ] +[[package]] +name = "lru" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0609345ddee5badacf857d4f547e0e5a2e987db77085c24cd887f73573a04237" +dependencies = [ + "hashbrown 0.6.3", +] + [[package]] name = "lru" version = "0.5.3" @@ -3293,19 +3274,6 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8883adfde9756c1d30b0f519c9b8c502a94b41ac62f696453c37c7fc0a958ce" -[[package]] -name = "multistream-select" -version = "0.8.2" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" -dependencies = [ - "bytes 0.5.6", - "futures 0.3.5", - "log 0.4.11", - "pin-project", - "smallvec 1.4.1", - "unsigned-varint 0.4.0", -] - [[package]] name = "multistream-select" version = "0.8.2" @@ -3581,23 +3549,6 @@ dependencies = [ "types", ] -[[package]] -name = "parity-multiaddr" -version = "0.9.1" -source = "git+https://github.com/sigp/rust-libp2p?rev=f1b660a1a96c1b6198cd62062e75d357893faf16#f1b660a1a96c1b6198cd62062e75d357893faf16" -dependencies = [ - "arrayref", - "bs58", - "byteorder", - "data-encoding", - "multihash", - "percent-encoding 2.1.0", - "serde", - "static_assertions", - "unsigned-varint 0.4.0", - "url 2.1.1", -] - [[package]] name = "parity-multiaddr" version = "0.9.1" @@ -5178,7 +5129,7 @@ dependencies = [ "lazy_static", "leveldb", "lighthouse_metrics", - "lru", + "lru 0.5.3", "parking_lot 0.11.0", "rayon", "serde", diff --git a/beacon_node/eth2_libp2p/Cargo.toml b/beacon_node/eth2_libp2p/Cargo.toml index b8d5646ec2f..358b1dce3ef 100644 --- a/beacon_node/eth2_libp2p/Cargo.toml +++ b/beacon_node/eth2_libp2p/Cargo.toml @@ -39,9 +39,9 @@ environment = { path = "../../lighthouse/environment" } rand = "0.7.3" [dependencies.libp2p] -#version = "0.19.1" -git = "https://github.com/sigp/rust-libp2p" -rev = "f1b660a1a96c1b6198cd62062e75d357893faf16" +version = "0.23.0" +#git = "https://github.com/sigp/rust-libp2p" +#rev = "f1b660a1a96c1b6198cd62062e75d357893faf16" default-features = false features = ["websocket", "identify", "mplex", "yamux", "noise", "gossipsub", "dns", "secio", "tcp-tokio"] From b3b01f0fb51047be96af16b57e10994f3665e38f Mon Sep 17 00:00:00 2001 From: Age Manning Date: Fri, 7 Aug 2020 12:20:51 +1000 Subject: [PATCH 4/9] Remove secio support --- Cargo.lock | 298 ++++++++++--------------- beacon_node/eth2_libp2p/Cargo.toml | 8 +- beacon_node/eth2_libp2p/src/service.rs | 62 ++--- 3 files changed, 137 insertions(+), 231 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 348ddce8255..178c562e3cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,33 +86,21 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7001367fde4c768a19d1029f0a8be5abd9308e1119846d5bd9ad26297b8faf5" dependencies = [ - "aes-soft 0.4.0", - "aesni 0.7.0", + "aes-soft", + "aesni", "block-cipher", ] -[[package]] -name = "aes-ctr" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2e5b0458ea3beae0d1d8c0f3946564f8e10f90646cf78c06b4351052058d1ee" -dependencies = [ - "aes-soft 0.3.3", - "aesni 0.6.0", - "ctr 0.3.2", - "stream-cipher 0.3.2", -] - [[package]] name = "aes-ctr" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92e60aeefd2a0243bd53a42e92444e039f67c3d7f0382c9813577696e7c10bf3" dependencies = [ - "aes-soft 0.4.0", - "aesni 0.7.0", - "ctr 0.4.0", - "stream-cipher 0.4.1", + "aes-soft", + "aesni", + "ctr", + "stream-cipher", ] [[package]] @@ -128,17 +116,6 @@ dependencies = [ "subtle 2.2.3", ] -[[package]] -name = "aes-soft" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfd7e7ae3f9a1fb5c03b389fc6bb9a51400d0c13053f0dca698c832bfd893a0d" -dependencies = [ - "block-cipher-trait", - "byteorder", - "opaque-debug 0.2.3", -] - [[package]] name = "aes-soft" version = "0.4.0" @@ -150,17 +127,6 @@ dependencies = [ "opaque-debug 0.2.3", ] -[[package]] -name = "aesni" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" -dependencies = [ - "block-cipher-trait", - "opaque-debug 0.2.3", - "stream-cipher 0.3.2", -] - [[package]] name = "aesni" version = "0.7.0" @@ -169,7 +135,7 @@ checksum = "d050d39b0b7688b3a3254394c3e30a9d66c41dcf9b05b0e2dbdc623f6505d264" dependencies = [ "block-cipher", "opaque-debug 0.2.3", - "stream-cipher 0.4.1", + "stream-cipher", ] [[package]] @@ -379,7 +345,7 @@ dependencies = [ "lazy_static", "lighthouse_metrics", "log 0.4.11", - "lru 0.5.3", + "lru", "merkle_proof", "operation_pool", "parking_lot 0.11.0", @@ -524,15 +490,6 @@ dependencies = [ "generic-array 0.14.3", ] -[[package]] -name = "block-cipher-trait" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" -dependencies = [ - "generic-array 0.12.3", -] - [[package]] name = "block-padding" version = "0.1.5" @@ -709,7 +666,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "086c0f07ac275808b7bf9a39f2fd013aae1498be83632814c8c4e0bd53f2dc58" dependencies = [ - "stream-cipher 0.4.1", + "stream-cipher", "zeroize", ] @@ -722,7 +679,7 @@ dependencies = [ "aead", "chacha20", "poly1305", - "stream-cipher 0.4.1", + "stream-cipher", "zeroize", ] @@ -1080,23 +1037,13 @@ dependencies = [ "memchr", ] -[[package]] -name = "ctr" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "022cd691704491df67d25d006fe8eca083098253c4d43516c2206479c58c6736" -dependencies = [ - "block-cipher-trait", - "stream-cipher 0.3.2", -] - [[package]] name = "ctr" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3592740fd55aaf61dd72df96756bd0d11e6037b89dcf30ae2e1895b267692be" dependencies = [ - "stream-cipher 0.4.1", + "stream-cipher", ] [[package]] @@ -1260,7 +1207,7 @@ dependencies = [ "hex 0.4.2", "hkdf", "lazy_static", - "libp2p-core", + "libp2p-core 0.20.1", "libsecp256k1", "log 0.4.11", "lru_time_cache", @@ -1508,7 +1455,7 @@ dependencies = [ name = "eth2_keystore" version = "0.1.0" dependencies = [ - "aes-ctr 0.4.0", + "aes-ctr", "bls", "eth2_key_derivation", "eth2_ssz", @@ -1547,7 +1494,7 @@ dependencies = [ "libp2p", "lighthouse_metrics", "lighthouse_version", - "lru 0.5.3", + "lru", "parking_lot 0.11.0", "rand 0.7.3", "serde", @@ -2191,6 +2138,12 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" +[[package]] +name = "hex_fmt" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b07f60793ff0a4d9cef0f18e63b5357e06209987153a64648c972c1e5aff336f" + [[package]] name = "hkdf" version = "0.8.0" @@ -2654,27 +2607,25 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" [[package]] name = "libp2p" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1ebb6c031584a5af181fe3a1e4b074af5d0b1a3b31663200f0251f4bcff6b5c" +source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" dependencies = [ "atomic", "bytes 0.5.6", "futures 0.3.5", "lazy_static", - "libp2p-core", + "libp2p-core 0.21.0", "libp2p-core-derive", "libp2p-dns", "libp2p-gossipsub", "libp2p-identify", "libp2p-mplex", "libp2p-noise", - "libp2p-secio", "libp2p-swarm", "libp2p-tcp", "libp2p-websocket", "libp2p-yamux", "multihash", - "parity-multiaddr", + "parity-multiaddr 0.9.1 (git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef)", "parking_lot 0.10.2", "pin-project", "smallvec 1.4.1", @@ -2698,8 +2649,41 @@ dependencies = [ "libsecp256k1", "log 0.4.11", "multihash", - "multistream-select", - "parity-multiaddr", + "multistream-select 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.10.2", + "pin-project", + "prost", + "prost-build", + "rand 0.7.3", + "ring", + "rw-stream-sink", + "sha2 0.8.2", + "smallvec 1.4.1", + "thiserror", + "unsigned-varint 0.4.0", + "void", + "zeroize", +] + +[[package]] +name = "libp2p-core" +version = "0.21.0" +source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +dependencies = [ + "asn1_der", + "bs58", + "ed25519-dalek", + "either", + "fnv", + "futures 0.3.5", + "futures-timer", + "lazy_static", + "libsecp256k1", + "log 0.4.11", + "multihash", + "multistream-select 0.8.2 (git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef)", + "parity-multiaddr 0.9.1 (git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef)", "parking_lot 0.10.2", "pin-project", "prost", @@ -2718,8 +2702,7 @@ dependencies = [ [[package]] name = "libp2p-core-derive" version = "0.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f753d9324cd3ec14bf04b8a8cd0d269c87f294153d6bf2a84497a63a5ad22213" +source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" dependencies = [ "quote", "syn", @@ -2727,20 +2710,18 @@ dependencies = [ [[package]] name = "libp2p-dns" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f751924b6b98e350005e0b87a822beb246792a3fb878c684e088f866158120ac" +version = "0.21.0" +source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" dependencies = [ "futures 0.3.5", - "libp2p-core", + "libp2p-core 0.21.0", "log 0.4.11", ] [[package]] name = "libp2p-gossipsub" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a70f76b6c53ae9c97c234498c799802e43f91766bcf4a2a1f94f9339617d713b" +version = "0.21.0" +source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" dependencies = [ "base64 0.11.0", "byteorder", @@ -2748,10 +2729,11 @@ dependencies = [ "fnv", "futures 0.3.5", "futures_codec", - "libp2p-core", + "hex_fmt", + "libp2p-core 0.21.0", "libp2p-swarm", "log 0.4.11", - "lru 0.4.3", + "lru_time_cache", "prost", "prost-build", "rand 0.7.3", @@ -2763,12 +2745,11 @@ dependencies = [ [[package]] name = "libp2p-identify" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "912c00a7bf67e0e765daf0cc37e08f675ea26aba3d6d1fbfaee81f19a4c23049" +version = "0.21.0" +source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" dependencies = [ "futures 0.3.5", - "libp2p-core", + "libp2p-core 0.21.0", "libp2p-swarm", "log 0.4.11", "prost", @@ -2779,15 +2760,14 @@ dependencies = [ [[package]] name = "libp2p-mplex" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14ae0ffacd30f073f96cd518b2c9cd2cb18ac27c3d136a4b23cf1af99f33e541" +version = "0.21.0" +source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" dependencies = [ "bytes 0.5.6", "fnv", "futures 0.3.5", "futures_codec", - "libp2p-core", + "libp2p-core 0.21.0", "log 0.4.11", "parking_lot 0.10.2", "unsigned-varint 0.4.0", @@ -2795,15 +2775,14 @@ dependencies = [ [[package]] name = "libp2p-noise" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e594f2de0c23c2b7ad14802c991a2e68e95315c6a6c7715e53801506f20135d" +version = "0.23.0" +source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" dependencies = [ "bytes 0.5.6", "curve25519-dalek", "futures 0.3.5", "lazy_static", - "libp2p-core", + "libp2p-core 0.21.0", "log 0.4.11", "prost", "prost-build", @@ -2815,44 +2794,13 @@ dependencies = [ "zeroize", ] -[[package]] -name = "libp2p-secio" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ff43513c383f7cdab2736eb98465fc4c5dd5d1988df89749dc8a68950349d56" -dependencies = [ - "aes-ctr 0.3.0", - "ctr 0.3.2", - "futures 0.3.5", - "hmac 0.7.1", - "js-sys", - "lazy_static", - "libp2p-core", - "log 0.4.11", - "parity-send-wrapper", - "pin-project", - "prost", - "prost-build", - "quicksink", - "rand 0.7.3", - "ring", - "rw-stream-sink", - "sha2 0.8.2", - "static_assertions", - "twofish", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - [[package]] name = "libp2p-swarm" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f88d5e2a090a2aadf042cd33484e2f015c6dab212567406a59deece5dedbd133" +version = "0.21.0" +source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" dependencies = [ "futures 0.3.5", - "libp2p-core", + "libp2p-core 0.21.0", "log 0.4.11", "rand 0.7.3", "smallvec 1.4.1", @@ -2862,15 +2810,14 @@ dependencies = [ [[package]] name = "libp2p-tcp" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b1fa2bbad054020cb875546a577a66a65a5bf42eff55ed5265f92ffee3cc052" +version = "0.21.0" +source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" dependencies = [ "futures 0.3.5", "futures-timer", "get_if_addrs", "ipnet", - "libp2p-core", + "libp2p-core 0.21.0", "log 0.4.11", "socket2", "tokio 0.2.22", @@ -2878,14 +2825,13 @@ dependencies = [ [[package]] name = "libp2p-websocket" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046a5201f6e471f22b22b394e4d084269ed1e28cf7300f7b49874385db84c7bd" +version = "0.22.0" +source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" dependencies = [ "async-tls", "either", "futures 0.3.5", - "libp2p-core", + "libp2p-core 0.21.0", "log 0.4.11", "quicksink", "rustls", @@ -2898,12 +2844,11 @@ dependencies = [ [[package]] name = "libp2p-yamux" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46ae9bf2f7d8a4be9c7e9b61df9de9dc1bd66419d669098f22f81f8d9571029a" +version = "0.21.0" +source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" dependencies = [ "futures 0.3.5", - "libp2p-core", + "libp2p-core 0.21.0", "parking_lot 0.10.2", "thiserror", "yamux", @@ -3044,15 +2989,6 @@ dependencies = [ "slog-term", ] -[[package]] -name = "lru" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0609345ddee5badacf857d4f547e0e5a2e987db77085c24cd887f73573a04237" -dependencies = [ - "hashbrown 0.6.3", -] - [[package]] name = "lru" version = "0.5.3" @@ -3274,6 +3210,19 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8883adfde9756c1d30b0f519c9b8c502a94b41ac62f696453c37c7fc0a958ce" +[[package]] +name = "multistream-select" +version = "0.8.2" +source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +dependencies = [ + "bytes 0.5.6", + "futures 0.3.5", + "log 0.4.11", + "pin-project", + "smallvec 1.4.1", + "unsigned-varint 0.4.0", +] + [[package]] name = "multistream-select" version = "0.8.2" @@ -3549,6 +3498,23 @@ dependencies = [ "types", ] +[[package]] +name = "parity-multiaddr" +version = "0.9.1" +source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +dependencies = [ + "arrayref", + "bs58", + "byteorder", + "data-encoding", + "multihash", + "percent-encoding 2.1.0", + "serde", + "static_assertions", + "unsigned-varint 0.4.0", + "url 2.1.1", +] + [[package]] name = "parity-multiaddr" version = "0.9.1" @@ -3579,12 +3545,6 @@ dependencies = [ "serde", ] -[[package]] -name = "parity-send-wrapper" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa9777aa91b8ad9dd5aaa04a9b6bcb02c7f1deb952fca5a66034d5e63afc5c6f" - [[package]] name = "parking_lot" version = "0.9.0" @@ -5129,7 +5089,7 @@ dependencies = [ "lazy_static", "leveldb", "lighthouse_metrics", - "lru 0.5.3", + "lru", "parking_lot 0.11.0", "rayon", "serde", @@ -5142,15 +5102,6 @@ dependencies = [ "types", ] -[[package]] -name = "stream-cipher" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8131256a5896cabcf5eb04f4d6dacbe1aefda854b0d9896e09cb58829ec5638c" -dependencies = [ - "generic-array 0.12.3", -] - [[package]] name = "stream-cipher" version = "0.4.1" @@ -5850,17 +5801,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" -[[package]] -name = "twofish" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712d261e83e727c8e2dbb75dacac67c36e35db36a958ee504f2164fc052434e1" -dependencies = [ - "block-cipher-trait", - "byteorder", - "opaque-debug 0.2.3", -] - [[package]] name = "typeable" version = "0.1.2" diff --git a/beacon_node/eth2_libp2p/Cargo.toml b/beacon_node/eth2_libp2p/Cargo.toml index 358b1dce3ef..434e99ed912 100644 --- a/beacon_node/eth2_libp2p/Cargo.toml +++ b/beacon_node/eth2_libp2p/Cargo.toml @@ -39,11 +39,11 @@ environment = { path = "../../lighthouse/environment" } rand = "0.7.3" [dependencies.libp2p] -version = "0.23.0" -#git = "https://github.com/sigp/rust-libp2p" -#rev = "f1b660a1a96c1b6198cd62062e75d357893faf16" +#version = "0.23.0" +git = "https://github.com/sigp/rust-libp2p" +rev = "5139ec3ace4ad52506f217d790f0a9425274caef" default-features = false -features = ["websocket", "identify", "mplex", "yamux", "noise", "gossipsub", "dns", "secio", "tcp-tokio"] +features = ["websocket", "identify", "mplex", "yamux", "noise", "gossipsub", "dns", "tcp-tokio"] [dev-dependencies] tokio = { version = "0.2.21", features = ["full"] } diff --git a/beacon_node/eth2_libp2p/src/service.rs b/beacon_node/eth2_libp2p/src/service.rs index 363e740c7a8..aac23385725 100644 --- a/beacon_node/eth2_libp2p/src/service.rs +++ b/beacon_node/eth2_libp2p/src/service.rs @@ -7,14 +7,10 @@ use crate::EnrExt; use crate::{NetworkConfig, NetworkGlobals, PeerAction}; use futures::prelude::*; use libp2p::core::{ - identity::Keypair, - multiaddr::Multiaddr, - muxing::StreamMuxerBox, - transport::boxed::Boxed, - upgrade::{InboundUpgradeExt, OutboundUpgradeExt}, + identity::Keypair, multiaddr::Multiaddr, muxing::StreamMuxerBox, transport::boxed::Boxed, }; use libp2p::{ - core, noise, secio, + core, noise, swarm::{SwarmBuilder, SwarmEvent}, PeerId, Swarm, Transport, }; @@ -239,7 +235,7 @@ impl Service { endpoint: _, num_established, } => { - debug!(self.log, "Connection closed"; "peer_id"=> peer_id.to_string(), "cause" => cause.to_string(), "connections" => num_established); + debug!(self.log, "Connection closed"; "peer_id"=> peer_id.to_string(), "cause" => format!("{:?}", cause), "connections" => num_established); } SwarmEvent::NewListenAddr(multiaddr) => { return Libp2pEvent::NewListenAddr(multiaddr) @@ -290,7 +286,6 @@ impl Service { /// The implementation supports TCP/IP, WebSockets over TCP/IP, noise as the encryption layer, and /// yamux or mplex as the multiplexing layer. - fn build_transport( local_private_key: Keypair, ) -> Result, Error> { @@ -302,47 +297,18 @@ fn build_transport( transport.or_transport(libp2p::websocket::WsConfig::new(trans_clone)) }; // Authentication - let transport = transport - .and_then(move |stream, endpoint| { - let upgrade = core::upgrade::SelectUpgrade::new( - secio::SecioConfig::new(local_private_key.clone()), - generate_noise_config(&local_private_key), - ); - core::upgrade::apply(stream, upgrade, endpoint, core::upgrade::Version::V1).and_then( - |out| async move { - match out { - // Secio was negotiated - core::either::EitherOutput::First((remote_id, out)) => { - Ok((core::either::EitherOutput::First(out), remote_id)) - } - // Noise was negotiated - core::either::EitherOutput::Second((remote_id, out)) => { - Ok((core::either::EitherOutput::Second(out), remote_id)) - } - } - }, - ) - }) - .timeout(Duration::from_secs(20)); - - // Multiplexing - let transport = transport - .and_then(move |(stream, peer_id), endpoint| { - let peer_id2 = peer_id.clone(); - let upgrade = core::upgrade::SelectUpgrade::new( - libp2p::mplex::MplexConfig::new(), - libp2p::yamux::Config::default(), - ) - .map_inbound(move |muxer| (peer_id, muxer)) - .map_outbound(move |muxer| (peer_id2, muxer)); - - core::upgrade::apply(stream, upgrade, endpoint, core::upgrade::Version::V1) - .map_ok(|(id, muxer)| (id, core::muxing::StreamMuxerBox::new(muxer))) - }) - .timeout(Duration::from_secs(20)) + Ok(transport + .upgrade(core::upgrade::Version::V1) + .authenticate(generate_noise_config(&local_private_key)) + .multiplex(core::upgrade::SelectUpgrade::new( + libp2p::mplex::MplexConfig::new(), + libp2p::yamux::Config::default(), + )) + .map(|(peer, muxer), _| (peer, core::muxing::StreamMuxerBox::new(muxer))) + .timeout(Duration::from_secs(10)) + .timeout(Duration::from_secs(10)) .map_err(|err| Error::new(ErrorKind::Other, err)) - .boxed(); - Ok(transport) + .boxed()) } // Useful helper functions for debugging. Currently not used in the client. From 8e082ad6d665dff497d9a8319c37bbf04cc029a2 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Fri, 7 Aug 2020 19:30:39 +1000 Subject: [PATCH 5/9] Update to latest network corrections --- beacon_node/eth2_libp2p/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon_node/eth2_libp2p/Cargo.toml b/beacon_node/eth2_libp2p/Cargo.toml index 434e99ed912..c37a9d6ef11 100644 --- a/beacon_node/eth2_libp2p/Cargo.toml +++ b/beacon_node/eth2_libp2p/Cargo.toml @@ -41,7 +41,7 @@ rand = "0.7.3" [dependencies.libp2p] #version = "0.23.0" git = "https://github.com/sigp/rust-libp2p" -rev = "5139ec3ace4ad52506f217d790f0a9425274caef" +rev = "3096cb6b89b2883a79ce5ffcb03d41778a09b695" default-features = false features = ["websocket", "identify", "mplex", "yamux", "noise", "gossipsub", "dns", "tcp-tokio"] From 118a1edfad4650204077fbc3398e980ca2a43a96 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Sat, 8 Aug 2020 12:29:58 +1000 Subject: [PATCH 6/9] Update behaviour injection logic --- Cargo.lock | 4 +-- .../src/behaviour/handler/delegate.rs | 2 +- beacon_node/eth2_libp2p/src/behaviour/mod.rs | 34 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bbd0d4c9acf..da63c3ce255 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2576,7 +2576,7 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" [[package]] name = "lcli" -version = "0.2.0" +version = "0.2.1" dependencies = [ "bls", "clap", @@ -2978,7 +2978,7 @@ dependencies = [ [[package]] name = "lighthouse" -version = "0.2.0" +version = "0.2.1" dependencies = [ "account_manager", "account_utils", diff --git a/beacon_node/eth2_libp2p/src/behaviour/handler/delegate.rs b/beacon_node/eth2_libp2p/src/behaviour/handler/delegate.rs index 03a2a08a733..ae1bcd05c36 100644 --- a/beacon_node/eth2_libp2p/src/behaviour/handler/delegate.rs +++ b/beacon_node/eth2_libp2p/src/behaviour/handler/delegate.rs @@ -49,7 +49,7 @@ impl DelegatingHandler { } /// Gives access to identify's handler. - pub fn identify(&self) -> &IdentifyHandler { + pub fn _identify(&self) -> &IdentifyHandler { &self.identify_handler } } diff --git a/beacon_node/eth2_libp2p/src/behaviour/mod.rs b/beacon_node/eth2_libp2p/src/behaviour/mod.rs index 336562f5925..5b25db85431 100644 --- a/beacon_node/eth2_libp2p/src/behaviour/mod.rs +++ b/beacon_node/eth2_libp2p/src/behaviour/mod.rs @@ -694,15 +694,28 @@ impl NetworkBehaviour for Behaviour { conn_id: &ConnectionId, endpoint: &ConnectedPoint, ) { + // If the peer manager (and therefore the behaviour's believe this peer connected, inform + // about the disconnection. + if !self.network_globals.peers.read().is_connected(&peer_id) { + return; + } delegate_to_behaviours!(self, inject_connection_closed, peer_id, conn_id, endpoint); } // This gets called once there are no more active connections. fn inject_disconnected(&mut self, peer_id: &PeerId) { + // If the application/behaviour layers thinks this peer has connected inform it of the disconnect. + if !self.network_globals.peers.read().is_connected(&peer_id) { + // Inform the application. + self.add_event(BehaviourEvent::PeerDisconnected(peer_id.clone())); + // Inform the behaviour. + delegate_to_behaviours!(self, inject_disconnected, peer_id); + } // Inform the peer manager. + // NOTE: It may be the case that a rejected node, due to too many peers is disconnected + // here and the peer manager has no knowledge of its connection. We insert it here for + // reference so that peer manager can track this peer. self.peer_manager.notify_disconnect(&peer_id); - // Inform the application. - self.add_event(BehaviourEvent::PeerDisconnected(peer_id.clone())); // Update the prometheus metrics metrics::inc_counter(&metrics::PEER_DISCONNECT_EVENT_COUNT); @@ -710,9 +723,6 @@ impl NetworkBehaviour for Behaviour { &metrics::PEERS_CONNECTED, self.network_globals.connected_peers() as i64, ); - - // Inform the behaviour. - delegate_to_behaviours!(self, inject_disconnected, peer_id); } // This gets called every time a connection is established. @@ -772,18 +782,8 @@ impl NetworkBehaviour for Behaviour { // This gets called on the initial connection establishment. fn inject_connected(&mut self, peer_id: &PeerId) { - // Drop any connection from a banned peer. The goodbye and disconnects are handled in - // `inject_connection_established()`, which gets called first. - // The same holds if we reached the peer limit and the connected peer has no future duty. - if self.peer_manager.is_banned(peer_id) - || (self.peer_manager.peer_limit_reached() - && self - .network_globals - .peers - .read() - .peer_info(peer_id) - .map_or(true, |i| !i.has_future_duty())) - { + // If the PeerManager has connected this peer, inform the behaviours + if !self.network_globals.peers.read().is_connected(&peer_id) { return; } From d35b147f7546b7ce9275c1c8d37985682b2cc2eb Mon Sep 17 00:00:00 2001 From: Age Manning Date: Sat, 8 Aug 2020 12:50:22 +1000 Subject: [PATCH 7/9] Fix inject disconnected --- beacon_node/eth2_libp2p/src/behaviour/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/beacon_node/eth2_libp2p/src/behaviour/mod.rs b/beacon_node/eth2_libp2p/src/behaviour/mod.rs index 5b25db85431..8d8df58f922 100644 --- a/beacon_node/eth2_libp2p/src/behaviour/mod.rs +++ b/beacon_node/eth2_libp2p/src/behaviour/mod.rs @@ -694,9 +694,9 @@ impl NetworkBehaviour for Behaviour { conn_id: &ConnectionId, endpoint: &ConnectedPoint, ) { - // If the peer manager (and therefore the behaviour's believe this peer connected, inform + // If the peer manager (and therefore the behaviour's) believe this peer connected, inform // about the disconnection. - if !self.network_globals.peers.read().is_connected(&peer_id) { + if self.network_globals.peers.read().is_connected(&peer_id) { return; } delegate_to_behaviours!(self, inject_connection_closed, peer_id, conn_id, endpoint); @@ -705,7 +705,7 @@ impl NetworkBehaviour for Behaviour { // This gets called once there are no more active connections. fn inject_disconnected(&mut self, peer_id: &PeerId) { // If the application/behaviour layers thinks this peer has connected inform it of the disconnect. - if !self.network_globals.peers.read().is_connected(&peer_id) { + if self.network_globals.peers.read().is_connected(&peer_id) { // Inform the application. self.add_event(BehaviourEvent::PeerDisconnected(peer_id.clone())); // Inform the behaviour. From 957ebe272bfbbcc60f013b37d6f0d83279d7f903 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Sat, 8 Aug 2020 14:05:51 +1000 Subject: [PATCH 8/9] Update clippy lint --- beacon_node/eth2_libp2p/src/behaviour/handler/mod.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/beacon_node/eth2_libp2p/src/behaviour/handler/mod.rs b/beacon_node/eth2_libp2p/src/behaviour/handler/mod.rs index 89a86a68411..76169504157 100644 --- a/beacon_node/eth2_libp2p/src/behaviour/handler/mod.rs +++ b/beacon_node/eth2_libp2p/src/behaviour/handler/mod.rs @@ -114,10 +114,8 @@ impl ProtocolsHandler for BehaviourHandler { > { // Disconnect if the sub-handlers are ready. // Currently we only respect the RPC handler. - if self.shutting_down { - if KeepAlive::No == self.delegate.rpc().connection_keep_alive() { - return Poll::Ready(ProtocolsHandlerEvent::Close(DelegateError::Disconnected)); - } + if self.shutting_down && KeepAlive::No == self.delegate.rpc().connection_keep_alive() { + return Poll::Ready(ProtocolsHandlerEvent::Close(DelegateError::Disconnected)); } match self.delegate.poll(cx) { From 2eb88e26d6123cc602979a5b6ddf81914f842425 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Sat, 8 Aug 2020 16:25:39 +1000 Subject: [PATCH 9/9] Update lock --- Cargo.lock | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 178c562e3cf..29eee0eeb60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -696,9 +696,9 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.1" +version = "2.33.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" +checksum = "10040cdf04294b565d9e0319955430099ec3813a64c952b86a41200ad714ae48" dependencies = [ "ansi_term", "atty", @@ -2394,9 +2394,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7" +checksum = "86b45e59b16c76b11bf9738fd5d38879d3bd28ad292d7b313608becb17ae2df9" dependencies = [ "autocfg 1.0.0", "hashbrown 0.8.1", @@ -2607,7 +2607,7 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" [[package]] name = "libp2p" version = "0.23.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +source = "git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695#3096cb6b89b2883a79ce5ffcb03d41778a09b695" dependencies = [ "atomic", "bytes 0.5.6", @@ -2625,7 +2625,7 @@ dependencies = [ "libp2p-websocket", "libp2p-yamux", "multihash", - "parity-multiaddr 0.9.1 (git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef)", + "parity-multiaddr 0.9.1 (git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695)", "parking_lot 0.10.2", "pin-project", "smallvec 1.4.1", @@ -2669,7 +2669,7 @@ dependencies = [ [[package]] name = "libp2p-core" version = "0.21.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +source = "git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695#3096cb6b89b2883a79ce5ffcb03d41778a09b695" dependencies = [ "asn1_der", "bs58", @@ -2682,8 +2682,8 @@ dependencies = [ "libsecp256k1", "log 0.4.11", "multihash", - "multistream-select 0.8.2 (git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef)", - "parity-multiaddr 0.9.1 (git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef)", + "multistream-select 0.8.2 (git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695)", + "parity-multiaddr 0.9.1 (git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695)", "parking_lot 0.10.2", "pin-project", "prost", @@ -2702,7 +2702,7 @@ dependencies = [ [[package]] name = "libp2p-core-derive" version = "0.20.2" -source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +source = "git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695#3096cb6b89b2883a79ce5ffcb03d41778a09b695" dependencies = [ "quote", "syn", @@ -2711,7 +2711,7 @@ dependencies = [ [[package]] name = "libp2p-dns" version = "0.21.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +source = "git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695#3096cb6b89b2883a79ce5ffcb03d41778a09b695" dependencies = [ "futures 0.3.5", "libp2p-core 0.21.0", @@ -2721,7 +2721,7 @@ dependencies = [ [[package]] name = "libp2p-gossipsub" version = "0.21.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +source = "git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695#3096cb6b89b2883a79ce5ffcb03d41778a09b695" dependencies = [ "base64 0.11.0", "byteorder", @@ -2733,7 +2733,6 @@ dependencies = [ "libp2p-core 0.21.0", "libp2p-swarm", "log 0.4.11", - "lru_time_cache", "prost", "prost-build", "rand 0.7.3", @@ -2746,7 +2745,7 @@ dependencies = [ [[package]] name = "libp2p-identify" version = "0.21.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +source = "git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695#3096cb6b89b2883a79ce5ffcb03d41778a09b695" dependencies = [ "futures 0.3.5", "libp2p-core 0.21.0", @@ -2761,7 +2760,7 @@ dependencies = [ [[package]] name = "libp2p-mplex" version = "0.21.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +source = "git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695#3096cb6b89b2883a79ce5ffcb03d41778a09b695" dependencies = [ "bytes 0.5.6", "fnv", @@ -2776,7 +2775,7 @@ dependencies = [ [[package]] name = "libp2p-noise" version = "0.23.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +source = "git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695#3096cb6b89b2883a79ce5ffcb03d41778a09b695" dependencies = [ "bytes 0.5.6", "curve25519-dalek", @@ -2797,7 +2796,7 @@ dependencies = [ [[package]] name = "libp2p-swarm" version = "0.21.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +source = "git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695#3096cb6b89b2883a79ce5ffcb03d41778a09b695" dependencies = [ "futures 0.3.5", "libp2p-core 0.21.0", @@ -2811,7 +2810,7 @@ dependencies = [ [[package]] name = "libp2p-tcp" version = "0.21.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +source = "git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695#3096cb6b89b2883a79ce5ffcb03d41778a09b695" dependencies = [ "futures 0.3.5", "futures-timer", @@ -2826,7 +2825,7 @@ dependencies = [ [[package]] name = "libp2p-websocket" version = "0.22.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +source = "git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695#3096cb6b89b2883a79ce5ffcb03d41778a09b695" dependencies = [ "async-tls", "either", @@ -2845,7 +2844,7 @@ dependencies = [ [[package]] name = "libp2p-yamux" version = "0.21.0" -source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +source = "git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695#3096cb6b89b2883a79ce5ffcb03d41778a09b695" dependencies = [ "futures 0.3.5", "libp2p-core 0.21.0", @@ -3213,7 +3212,7 @@ checksum = "d8883adfde9756c1d30b0f519c9b8c502a94b41ac62f696453c37c7fc0a958ce" [[package]] name = "multistream-select" version = "0.8.2" -source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +source = "git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695#3096cb6b89b2883a79ce5ffcb03d41778a09b695" dependencies = [ "bytes 0.5.6", "futures 0.3.5", @@ -3501,7 +3500,7 @@ dependencies = [ [[package]] name = "parity-multiaddr" version = "0.9.1" -source = "git+https://github.com/sigp/rust-libp2p?rev=5139ec3ace4ad52506f217d790f0a9425274caef#5139ec3ace4ad52506f217d790f0a9425274caef" +source = "git+https://github.com/sigp/rust-libp2p?rev=3096cb6b89b2883a79ce5ffcb03d41778a09b695#3096cb6b89b2883a79ce5ffcb03d41778a09b695" dependencies = [ "arrayref", "bs58", @@ -4709,9 +4708,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41" +checksum = "a3e12110bc539e657a646068aaf5eb5b63af9d0c1f7b29c97113fad80e15f035" dependencies = [ "arc-swap", "libc", @@ -5741,9 +5740,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2734b5a028fa697686f16c6d18c2c6a3c7e41513f9a213abb6754c4acb3c8d7" +checksum = "d593f98af59ebc017c0648f0117525db358745a8894a8d684e185ba3f45954f9" dependencies = [ "lazy_static", ]