Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit d38d176

Browse files
authored
chore: update libp2p to 0.52.1 (#14429)
* update libp2p to 0.52.0 * proto name now must implement `AsRef<str>` * update libp2p version everywhere * ToSwarm, FromBehaviour, ToBehaviour also LocalProtocolsChange and RemoteProtocolsChange * new NetworkBehaviour invariants * replace `Vec<u8>` with `StreamProtocol` * rename ConnectionHandlerEvent::Custom to NotifyBehaviour * remove DialError & ListenError invariants also fix pending_events * use connection_limits::Behaviour See libp2p/rust-libp2p#3885 * impl `void::Void` for `BehaviourOut` also use `Behaviour::with_codec` * KademliaHandler no longer public * fix StreamProtocol construction * update libp2p-identify to 0.2.0 * remove non-existing methods from PollParameters rename ConnectionHandlerUpgrErr to StreamUpgradeError * `P2p` now contains `PeerId`, not `Multihash` * use multihash-codetable crate * update Cargo.lock * reformat text * comment out tests for now * remove `.into()` from P2p * confirm observed addr manually See https://github.com/libp2p/rust-libp2p/blob/master/protocols/identify/CHANGELOG.md#0430 * remove SwarmEvent::Banned since we're not using `ban_peer_id`, this can be safely removed. we may want to introduce `libp2p::allow_block_list` module in the future. * fix imports * replace `libp2p` with smaller deps in network-gossip * bring back tests * finish rewriting tests * uncomment handler tests * Revert "uncomment handler tests" This reverts commit 720a068. * add a fixme * update Cargo.lock * remove extra From * make void uninhabited * fix discovery test * use autonat protocols confirming external addresses manually is unsafe in open networks * fix SyncNotificationsClogged invariant * only set server mode manually in tests doubt that we need to set it on node since we're adding public addresses * address @dmitry-markin comments * remove autonat * removed unused var * fix EOL * update smallvec and sha2 in attempt to compile polkadot * bump k256 in attempt to build cumulus --------- Co-authored-by: parity-processbot <>
1 parent b9b1bbb commit d38d176

File tree

44 files changed

+1311
-2201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1311
-2201
lines changed

Cargo.lock

Lines changed: 272 additions & 1205 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/authority-discovery/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ codec = { package = "parity-scale-codec", version = "3.6.1", default-features =
2121
futures = "0.3.21"
2222
futures-timer = "3.0.1"
2323
ip_network = "0.4.1"
24-
libp2p = { version = "0.51.3", features = ["kad", "ed25519"] }
25-
multihash = { version = "0.17.0", default-features = false, features = ["std", "sha2"] }
24+
libp2p = { version = "0.52.1", features = ["kad", "ed25519"] }
25+
multihash-codetable = { version = "0.1.0", features = ["sha2", "digest"] }
2626
log = "0.4.17"
2727
prost = "0.11"
2828
rand = "0.8.5"

client/authority-discovery/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn get_addresses_and_authority_id() {
5656
let remote_addr = "/ip6/2001:db8:0:0:0:0:0:2/tcp/30333"
5757
.parse::<Multiaddr>()
5858
.unwrap()
59-
.with(Protocol::P2p(remote_peer_id.into()));
59+
.with(Protocol::P2p(remote_peer_id));
6060

6161
let test_api = Arc::new(TestApi { authorities: vec![] });
6262

client/authority-discovery/src/worker.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use futures::{channel::mpsc, future, stream::Fuse, FutureExt, Stream, StreamExt}
3434
use addr_cache::AddrCache;
3535
use codec::{Decode, Encode};
3636
use ip_network::IpNetwork;
37-
use libp2p::{core::multiaddr, identity::PublicKey, multihash::Multihash, Multiaddr, PeerId};
38-
use multihash::{Code, MultihashDigest};
37+
use libp2p::{core::multiaddr, identity::PublicKey, Multiaddr};
38+
use multihash_codetable::{Code, MultihashDigest};
3939

4040
use log::{debug, error, log_enabled};
4141
use prometheus_endpoint::{register, Counter, CounterVec, Gauge, Opts, U64};
@@ -304,7 +304,7 @@ where
304304
}
305305

306306
fn addresses_to_publish(&self) -> impl Iterator<Item = Multiaddr> {
307-
let peer_id: Multihash = self.network.local_peer_id().into();
307+
let peer_id = self.network.local_peer_id();
308308
let publish_non_global_ips = self.publish_non_global_ips;
309309
self.network
310310
.external_addresses()
@@ -529,7 +529,7 @@ where
529529
.map_err(Error::ParsingMultiaddress)?;
530530

531531
let get_peer_id = |a: &Multiaddr| match a.iter().last() {
532-
Some(multiaddr::Protocol::P2p(key)) => PeerId::from_multihash(key).ok(),
532+
Some(multiaddr::Protocol::P2p(peer_id)) => Some(peer_id),
533533
_ => None,
534534
};
535535

client/authority-discovery/src/worker/addr_cache.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ impl AddrCache {
162162

163163
fn peer_id_from_multiaddr(addr: &Multiaddr) -> Option<PeerId> {
164164
addr.iter().last().and_then(|protocol| {
165-
if let Protocol::P2p(multihash) = protocol {
166-
PeerId::from_multihash(multihash).ok()
165+
if let Protocol::P2p(peer_id) = protocol {
166+
Some(peer_id)
167167
} else {
168168
None
169169
}
@@ -178,7 +178,8 @@ fn addresses_to_peer_ids(addresses: &HashSet<Multiaddr>) -> HashSet<PeerId> {
178178
mod tests {
179179
use super::*;
180180

181-
use libp2p::multihash::{self, Multihash};
181+
use libp2p::multihash::Multihash;
182+
use multihash_codetable::Code;
182183
use quickcheck::{Arbitrary, Gen, QuickCheck, TestResult};
183184

184185
use sp_authority_discovery::{AuthorityId, AuthorityPair};
@@ -200,14 +201,13 @@ mod tests {
200201
impl Arbitrary for TestMultiaddr {
201202
fn arbitrary(g: &mut Gen) -> Self {
202203
let seed = (0..32).map(|_| u8::arbitrary(g)).collect::<Vec<_>>();
203-
let peer_id = PeerId::from_multihash(
204-
Multihash::wrap(multihash::Code::Sha2_256.into(), &seed).unwrap(),
205-
)
206-
.unwrap();
204+
let peer_id =
205+
PeerId::from_multihash(Multihash::wrap(Code::Sha2_256.into(), &seed).unwrap())
206+
.unwrap();
207207
let multiaddr = "/ip6/2001:db8:0:0:0:0:0:2/tcp/30333"
208208
.parse::<Multiaddr>()
209209
.unwrap()
210-
.with(Protocol::P2p(peer_id.into()));
210+
.with(Protocol::P2p(peer_id));
211211

212212
TestMultiaddr(multiaddr)
213213
}
@@ -219,18 +219,17 @@ mod tests {
219219
impl Arbitrary for TestMultiaddrsSamePeerCombo {
220220
fn arbitrary(g: &mut Gen) -> Self {
221221
let seed = (0..32).map(|_| u8::arbitrary(g)).collect::<Vec<_>>();
222-
let peer_id = PeerId::from_multihash(
223-
Multihash::wrap(multihash::Code::Sha2_256.into(), &seed).unwrap(),
224-
)
225-
.unwrap();
222+
let peer_id =
223+
PeerId::from_multihash(Multihash::wrap(Code::Sha2_256.into(), &seed).unwrap())
224+
.unwrap();
226225
let multiaddr1 = "/ip6/2001:db8:0:0:0:0:0:2/tcp/30333"
227226
.parse::<Multiaddr>()
228227
.unwrap()
229-
.with(Protocol::P2p(peer_id.into()));
228+
.with(Protocol::P2p(peer_id));
230229
let multiaddr2 = "/ip6/2002:db8:0:0:0:0:0:2/tcp/30133"
231230
.parse::<Multiaddr>()
232231
.unwrap()
233-
.with(Protocol::P2p(peer_id.into()));
232+
.with(Protocol::P2p(peer_id));
234233
TestMultiaddrsSamePeerCombo(multiaddr1, multiaddr2)
235234
}
236235
}
@@ -367,7 +366,7 @@ mod tests {
367366
let mut addr_cache = AddrCache::new();
368367

369368
let peer_id = PeerId::random();
370-
let addr = Multiaddr::empty().with(Protocol::P2p(peer_id.into()));
369+
let addr = Multiaddr::empty().with(Protocol::P2p(peer_id));
371370

372371
let authority_id0 = AuthorityPair::generate().0.public();
373372
let authority_id1 = AuthorityPair::generate().0.public();

client/authority-discovery/src/worker/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ fn dont_stop_polling_dht_event_stream_after_bogus_event() {
415415
let peer_id = PeerId::random();
416416
let address: Multiaddr = "/ip6/2001:db8:0:0:0:0:0:1/tcp/30333".parse().unwrap();
417417

418-
address.with(multiaddr::Protocol::P2p(peer_id.into()))
418+
address.with(multiaddr::Protocol::P2p(peer_id))
419419
};
420420
let remote_key_store = MemoryKeystore::new();
421421
let remote_public_key: AuthorityId = remote_key_store
@@ -526,7 +526,7 @@ impl DhtValueFoundTester {
526526
let address: Multiaddr =
527527
format!("/ip6/2001:db8:0:0:0:0:0:{:x}/tcp/30333", idx).parse().unwrap();
528528

529-
address.with(multiaddr::Protocol::P2p(peer_id.into()))
529+
address.with(multiaddr::Protocol::P2p(peer_id))
530530
}
531531

532532
fn process_value_found(
@@ -749,7 +749,7 @@ fn lookup_throttling() {
749749
let peer_id = PeerId::random();
750750
let address: Multiaddr = "/ip6/2001:db8:0:0:0:0:0:1/tcp/30333".parse().unwrap();
751751

752-
address.with(multiaddr::Protocol::P2p(peer_id.into()))
752+
address.with(multiaddr::Protocol::P2p(peer_id))
753753
};
754754
let remote_key_store = MemoryKeystore::new();
755755
let remote_public_keys: Vec<AuthorityId> = (0..20)

client/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ chrono = "0.4.10"
1818
clap = { version = "4.2.5", features = ["derive", "string"] }
1919
fdlimit = "0.2.1"
2020
futures = "0.3.21"
21-
libp2p-identity = { version = "0.1.2", features = ["peerid", "ed25519"]}
21+
libp2p-identity = { version = "0.2.0", features = ["peerid", "ed25519"]}
2222
log = "0.4.17"
2323
names = { version = "0.13.0", default-features = false }
2424
parity-scale-codec = "3.6.1"

client/consensus/common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
1616
async-trait = "0.1.57"
1717
futures = { version = "0.3.21", features = ["thread-pool"] }
1818
futures-timer = "3.0.1"
19-
libp2p-identity = { version = "0.1.2", features = ["peerid", "ed25519"] }
19+
libp2p-identity = { version = "0.2.0", features = ["peerid", "ed25519"] }
2020
log = "0.4.17"
2121
mockall = "0.11.3"
2222
parking_lot = "0.12.1"

client/network-gossip/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ targets = ["x86_64-unknown-linux-gnu"]
1717
ahash = "0.8.2"
1818
futures = "0.3.21"
1919
futures-timer = "3.0.1"
20-
libp2p = "0.51.3"
20+
libp2p-identity = { version = "0.2.0", features = ["peerid", "ed25519"]}
21+
multiaddr = "0.18.0"
2122
log = "0.4.17"
2223
schnellru = "0.2.1"
2324
tracing = "0.1.29"

client/network-gossip/src/bridge.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use futures::{
2828
channel::mpsc::{channel, Receiver, Sender},
2929
prelude::*,
3030
};
31-
use libp2p::PeerId;
31+
use libp2p_identity::PeerId;
3232
use log::trace;
3333
use prometheus_endpoint::Registry;
3434
use sp_runtime::traits::Block as BlockT;
@@ -330,12 +330,13 @@ impl<B: BlockT> futures::future::FusedFuture for GossipEngine<B> {
330330
#[cfg(test)]
331331
mod tests {
332332
use super::*;
333-
use crate::{multiaddr::Multiaddr, ValidationResult, ValidatorContext};
333+
use crate::{ValidationResult, ValidatorContext};
334334
use futures::{
335335
channel::mpsc::{unbounded, UnboundedSender},
336336
executor::{block_on, block_on_stream},
337337
future::poll_fn,
338338
};
339+
use multiaddr::Multiaddr;
339340
use quickcheck::{Arbitrary, Gen, QuickCheck};
340341
use sc_network::{
341342
config::MultiaddrWithPeerId, NetworkBlock, NetworkEventStream, NetworkNotification,

0 commit comments

Comments
 (0)