From 1d112cd5f599649abd48a8da277f9a4fc48b0f78 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Sun, 27 Oct 2024 03:49:28 +0300 Subject: [PATCH] Upgrade libp2p to 0.54.1 --- Cargo.lock | 163 +++++++++--------- Cargo.toml | 2 +- prdoc/pr_6248.prdoc | 4 +- substrate/client/network/src/discovery.rs | 17 +- substrate/client/network/src/network_state.rs | 2 +- substrate/client/network/src/peer_info.rs | 18 +- substrate/client/network/src/protocol.rs | 4 +- .../src/protocol/notifications/behaviour.rs | 30 +++- .../src/protocol/notifications/tests.rs | 15 +- .../client/network/src/request_responses.rs | 13 +- substrate/client/network/src/service.rs | 7 +- substrate/client/telemetry/src/node.rs | 13 +- 12 files changed, 175 insertions(+), 113 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 082b1a42ba3bf..5fd486a2145f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5089,9 +5089,9 @@ dependencies = [ [[package]] name = "data-encoding" -version = "2.4.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" [[package]] name = "data-encoding-macro" @@ -8700,19 +8700,18 @@ dependencies = [ [[package]] name = "libp2p" -version = "0.53.2" +version = "0.54.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "681fb3f183edfbedd7a57d32ebe5dcdc0b9f94061185acf3c30249349cc6fc99" +checksum = "bbbe80f9c7e00526cd6b838075b9c171919404a4732cb2fa8ece0a093223bfc4" dependencies = [ "bytes", "either", "futures", "futures-timer", "getrandom", - "instant", - "libp2p-allow-block-list 0.3.0", - "libp2p-connection-limits 0.3.1", - "libp2p-core 0.41.3", + "libp2p-allow-block-list 0.4.0", + "libp2p-connection-limits 0.4.0", + "libp2p-core 0.42.0", "libp2p-dns", "libp2p-identify", "libp2p-identity", @@ -8723,7 +8722,7 @@ dependencies = [ "libp2p-ping", "libp2p-quic", "libp2p-request-response", - "libp2p-swarm 0.44.2", + "libp2p-swarm 0.45.1", "libp2p-tcp", "libp2p-upnp", "libp2p-websocket", @@ -8748,13 +8747,13 @@ dependencies = [ [[package]] name = "libp2p-allow-block-list" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "107b238b794cb83ab53b74ad5dcf7cca3200899b72fe662840cfb52f5b0a32e6" +checksum = "d1027ccf8d70320ed77e984f273bc8ce952f623762cb9bf2d126df73caef8041" dependencies = [ - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identity", - "libp2p-swarm 0.44.2", + "libp2p-swarm 0.45.1", "void", ] @@ -8772,13 +8771,13 @@ dependencies = [ [[package]] name = "libp2p-connection-limits" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7cd50a78ccfada14de94cbacd3ce4b0138157f376870f13d3a8422cd075b4fd" +checksum = "8d003540ee8baef0d254f7b6bfd79bac3ddf774662ca0abf69186d517ef82ad8" dependencies = [ - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identity", - "libp2p-swarm 0.44.2", + "libp2p-swarm 0.45.1", "void", ] @@ -8812,9 +8811,9 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.41.3" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5a8920cbd8540059a01950c1e5c96ea8d89eb50c51cd366fc18bdf540a6e48f" +checksum = "a61f26c83ed111104cd820fe9bc3aaabbac5f1652a1d213ed6e900b7918a1298" dependencies = [ "either", "fnv", @@ -8840,14 +8839,14 @@ dependencies = [ [[package]] name = "libp2p-dns" -version = "0.41.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d17cbcf7160ff35c3e8e560de4a068fe9d6cb777ea72840e48eb76ff9576c4b6" +checksum = "97f37f30d5c7275db282ecd86e54f29dd2176bd3ac656f06abf43bedb21eb8bd" dependencies = [ "async-trait", "futures", "hickory-resolver", - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identity", "parking_lot 0.12.3", "smallvec", @@ -8856,18 +8855,18 @@ dependencies = [ [[package]] name = "libp2p-identify" -version = "0.44.2" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5d635ebea5ca0c3c3e77d414ae9b67eccf2a822be06091b9c1a0d13029a1e2f" +checksum = "1711b004a273be4f30202778856368683bd9a83c4c7dcc8f848847606831a4e3" dependencies = [ "asynchronous-codec 0.7.0", "either", "futures", "futures-bounded", "futures-timer", - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identity", - "libp2p-swarm 0.44.2", + "libp2p-swarm 0.45.1", "lru 0.12.3", "quick-protobuf 0.8.1", "quick-protobuf-codec", @@ -8897,9 +8896,9 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.45.3" +version = "0.46.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc5767727d062c4eac74dd812c998f0e488008e82cce9c33b463d38423f9ad2" +checksum = "ced237d0bd84bbebb7c2cad4c073160dacb4fe40534963c32ed6d4c6bb7702a3" dependencies = [ "arrayvec 0.7.4", "asynchronous-codec 0.7.0", @@ -8909,10 +8908,9 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "instant", - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identity", - "libp2p-swarm 0.44.2", + "libp2p-swarm 0.45.1", "quick-protobuf 0.8.1", "quick-protobuf-codec", "rand", @@ -8922,21 +8920,22 @@ dependencies = [ "tracing", "uint 0.9.5", "void", + "web-time", ] [[package]] name = "libp2p-mdns" -version = "0.45.1" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49007d9a339b3e1d7eeebc4d67c05dbf23d300b7d091193ec2d3f26802d7faf2" +checksum = "14b8546b6644032565eb29046b42744aee1e9f261ed99671b2c93fb140dba417" dependencies = [ "data-encoding", "futures", "hickory-proto", "if-watch", - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identity", - "libp2p-swarm 0.44.2", + "libp2p-swarm 0.45.1", "rand", "smallvec", "socket2 0.5.7", @@ -8947,33 +8946,33 @@ dependencies = [ [[package]] name = "libp2p-metrics" -version = "0.14.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdac91ae4f291046a3b2660c039a2830c931f84df2ee227989af92f7692d3357" +checksum = "77ebafa94a717c8442d8db8d3ae5d1c6a15e30f2d347e0cd31d057ca72e42566" dependencies = [ "futures", - "instant", - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identify", "libp2p-identity", "libp2p-kad", "libp2p-ping", - "libp2p-swarm 0.44.2", + "libp2p-swarm 0.45.1", "pin-project", "prometheus-client", + "web-time", ] [[package]] name = "libp2p-noise" -version = "0.44.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecd0545ce077f6ea5434bcb76e8d0fe942693b4380aaad0d34a358c2bd05793" +checksum = "36b137cb1ae86ee39f8e5d6245a296518912014eaa87427d24e6ff58cfc1b28c" dependencies = [ "asynchronous-codec 0.7.0", "bytes", "curve25519-dalek 4.1.3", "futures", - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identity", "multiaddr 0.18.1", "multihash 0.19.1", @@ -8991,33 +8990,33 @@ dependencies = [ [[package]] name = "libp2p-ping" -version = "0.44.1" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1de5a6cf64fba7f7e8f2102711c9c6c043a8e56b86db8cd306492c517da3fb3" +checksum = "005a34420359223b974ee344457095f027e51346e992d1e0dcd35173f4cdd422" dependencies = [ "either", "futures", "futures-timer", - "instant", - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identity", - "libp2p-swarm 0.44.2", + "libp2p-swarm 0.45.1", "rand", "tracing", "void", + "web-time", ] [[package]] name = "libp2p-quic" -version = "0.10.3" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c67296ad4e092e23f92aea3d2bdb6f24eab79c0929ed816dfb460ea2f4567d2b" +checksum = "46352ac5cd040c70e88e7ff8257a2ae2f891a4076abad2c439584a31c15fd24e" dependencies = [ "bytes", "futures", "futures-timer", "if-watch", - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-tls", "parking_lot 0.12.3", @@ -9033,22 +9032,22 @@ dependencies = [ [[package]] name = "libp2p-request-response" -version = "0.26.3" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c314fe28368da5e3a262553fb0ad575c1c8934c461e10de10265551478163836" +checksum = "1356c9e376a94a75ae830c42cdaea3d4fe1290ba409a22c809033d1b7dcab0a6" dependencies = [ "async-trait", "futures", "futures-bounded", "futures-timer", - "instant", - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identity", - "libp2p-swarm 0.44.2", + "libp2p-swarm 0.45.1", "rand", "smallvec", "tracing", "void", + "web-time", ] [[package]] @@ -9074,16 +9073,15 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.44.2" +version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80cae6cb75f89dbca53862f9ebe0b9f463aa7b302762fcfaafb9e51dcc9b0f7e" +checksum = "d7dd6741793d2c1fb2088f67f82cf07261f25272ebe3c0b0c311e0c6b50e851a" dependencies = [ "either", "fnv", "futures", "futures-timer", - "instant", - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm-derive", "lru 0.12.3", @@ -9094,13 +9092,14 @@ dependencies = [ "tokio", "tracing", "void", + "web-time", ] [[package]] name = "libp2p-swarm-derive" -version = "0.34.2" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5daceb9dd908417b6dfcfe8e94098bc4aac54500c282e78120b885dadc09b999" +checksum = "206e0aa0ebe004d778d79fb0966aa0de996c19894e2c0605ba2f8524dd4443d8" dependencies = [ "heck 0.5.0", "proc-macro2 1.0.86", @@ -9110,15 +9109,15 @@ dependencies = [ [[package]] name = "libp2p-tcp" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b2460fc2748919adff99ecbc1aab296e4579e41f374fb164149bd2c9e529d4c" +checksum = "ad964f312c59dcfcac840acd8c555de8403e295d39edf96f5240048b5fcaa314" dependencies = [ "futures", "futures-timer", "if-watch", "libc", - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identity", "socket2 0.5.7", "tokio", @@ -9127,13 +9126,13 @@ dependencies = [ [[package]] name = "libp2p-tls" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b7b831e55ce2aa6c354e6861a85fdd4dd0a2b97d5e276fabac0e4810a71776" +checksum = "47b23dddc2b9c355f73c1e36eb0c3ae86f7dc964a3715f0731cfad352db4d847" dependencies = [ "futures", "futures-rustls", - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identity", "rcgen 0.11.3", "ring 0.17.8", @@ -9146,15 +9145,15 @@ dependencies = [ [[package]] name = "libp2p-upnp" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccf04b0e3ff3de52d07d5fd6c3b061d0e7f908ffc683c32d9638caedce86fc8" +checksum = "01bf2d1b772bd3abca049214a3304615e6a36fa6ffc742bdd1ba774486200b8f" dependencies = [ "futures", "futures-timer", "igd-next", - "libp2p-core 0.41.3", - "libp2p-swarm 0.44.2", + "libp2p-core 0.42.0", + "libp2p-swarm 0.45.1", "tokio", "tracing", "void", @@ -9162,14 +9161,14 @@ dependencies = [ [[package]] name = "libp2p-websocket" -version = "0.43.2" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b953b6803a1f3161a989538974d72511c4e48a4af355337b6fb90723c56c05" +checksum = "888b2ff2e5d8dcef97283daab35ad1043d18952b65e05279eecbe02af4c6e347" dependencies = [ "either", "futures", "futures-rustls", - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "libp2p-identity", "parking_lot 0.12.3", "pin-project-lite", @@ -9183,13 +9182,13 @@ dependencies = [ [[package]] name = "libp2p-yamux" -version = "0.45.2" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddd5265f6b80f94d48a3963541aad183cc598a645755d2f1805a373e41e0716b" +checksum = "788b61c80789dba9760d8c669a5bedb642c8267555c803fabd8396e4ca5c5882" dependencies = [ "either", "futures", - "libp2p-core 0.41.3", + "libp2p-core 0.42.0", "thiserror", "tracing", "yamux 0.12.1", @@ -18411,7 +18410,7 @@ dependencies = [ "futures", "futures-timer", "ip_network", - "libp2p 0.53.2", + "libp2p 0.54.1", "linked_hash_set", "log", "multihash 0.19.1", @@ -19221,7 +19220,7 @@ dependencies = [ "futures", "futures-timer", "ip_network", - "libp2p 0.53.2", + "libp2p 0.54.1", "linked_hash_set", "litep2p", "log", @@ -19396,7 +19395,7 @@ dependencies = [ "async-trait", "futures", "futures-timer", - "libp2p 0.53.2", + "libp2p 0.54.1", "log", "parking_lot 0.12.3", "rand", @@ -19831,7 +19830,7 @@ version = "15.0.0" dependencies = [ "chrono", "futures", - "libp2p 0.53.2", + "libp2p 0.54.1", "log", "parking_lot 0.12.3", "pin-project", diff --git a/Cargo.toml b/Cargo.toml index a55f2a105e04d..b1158764b7792 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -833,7 +833,7 @@ kvdb-shared-tests = { version = "0.11.0" } landlock = { version = "0.3.0" } libc = { version = "0.2.155" } libfuzzer-sys = { version = "0.4" } -libp2p = { version = "0.53.2" } +libp2p = { version = "0.54.1" } libp2p-identity = { version = "0.2.9" } libsecp256k1 = { version = "0.7.0", default-features = false } linked-hash-map = { version = "0.5.4" } diff --git a/prdoc/pr_6248.prdoc b/prdoc/pr_6248.prdoc index 0caf39520ac50..7cf97ca5f8ecf 100644 --- a/prdoc/pr_6248.prdoc +++ b/prdoc/pr_6248.prdoc @@ -1,9 +1,9 @@ -title: Upgrade libp2p to 0.53.2 +title: Upgrade libp2p to 0.54.1 doc: - audience: [Node Dev, Node Operator] description: | - Upgrade libp2p from 0.52.4 to 0.53.2 + Upgrade libp2p from 0.52.4 to 0.54.1 crates: - name: sc-authority-discovery diff --git a/substrate/client/network/src/discovery.rs b/substrate/client/network/src/discovery.rs index daecadc08e2f7..603eeeb764538 100644 --- a/substrate/client/network/src/discovery.rs +++ b/substrate/client/network/src/discovery.rs @@ -53,7 +53,7 @@ use futures::prelude::*; use futures_timer::Delay; use ip_network::IpNetwork; use libp2p::{ - core::{Endpoint, Multiaddr}, + core::{transport::PortUse, Endpoint, Multiaddr}, kad::{ self, store::{MemoryStore, RecordStore}, @@ -214,23 +214,14 @@ impl DiscoveryConfig { enable_mdns, kademlia_disjoint_query_paths, kademlia_protocol, - kademlia_legacy_protocol, + kademlia_legacy_protocol: _, kademlia_replication_factor, } = self; let kademlia = if let Some(ref kademlia_protocol) = kademlia_protocol { - let mut config = KademliaConfig::default(); + let mut config = KademliaConfig::new(kademlia_protocol.clone()); config.set_replication_factor(kademlia_replication_factor); - // Populate kad with both the legacy and the new protocol names. - // Remove the legacy protocol: - // https://github.com/paritytech/polkadot-sdk/issues/504 - let kademlia_protocols = if let Some(legacy_protocol) = kademlia_legacy_protocol { - vec![kademlia_protocol.clone(), legacy_protocol] - } else { - vec![kademlia_protocol.clone()] - }; - config.set_protocol_names(kademlia_protocols.into_iter().map(Into::into).collect()); config.set_record_filtering(libp2p::kad::StoreInserts::FilterBoth); @@ -613,12 +604,14 @@ impl NetworkBehaviour for DiscoveryBehaviour { peer: PeerId, addr: &Multiaddr, role_override: Endpoint, + port_use: PortUse, ) -> Result, ConnectionDenied> { self.kademlia.handle_established_outbound_connection( connection_id, peer, addr, role_override, + port_use, ) } diff --git a/substrate/client/network/src/network_state.rs b/substrate/client/network/src/network_state.rs index cf8b8b55a7ff8..65fd494739ee3 100644 --- a/substrate/client/network/src/network_state.rs +++ b/substrate/client/network/src/network_state.rs @@ -106,7 +106,7 @@ pub enum Endpoint { impl From for PeerEndpoint { fn from(endpoint: ConnectedPoint) -> Self { match endpoint { - ConnectedPoint::Dialer { address, role_override } => + ConnectedPoint::Dialer { address, role_override, port_use: _ } => Self::Dialing(address, role_override.into()), ConnectedPoint::Listener { local_addr, send_back_addr } => Self::Listening { local_addr, send_back_addr }, diff --git a/substrate/client/network/src/peer_info.rs b/substrate/client/network/src/peer_info.rs index 77036c2829221..bd3143ad4b13b 100644 --- a/substrate/client/network/src/peer_info.rs +++ b/substrate/client/network/src/peer_info.rs @@ -25,7 +25,7 @@ use either::Either; use fnv::FnvHashMap; use futures::prelude::*; use libp2p::{ - core::{ConnectedPoint, Endpoint}, + core::{transport::PortUse, ConnectedPoint, Endpoint}, identify::{ Behaviour as Identify, Config as IdentifyConfig, Event as IdentifyEvent, Info as IdentifyInfo, @@ -275,18 +275,21 @@ impl NetworkBehaviour for PeerInfoBehaviour { peer: PeerId, addr: &Multiaddr, role_override: Endpoint, + port_use: PortUse, ) -> Result, ConnectionDenied> { let ping_handler = self.ping.handle_established_outbound_connection( connection_id, peer, addr, role_override, + port_use, )?; let identify_handler = self.identify.handle_established_outbound_connection( connection_id, peer, addr, role_override, + port_use, )?; Ok(ping_handler.select(identify_handler)) } @@ -319,18 +322,21 @@ impl NetworkBehaviour for PeerInfoBehaviour { peer_id, connection_id, endpoint, + cause, remaining_established, }) => { self.ping.on_swarm_event(FromSwarm::ConnectionClosed(ConnectionClosed { peer_id, connection_id, endpoint, + cause, remaining_established, })); self.identify.on_swarm_event(FromSwarm::ConnectionClosed(ConnectionClosed { peer_id, connection_id, endpoint, + cause, remaining_established, })); @@ -365,18 +371,21 @@ impl NetworkBehaviour for PeerInfoBehaviour { send_back_addr, error, connection_id, + peer_id, }) => { self.ping.on_swarm_event(FromSwarm::ListenFailure(ListenFailure { local_addr, send_back_addr, error, connection_id, + peer_id, })); self.identify.on_swarm_event(FromSwarm::ListenFailure(ListenFailure { local_addr, send_back_addr, error, connection_id, + peer_id, })); }, FromSwarm::ListenerError(e) => { @@ -486,8 +495,11 @@ impl NetworkBehaviour for PeerInfoBehaviour { let event = PeerInfoEvent::Identified { peer_id, info }; return Poll::Ready(ToSwarm::GenerateEvent(event)) }, - IdentifyEvent::Error { peer_id, error } => { - debug!(target: "sub-libp2p", "Identification with peer {:?} failed => {}", peer_id, error) + IdentifyEvent::Error { connection_id, peer_id, error } => { + debug!( + target: "sub-libp2p", + "Identification with peer {peer_id:?}({connection_id}) failed => {error}" + ); }, IdentifyEvent::Pushed { .. } => {}, IdentifyEvent::Sent { .. } => {}, diff --git a/substrate/client/network/src/protocol.rs b/substrate/client/network/src/protocol.rs index e069b85189ed0..6da1d601b34fc 100644 --- a/substrate/client/network/src/protocol.rs +++ b/substrate/client/network/src/protocol.rs @@ -27,7 +27,7 @@ use crate::{ use codec::Encode; use libp2p::{ - core::Endpoint, + core::{transport::PortUse, Endpoint}, swarm::{ behaviour::FromSwarm, ConnectionDenied, ConnectionId, NetworkBehaviour, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, @@ -248,12 +248,14 @@ impl NetworkBehaviour for Protocol { peer: PeerId, addr: &Multiaddr, role_override: Endpoint, + port_use: PortUse, ) -> Result, ConnectionDenied> { self.behaviour.handle_established_outbound_connection( connection_id, peer, addr, role_override, + port_use, ) } diff --git a/substrate/client/network/src/protocol/notifications/behaviour.rs b/substrate/client/network/src/protocol/notifications/behaviour.rs index a9875a7f532e4..aaa7db29404c5 100644 --- a/substrate/client/network/src/protocol/notifications/behaviour.rs +++ b/substrate/client/network/src/protocol/notifications/behaviour.rs @@ -33,7 +33,7 @@ use bytes::BytesMut; use fnv::FnvHashMap; use futures::{future::BoxFuture, prelude::*, stream::FuturesUnordered}; use libp2p::{ - core::{Endpoint, Multiaddr}, + core::{transport::PortUse, Endpoint, Multiaddr}, swarm::{ behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm}, ConnectionDenied, ConnectionId, DialError, NetworkBehaviour, NotifyHandler, THandler, @@ -1234,6 +1234,7 @@ impl NetworkBehaviour for Notifications { peer: PeerId, _addr: &Multiaddr, _role_override: Endpoint, + _port_use: PortUse, ) -> Result, ConnectionDenied> { Ok(NotifsHandler::new(peer, self.notif_protocols.clone(), Some(self.metrics.clone()))) } @@ -2651,6 +2652,7 @@ mod tests { peer_id: peer, connection_id: conn, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -2850,6 +2852,7 @@ mod tests { peer_id: peer, connection_id: conn, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -3002,6 +3005,7 @@ mod tests { peer_id: peer, connection_id: conn, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -3045,6 +3049,7 @@ mod tests { peer_id: peer, connection_id: conn, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -3114,6 +3119,7 @@ mod tests { peer_id: peer, connection_id: conn, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -3261,6 +3267,7 @@ mod tests { peer_id: peer, connection_id: conn1, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -3386,6 +3393,7 @@ mod tests { peer_id: peer, connection_id: conn, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -3459,6 +3467,7 @@ mod tests { peer_id: peer, connection_id: conn, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -3521,6 +3530,7 @@ mod tests { peer_id: peer, connection_id: conn1, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -3534,6 +3544,7 @@ mod tests { peer_id: peer, connection_id: conn2, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -3587,6 +3598,7 @@ mod tests { peer_id: peer, connection_id: conn, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -3644,6 +3656,7 @@ mod tests { peer_id: peer, connection_id: conn2, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -3704,6 +3717,7 @@ mod tests { peer_id: peer, connection_id: conn1, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -3772,6 +3786,7 @@ mod tests { peer_id: peer, connection_id: conn1, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -3812,6 +3827,7 @@ mod tests { peer_id: peer, connection_id: conn, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -3934,6 +3950,7 @@ mod tests { peer_id: peer, connection_id: conn, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -4239,6 +4256,7 @@ mod tests { peer_id: peer, connection_id: conn, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -4479,6 +4497,7 @@ mod tests { peer_id: peer, connection_id: ConnectionId::new_unchecked(0), endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -4580,6 +4599,7 @@ mod tests { peer_id: peer, connection_id: ConnectionId::new_unchecked(0), endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -4661,6 +4681,7 @@ mod tests { peer_id: peer, connection_id: ConnectionId::new_unchecked(0), endpoint: &endpoint.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -4777,6 +4798,7 @@ mod tests { peer_id: peer, connection_id: ConnectionId::new_unchecked(1337), endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -4811,6 +4833,7 @@ mod tests { peer_id: peer, connection_id: ConnectionId::new_unchecked(1337), endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -4861,6 +4884,7 @@ mod tests { peer_id: peer, connection_id: ConnectionId::new_unchecked(1337), endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -4907,6 +4931,7 @@ mod tests { peer_id: peer, connection_id: conn, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -4956,6 +4981,7 @@ mod tests { peer_id: peer, connection_id: ConnectionId::new_unchecked(1337), endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -4998,6 +5024,7 @@ mod tests { peer_id: peer, connection_id: conn, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); @@ -5008,6 +5035,7 @@ mod tests { peer_id: peer, connection_id: conn, endpoint: &connected.clone(), + cause: None, remaining_established: 0usize, }, )); diff --git a/substrate/client/network/src/protocol/notifications/tests.rs b/substrate/client/network/src/protocol/notifications/tests.rs index ce485e00fa321..50f03b5911b67 100644 --- a/substrate/client/network/src/protocol/notifications/tests.rs +++ b/substrate/client/network/src/protocol/notifications/tests.rs @@ -30,7 +30,10 @@ use crate::{ use futures::{future::BoxFuture, prelude::*}; use libp2p::{ - core::{transport::MemoryTransport, upgrade, Endpoint}, + core::{ + transport::{MemoryTransport, PortUse}, + upgrade, Endpoint, + }, identity, noise, swarm::{ behaviour::FromSwarm, ConnectionDenied, ConnectionId, NetworkBehaviour, Swarm, SwarmEvent, @@ -232,9 +235,15 @@ impl NetworkBehaviour for CustomProtoWithAddr { peer: PeerId, addr: &Multiaddr, role_override: Endpoint, + port_use: PortUse, ) -> Result, ConnectionDenied> { - self.inner - .handle_established_outbound_connection(connection_id, peer, addr, role_override) + self.inner.handle_established_outbound_connection( + connection_id, + peer, + addr, + role_override, + port_use, + ) } fn on_swarm_event(&mut self, event: FromSwarm) { diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 17200bfb9d115..aa831ec6d8578 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -43,7 +43,7 @@ use crate::{ use futures::{channel::oneshot, prelude::*}; use libp2p::{ - core::{Endpoint, Multiaddr}, + core::{transport::PortUse, Endpoint, Multiaddr}, request_response::{self, Behaviour, Codec, Message, ProtocolSupport, ResponseChannel}, swarm::{ behaviour::FromSwarm, handler::multi::MultiHandler, ConnectionDenied, ConnectionId, @@ -546,11 +546,16 @@ impl NetworkBehaviour for RequestResponsesBehaviour { peer: PeerId, addr: &Multiaddr, role_override: Endpoint, + port_use: PortUse, ) -> Result, ConnectionDenied> { let iter = self.protocols.iter_mut().filter_map(|(p, (r, _))| { - if let Ok(handler) = - r.handle_established_outbound_connection(connection_id, peer, addr, role_override) - { + if let Ok(handler) = r.handle_established_outbound_connection( + connection_id, + peer, + addr, + role_override, + port_use, + ) { Some((p.to_string(), handler)) } else { None diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 04aadb3075384..f0df43df1da13 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -1729,7 +1729,12 @@ where not_reported.then(|| self.boot_node_ids.get(&peer_id)).flatten() { if let DialError::WrongPeerId { obtained, endpoint } = &error { - if let ConnectedPoint::Dialer { address, role_override: _ } = endpoint { + if let ConnectedPoint::Dialer { + address, + role_override: _, + port_use: _, + } = endpoint + { let address_without_peer_id = parse_addr(address.clone().into()) .map_or_else(|_| address.clone(), |r| r.1.into()); diff --git a/substrate/client/telemetry/src/node.rs b/substrate/client/telemetry/src/node.rs index 0bbdbfb622ef1..2c8d424c4340f 100644 --- a/substrate/client/telemetry/src/node.rs +++ b/substrate/client/telemetry/src/node.rs @@ -18,7 +18,13 @@ use crate::TelemetryPayload; use futures::{channel::mpsc, prelude::*}; -use libp2p::{core::transport::Transport, Multiaddr}; +use libp2p::{ + core::{ + transport::{DialOpts, PortUse, Transport}, + Endpoint, + }, + Multiaddr, +}; use rand::Rng as _; use std::{ fmt, mem, @@ -229,7 +235,10 @@ where }, NodeSocket::ReconnectNow => { let addr = self.addr.clone(); - match self.transport.dial(addr) { + match self + .transport + .dial(addr, DialOpts { role: Endpoint::Dialer, port_use: PortUse::New }) + { Ok(d) => { log::trace!(target: "telemetry", "Re-dialing {}", self.addr); socket = NodeSocket::Dialing(d);