Skip to content

Commit

Permalink
Upgrade libp2p to 0.54.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Oct 27, 2024
1 parent aa14790 commit 7903b11
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 113 deletions.
163 changes: 81 additions & 82 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 2 additions & 2 deletions prdoc/pr_6248.prdoc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 5 additions & 12 deletions substrate/client/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -613,12 +604,14 @@ impl NetworkBehaviour for DiscoveryBehaviour {
peer: PeerId,
addr: &Multiaddr,
role_override: Endpoint,
port_use: PortUse,
) -> Result<THandler<Self>, ConnectionDenied> {
self.kademlia.handle_established_outbound_connection(
connection_id,
peer,
addr,
role_override,
port_use,
)
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/client/network/src/network_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub enum Endpoint {
impl From<ConnectedPoint> 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 },
Expand Down
18 changes: 15 additions & 3 deletions substrate/client/network/src/peer_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -275,18 +275,21 @@ impl NetworkBehaviour for PeerInfoBehaviour {
peer: PeerId,
addr: &Multiaddr,
role_override: Endpoint,
port_use: PortUse,
) -> Result<THandler<Self>, 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))
}
Expand Down Expand Up @@ -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,
}));

Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 { .. } => {},
Expand Down
4 changes: 3 additions & 1 deletion substrate/client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -248,12 +248,14 @@ impl<B: BlockT> NetworkBehaviour for Protocol<B> {
peer: PeerId,
addr: &Multiaddr,
role_override: Endpoint,
port_use: PortUse,
) -> Result<THandler<Self>, ConnectionDenied> {
self.behaviour.handle_established_outbound_connection(
connection_id,
peer,
addr,
role_override,
port_use,
)
}

Expand Down
Loading

0 comments on commit 7903b11

Please sign in to comment.