Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
1f838db
client/network: upgrade to libp2p 0.51.0
melekes Mar 6, 2023
a96ec02
make discovery.rs compile
melekes Mar 13, 2023
1feeea5
make peer_info.rs compile
melekes Mar 13, 2023
7f5bd59
changes to notifications and request-response proto
melekes Mar 14, 2023
6fa1fec
make service.rs compile
melekes Mar 14, 2023
84fa16e
towards making request_responses.rs compile
melekes Mar 14, 2023
b469184
make request_responses.rs compile
melekes Mar 15, 2023
82381e7
make request_responses.rs compile
melekes Mar 15, 2023
5d47761
fix notifications/behaviour.rs tests
melekes Mar 15, 2023
683f7d0
fix warnings
melekes Mar 15, 2023
88faef0
remove old code
melekes Mar 16, 2023
0e4e650
allow deprecated code (temporary)
melekes Mar 16, 2023
44734ce
upgrade to libp2p 0.51.1
melekes Mar 23, 2023
38db38c
add TODO for behaviour tests
melekes Mar 23, 2023
a02f891
return empty vec if peer_id is absent
melekes Mar 23, 2023
dfd5c3e
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes Mar 24, 2023
7a981ab
update comment to reflect new defaults
melekes Mar 27, 2023
943c031
Revert "update comment to reflect new defaults"
melekes Mar 28, 2023
17365d1
remove config.rs (from wrong merge)
melekes Mar 29, 2023
6b87f23
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes Mar 30, 2023
4fc9c96
upgrade to libp2p 0.51.2
melekes Mar 30, 2023
fd6429d
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes Mar 30, 2023
890ce96
fix formatting
melekes Mar 31, 2023
df205b6
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes Mar 31, 2023
c1cf2e8
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes Apr 3, 2023
31f5653
use handle_pending_outbound_connection in networt_state RPC
melekes Apr 3, 2023
ae2c0c4
update deps
melekes Apr 3, 2023
3f0ca7e
use re-exports when we use other libp2p packages
melekes Apr 3, 2023
83f5373
Apply suggestions from code review
melekes Apr 3, 2023
854509b
format code
melekes Apr 3, 2023
3a865c5
handle potential errors in network_state RPC
melekes Apr 3, 2023
7571f9d
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes Apr 3, 2023
9a8861f
only update libp2p crate
melekes Apr 3, 2023
8ee6f65
update libp2p-core
melekes Apr 4, 2023
29caff6
fix docs
melekes Apr 4, 2023
c69c0a6
use libp2p-identity instead of libp2p
melekes Apr 4, 2023
866d522
Update client/network/src/discovery.rs
melekes Apr 5, 2023
a3c9038
Merge remote-tracking branch 'origin/master' into anton/13537-upgrade…
Apr 5, 2023
1068d77
Merge remote-tracking branch 'origin/master' into anton/13537-upgrade…
Apr 6, 2023
724188d
update Cargo.lock
melekes Apr 6, 2023
60e1634
add comment for per_connection_event_buffer_size
melekes Apr 6, 2023
bb1b5db
fix link format
melekes Apr 6, 2023
f5a2828
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes Apr 7, 2023
b3d43e3
update Cargo.lock
melekes Apr 7, 2023
b675df1
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes May 3, 2023
6544dd4
upgrade to libp2p 0.51.3
melekes May 4, 2023
9e25820
deprecate mplex
melekes May 4, 2023
39ffe48
Revert "deprecate mplex"
melekes May 4, 2023
0bf1bfa
Revert "upgrade to libp2p 0.51.3"
melekes May 4, 2023
3c69044
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes May 5, 2023
979d076
use new libp2p version in `statement` crate
melekes May 5, 2023
82b3956
pin version temporarily
melekes May 6, 2023
90691b9
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes May 6, 2023
1c35b82
libp2p 0.51.3
melekes May 6, 2023
7c7ff40
deprecate mplex
melekes May 6, 2023
bb161c7
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes May 11, 2023
0630e6d
deprecate legacy noise handshake
melekes May 11, 2023
5551d23
fix build error
melekes May 11, 2023
97e75cf
update libp2p-identity
melekes May 11, 2023
a7a5b8e
enable libp2p-identity:ed25519 feature in sc-consensus
melekes May 11, 2023
0a0defc
enable ed25519 for peerset as well
melekes May 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
528 changes: 228 additions & 300 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/authority-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ codec = { package = "parity-scale-codec", version = "3.2.2", default-features =
futures = "0.3.21"
futures-timer = "3.0.1"
ip_network = "0.4.1"
libp2p = { version = "0.50.0", features = ["kad"] }
libp2p = { version = "0.51.0", features = ["kad"] }
log = "0.4.17"
prost = "0.11"
rand = "0.8.5"
Expand Down
2 changes: 1 addition & 1 deletion client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ chrono = "0.4.10"
clap = { version = "4.0.9", features = ["derive", "string"] }
fdlimit = "0.2.1"
futures = "0.3.21"
libp2p = "0.50.0"
libp2p = "0.51.0"
log = "0.4.17"
names = { version = "0.13.0", default-features = false }
parity-scale-codec = "3.2.2"
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
async-trait = "0.1.57"
futures = { version = "0.3.21", features = ["thread-pool"] }
futures-timer = "3.0.1"
libp2p = "0.50.0"
libp2p = "0.51.0"
log = "0.4.17"
mockall = "0.11.3"
parking_lot = "0.12.1"
Expand Down
2 changes: 1 addition & 1 deletion client/network-gossip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"]
ahash = "0.8.2"
futures = "0.3.21"
futures-timer = "3.0.1"
libp2p = "0.50.0"
libp2p = "0.51.0"
log = "0.4.17"
lru = "0.8.1"
tracing = "0.1.29"
Expand Down
2 changes: 1 addition & 1 deletion client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fnv = "1.0.6"
futures = "0.3.21"
futures-timer = "3.0.2"
ip_network = "0.4.1"
libp2p = { version = "0.50.0", features = ["dns", "identify", "kad", "macros", "mdns", "mplex", "noise", "ping", "tcp", "tokio", "yamux", "websocket"] }
libp2p = { version = "0.51.0", features = ["dns", "identify", "kad", "macros", "mdns", "mplex", "noise", "ping", "tcp", "tokio", "yamux", "websocket"] }
log = "0.4.17"
lru = "0.8.1"
mockall = "0.11.3"
Expand Down
2 changes: 1 addition & 1 deletion client/network/bitswap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ prost-build = "0.11"
[dependencies]
cid = "0.8.6"
futures = "0.3.21"
libp2p = "0.50.0"
libp2p = "0.51.0"
log = "0.4.17"
prost = "0.11"
thiserror = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion client/network/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ codec = { package = "parity-scale-codec", version = "3.2.2", features = [
] }
futures = "0.3.21"
futures-timer = "3.0.2"
libp2p = { version = "0.50.0", features = ["request-response", "kad"] }
libp2p = { version = "0.51.0", features = ["request-response", "kad"] }
linked_hash_set = "0.1.3"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../../utils/prometheus" }
smallvec = "1.8.0"
Expand Down
2 changes: 1 addition & 1 deletion client/network/light/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ codec = { package = "parity-scale-codec", version = "3.2.2", features = [
"derive",
] }
futures = "0.3.21"
libp2p = "0.50.0"
libp2p = "0.51.0"
log = "0.4.16"
prost = "0.11"
sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" }
Expand Down
108 changes: 82 additions & 26 deletions client/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ use futures::prelude::*;
use futures_timer::Delay;
use ip_network::IpNetwork;
use libp2p::{
core::{connection::ConnectionId, Multiaddr, PeerId, PublicKey},
core::{Endpoint, Multiaddr, PeerId, PublicKey},
kad::{
handler::KademliaHandlerProto,
handler::KademliaHandler,
record::{
self,
store::{MemoryStore, RecordStore},
Expand All @@ -65,11 +65,11 @@ use libp2p::{
multiaddr::Protocol,
swarm::{
behaviour::{
toggle::{Toggle, ToggleIntoConnectionHandler},
toggle::{Toggle, ToggleConnectionHandler},
DialFailure, FromSwarm, NewExternalAddr,
},
ConnectionHandler, DialError, IntoConnectionHandler, NetworkBehaviour,
NetworkBehaviourAction, PollParameters,
ConnectionDenied, ConnectionId, DialError, NetworkBehaviour, NetworkBehaviourAction,
PollParameters, THandler, THandlerInEvent, THandlerOutEvent,
},
};
use log::{debug, info, trace, warn};
Expand Down Expand Up @@ -234,7 +234,7 @@ impl DiscoveryConfig {
allow_private_ip,
discovery_only_if_under_num,
mdns: if enable_mdns {
match TokioMdns::new(mdns::Config::default()) {
match TokioMdns::new(mdns::Config::default(), local_peer_id) {
Ok(mdns) => Some(mdns),
Err(err) => {
warn!(target: "sub-libp2p", "Failed to initialize mDNS: {:?}", err);
Expand Down Expand Up @@ -483,29 +483,86 @@ pub enum DiscoveryOut {
}

impl NetworkBehaviour for DiscoveryBehaviour {
type ConnectionHandler = ToggleIntoConnectionHandler<KademliaHandlerProto<QueryId>>;
type ConnectionHandler = ToggleConnectionHandler<KademliaHandler<QueryId>>;
type OutEvent = DiscoveryOut;

fn new_handler(&mut self) -> Self::ConnectionHandler {
self.kademlia.new_handler()
fn handle_established_inbound_connection(
&mut self,
connection_id: ConnectionId,
peer: PeerId,
local_addr: &Multiaddr,
remote_addr: &Multiaddr,
) -> Result<THandler<Self>, ConnectionDenied> {
self.kademlia.handle_established_inbound_connection(
connection_id,
peer,
local_addr,
remote_addr,
)
}

fn addresses_of_peer(&mut self, peer_id: &PeerId) -> Vec<Multiaddr> {
let mut list = self
.permanent_addresses
.iter()
.filter_map(|(p, a)| if p == peer_id { Some(a.clone()) } else { None })
.collect::<Vec<_>>();
fn handle_established_outbound_connection(
&mut self,
connection_id: ConnectionId,
peer: PeerId,
addr: &Multiaddr,
role_override: Endpoint,
) -> Result<THandler<Self>, ConnectionDenied> {
self.kademlia.handle_established_outbound_connection(
connection_id,
peer,
addr,
role_override,
)
}

fn handle_pending_inbound_connection(
&mut self,
connection_id: ConnectionId,
local_addr: &Multiaddr,
remote_addr: &Multiaddr,
) -> Result<(), ConnectionDenied> {
self.kademlia
.handle_pending_inbound_connection(connection_id, local_addr, remote_addr)
}

fn handle_pending_outbound_connection(
&mut self,
connection_id: ConnectionId,
maybe_peer: Option<PeerId>,
addresses: &[Multiaddr],
effective_role: Endpoint,
) -> Result<Vec<Multiaddr>, ConnectionDenied> {
let mut list = Vec::new();

if let Some(peer_id) = maybe_peer {
list.extend(
self.permanent_addresses
.iter()
.filter_map(|(p, a)| if *p == peer_id { Some(a.clone()) } else { None })
.collect::<Vec<_>>(),
);

if let Some(ephemeral_addresses) = self.ephemeral_addresses.get(peer_id) {
list.extend(ephemeral_addresses.clone());
if let Some(ephemeral_addresses) = self.ephemeral_addresses.get(&peer_id) {
list.extend(ephemeral_addresses.clone());
}
}

{
let mut list_to_filter = self.kademlia.addresses_of_peer(peer_id);
let mut list_to_filter = self.kademlia.handle_pending_outbound_connection(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we attempt to get more addresses from kademlia and mdns for a peer if there's no ID (maybe_peer is None)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there easy way to do it? I'd probably not bother with it and just let the next random walk find new peers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there easy way to do it?

the code already does this. no need to do anything.

I was asking if it even makes sense to probe kademlia / mdns if peerID is empty. I guess it won't hurt. Otherwise we can just return empty Vec if maybe_peer.is_none() in the beginning of this function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would err on the side of caution and keep the old behavior for now at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in a02f891

connection_id,
maybe_peer,
addresses,
effective_role,
)?;

if let Some(ref mut mdns) = self.mdns {
list_to_filter.extend(mdns.addresses_of_peer(peer_id));
list_to_filter.extend(mdns.handle_pending_outbound_connection(
connection_id,
maybe_peer,
addresses,
effective_role,
)?);
}

if !self.allow_private_ip {
Expand All @@ -519,9 +576,9 @@ impl NetworkBehaviour for DiscoveryBehaviour {
list.extend(list_to_filter);
}

trace!(target: "sub-libp2p", "Addresses of {:?}: {:?}", peer_id, list);
trace!(target: "sub-libp2p","Addresses of {:?} (connection ID: {:?}): {:?}", maybe_peer, connection_id, list);

list
Ok(list)
}

fn on_swarm_event(&mut self, event: FromSwarm<Self::ConnectionHandler>) {
Expand Down Expand Up @@ -602,8 +659,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
&mut self,
peer_id: PeerId,
connection_id: ConnectionId,
event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as
ConnectionHandler>::OutEvent,
event: THandlerOutEvent<Self>,
) {
self.kademlia.on_connection_handler_event(peer_id, connection_id, event);
}
Expand All @@ -612,7 +668,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
&mut self,
cx: &mut Context,
params: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
) -> Poll<NetworkBehaviourAction<Self::OutEvent, THandlerInEvent<Self>>> {
// Immediately process the content of `discovered`.
if let Some(ev) = self.pending_events.pop_front() {
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev))
Expand Down Expand Up @@ -820,8 +876,8 @@ impl NetworkBehaviour for DiscoveryBehaviour {
warn!(target: "sub-libp2p", "Libp2p => Unhandled Kademlia event: {:?}", e)
},
},
NetworkBehaviourAction::Dial { opts, handler } =>
return Poll::Ready(NetworkBehaviourAction::Dial { opts, handler }),
NetworkBehaviourAction::Dial { opts } =>
return Poll::Ready(NetworkBehaviourAction::Dial { opts }),
NetworkBehaviourAction::NotifyHandler { peer_id, handler, event } =>
return Poll::Ready(NetworkBehaviourAction::NotifyHandler {
peer_id,
Expand Down
Loading