Skip to content

Commit

Permalink
chore: update libp2p to 0.52.1 (paritytech#14429)
Browse files Browse the repository at this point in the history
* 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 <>
  • Loading branch information
melekes authored and kayabaNerve committed Jul 28, 2023
1 parent 32907bb commit 6fc5b71
Show file tree
Hide file tree
Showing 43 changed files with 1,180 additions and 1,126 deletions.
6 changes: 3 additions & 3 deletions client/authority-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ codec = { package = "parity-scale-codec", version = "3", default-features = fals
futures = "0.3"
futures-timer = "3"
ip_network = "0.4.1"
libp2p = { version = "0.51", features = ["kad", "ed25519"] }
multihash = { version = "0.17", default-features = false, features = ["std", "sha2"] }
log = "0.4"
libp2p = { version = "0.52.1", features = ["kad", "ed25519"] }
multihash-codetable = { version = "0.1.0", features = ["sha2", "digest"] }
log = "0.4.17"
prost = "0.11"
rand = "0.8"
thiserror = "1"
Expand Down
2 changes: 1 addition & 1 deletion client/authority-discovery/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn get_addresses_and_authority_id() {
let remote_addr = "/ip6/2001:db8:0:0:0:0:0:2/tcp/30333"
.parse::<Multiaddr>()
.unwrap()
.with(Protocol::P2p(remote_peer_id.into()));
.with(Protocol::P2p(remote_peer_id));

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

Expand Down
8 changes: 4 additions & 4 deletions client/authority-discovery/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ use futures::{channel::mpsc, future, stream::Fuse, FutureExt, Stream, StreamExt}
use addr_cache::AddrCache;
use codec::{Decode, Encode};
use ip_network::IpNetwork;
use libp2p::{core::multiaddr, identity::PublicKey, multihash::Multihash, Multiaddr, PeerId};
use multihash::{Code, MultihashDigest};
use libp2p::{core::multiaddr, identity::PublicKey, Multiaddr};
use multihash_codetable::{Code, MultihashDigest};

use log::{debug, error, log_enabled};
use prometheus_endpoint::{register, Counter, CounterVec, Gauge, Opts, U64};
Expand Down Expand Up @@ -304,7 +304,7 @@ where
}

fn addresses_to_publish(&self) -> impl Iterator<Item = Multiaddr> {
let peer_id: Multihash = self.network.local_peer_id().into();
let peer_id = self.network.local_peer_id();
let publish_non_global_ips = self.publish_non_global_ips;
self.network
.external_addresses()
Expand Down Expand Up @@ -529,7 +529,7 @@ where
.map_err(Error::ParsingMultiaddress)?;

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

Expand Down
29 changes: 14 additions & 15 deletions client/authority-discovery/src/worker/addr_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ impl AddrCache {

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

use libp2p::multihash::{self, Multihash};
use libp2p::multihash::Multihash;
use multihash_codetable::Code;
use quickcheck::{Arbitrary, Gen, QuickCheck, TestResult};

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

TestMultiaddr(multiaddr)
}
Expand All @@ -219,18 +219,17 @@ mod tests {
impl Arbitrary for TestMultiaddrsSamePeerCombo {
fn arbitrary(g: &mut Gen) -> Self {
let seed = (0..32).map(|_| u8::arbitrary(g)).collect::<Vec<_>>();
let peer_id = PeerId::from_multihash(
Multihash::wrap(multihash::Code::Sha2_256.into(), &seed).unwrap(),
)
.unwrap();
let peer_id =
PeerId::from_multihash(Multihash::wrap(Code::Sha2_256.into(), &seed).unwrap())
.unwrap();
let multiaddr1 = "/ip6/2001:db8:0:0:0:0:0:2/tcp/30333"
.parse::<Multiaddr>()
.unwrap()
.with(Protocol::P2p(peer_id.into()));
.with(Protocol::P2p(peer_id));
let multiaddr2 = "/ip6/2002:db8:0:0:0:0:0:2/tcp/30133"
.parse::<Multiaddr>()
.unwrap()
.with(Protocol::P2p(peer_id.into()));
.with(Protocol::P2p(peer_id));
TestMultiaddrsSamePeerCombo(multiaddr1, multiaddr2)
}
}
Expand Down Expand Up @@ -367,7 +366,7 @@ mod tests {
let mut addr_cache = AddrCache::new();

let peer_id = PeerId::random();
let addr = Multiaddr::empty().with(Protocol::P2p(peer_id.into()));
let addr = Multiaddr::empty().with(Protocol::P2p(peer_id));

let authority_id0 = AuthorityPair::generate().0.public();
let authority_id1 = AuthorityPair::generate().0.public();
Expand Down
6 changes: 3 additions & 3 deletions client/authority-discovery/src/worker/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ fn dont_stop_polling_dht_event_stream_after_bogus_event() {
let peer_id = PeerId::random();
let address: Multiaddr = "/ip6/2001:db8:0:0:0:0:0:1/tcp/30333".parse().unwrap();

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

address.with(multiaddr::Protocol::P2p(peer_id.into()))
address.with(multiaddr::Protocol::P2p(peer_id))
}

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

address.with(multiaddr::Protocol::P2p(peer_id.into()))
address.with(multiaddr::Protocol::P2p(peer_id))
};
let remote_key_store = MemoryKeystore::new();
let remote_public_keys: Vec<AuthorityId> = (0..20)
Expand Down
32 changes: 16 additions & 16 deletions client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
array-bytes = "6"
chrono = "0.4"
clap = { version = "4", features = ["derive", "string"] }
fdlimit = "0.2"
futures = "0.3"
libp2p-identity = { version = "0.1", features = ["peerid", "ed25519"]}
log = "0.4"
array-bytes = "6.1"
chrono = "0.4.10"
clap = { version = "4.2.5", features = ["derive", "string"] }
fdlimit = "0.2.1"
futures = "0.3.21"
libp2p-identity = { version = "0.2.0", features = ["peerid", "ed25519"]}
log = "0.4.17"
names = { version = "0.14", default-features = false }
parity-scale-codec = "3"
rand = "0.8"
regex = "1"
rpassword = "7"
serde = "1"
serde_json = "1"
thiserror = "1"
tiny-bip39 = "1"
tokio = { version = "1", features = ["signal", "rt-multi-thread", "parking_lot"] }
parity-scale-codec = "3.6.1"
rand = "0.8.5"
regex = "1.6.0"
rpassword = "7.0.0"
serde = "1.0.163"
serde_json = "1.0.85"
thiserror = "1.0.30"
tiny-bip39 = "1.0.0"
tokio = { version = "1.22.0", features = ["signal", "rt-multi-thread", "parking_lot"] }
sc-client-api = { version = "4.0.0-dev", path = "../api" }
sc-client-db = { version = "0.10.0-dev", default-features = false, path = "../db" }
sc-keystore = { version = "4.0.0-dev", path = "../keystore" }
Expand Down
12 changes: 6 additions & 6 deletions client/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
async-trait = "0.1"
futures = { version = "0.3", features = ["thread-pool"] }
futures-timer = "3"
libp2p-identity = { version = "0.1", features = ["peerid", "ed25519"] }
log = "0.4"
mockall = "0.11"
async-trait = "0.1.57"
futures = { version = "0.3.21", features = ["thread-pool"] }
futures-timer = "3.0.1"
libp2p-identity = { version = "0.2.0", features = ["peerid", "ed25519"] }
log = "0.4.17"
mockall = "0.11.3"
parking_lot = "0.12.1"
serde = { version = "1", features = ["derive"] }
thiserror = "1"
Expand Down
15 changes: 8 additions & 7 deletions client/network-gossip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
ahash = "0.8"
futures = "0.3"
futures-timer = "3"
libp2p = "0.51"
log = "0.4"
schnellru = "0.2"
tracing = "0.1"
ahash = "0.8.2"
futures = "0.3.21"
futures-timer = "3.0.1"
libp2p-identity = { version = "0.2.0", features = ["peerid", "ed25519"]}
multiaddr = "0.18.0"
log = "0.4.17"
schnellru = "0.2.1"
tracing = "0.1.29"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../utils/prometheus" }
sc-network = { version = "0.10.0-dev", path = "../network/" }
sc-network-common = { version = "0.10.0-dev", path = "../network/common" }
Expand Down
5 changes: 3 additions & 2 deletions client/network-gossip/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use futures::{
channel::mpsc::{channel, Receiver, Sender},
prelude::*,
};
use libp2p::PeerId;
use libp2p_identity::PeerId;
use log::trace;
use prometheus_endpoint::Registry;
use sp_runtime::traits::Block as BlockT;
Expand Down Expand Up @@ -330,12 +330,13 @@ impl<B: BlockT> futures::future::FusedFuture for GossipEngine<B> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{multiaddr::Multiaddr, ValidationResult, ValidatorContext};
use crate::{ValidationResult, ValidatorContext};
use futures::{
channel::mpsc::{unbounded, UnboundedSender},
executor::{block_on, block_on_stream},
future::poll_fn,
};
use multiaddr::Multiaddr;
use quickcheck::{Arbitrary, Gen, QuickCheck};
use sc_network::{
config::MultiaddrWithPeerId, NetworkBlock, NetworkEventStream, NetworkNotification,
Expand Down
6 changes: 3 additions & 3 deletions client/network-gossip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ pub use self::{
validator::{DiscardAll, MessageIntent, ValidationResult, Validator, ValidatorContext},
};

use libp2p::{multiaddr, PeerId};
use libp2p_identity::PeerId;
use multiaddr::{Multiaddr, Protocol};
use sc_network::{
types::ProtocolName, NetworkBlock, NetworkEventStream, NetworkNotification, NetworkPeers,
};
Expand All @@ -82,8 +83,7 @@ mod validator;
/// Abstraction over a network.
pub trait Network<B: BlockT>: NetworkPeers + NetworkEventStream + NetworkNotification {
fn add_set_reserved(&self, who: PeerId, protocol: ProtocolName) {
let addr =
iter::once(multiaddr::Protocol::P2p(who.into())).collect::<multiaddr::Multiaddr>();
let addr = Multiaddr::empty().with(Protocol::P2p(who));
let result = self.add_peers_to_reserved_set(protocol, iter::once(addr).collect());
if let Err(err) = result {
log::error!(target: "gossip", "add_set_reserved failed: {}", err);
Expand Down
4 changes: 2 additions & 2 deletions client/network-gossip/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate::{MessageIntent, Network, ValidationResult, Validator, ValidatorContext};

use ahash::AHashSet;
use libp2p::PeerId;
use libp2p_identity::PeerId;
use schnellru::{ByLength, LruMap};

use prometheus_endpoint::{register, Counter, PrometheusError, Registry, U64};
Expand Down Expand Up @@ -521,8 +521,8 @@ impl Metrics {
#[cfg(test)]
mod tests {
use super::*;
use crate::multiaddr::Multiaddr;
use futures::prelude::*;
use multiaddr::Multiaddr;
use sc_network::{
config::MultiaddrWithPeerId, event::Event, NetworkBlock, NetworkEventStream,
NetworkNotification, NetworkPeers, NotificationSenderError,
Expand Down
2 changes: 1 addition & 1 deletion client/network-gossip/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use libp2p::PeerId;
use libp2p_identity::PeerId;
use sc_network_common::role::ObservedRole;
use sp_runtime::traits::Block as BlockT;

Expand Down
58 changes: 30 additions & 28 deletions client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,28 @@ async-channel = "1"
async-trait = "0.1"
asynchronous-codec = "0.6"
bytes = "1"
codec = { package = "parity-scale-codec", version = "3", features = ["derive"] }
either = "1"
fnv = "1"
futures = "0.3"
futures-timer = "3"
ip_network = "0.4"
libp2p = { version = "0.51", features = ["dns", "identify", "kad", "macros", "mdns", "noise", "ping", "tcp", "tokio", "yamux", "websocket", "request-response"] }
linked_hash_set = "0.1"
log = "0.4"
mockall = "0.11"
parking_lot = "0.12"
partial_sort = "0.2"
pin-project = "1"
rand = "0.8"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
smallvec = "1"
thiserror = "1"
unsigned-varint = { version = "0.7", features = ["futures", "asynchronous_codec"] }
zeroize = "1"
codec = { package = "parity-scale-codec", version = "3.6.1", features = ["derive"] }
either = "1.5.3"
fnv = "1.0.6"
futures = "0.3.21"
futures-timer = "3.0.2"
ip_network = "0.4.1"
libp2p = { version = "0.52.1", features = ["dns", "identify", "kad", "macros", "mdns", "noise", "ping", "tcp", "tokio", "yamux", "websocket", "request-response"] }
libp2p-kad = { version = "0.44.2" }
linked_hash_set = "0.1.3"
log = "0.4.17"
mockall = "0.11.3"
parking_lot = "0.12.1"
partial_sort = "0.2.0"
pin-project = "1.0.12"
rand = "0.8.5"
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.85"
smallvec = "1.11.0"
thiserror = "1.0"
unsigned-varint = { version = "0.7.1", features = ["futures", "asynchronous_codec"] }
void = "1"
zeroize = "1.4.3"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../utils/prometheus" }
sc-client-api = { version = "4.0.0-dev", path = "../api" }
sc-network-common = { version = "0.10.0-dev", path = "./common" }
Expand All @@ -50,14 +52,14 @@ sp-runtime = { version = "24", path = "../../primitives/runtime" }
wasm-timer = "0.2"

[dev-dependencies]
assert_matches = "1"
mockall = "0.11"
multistream-select = "0.12"
rand = "0.8"
tempfile = "3"
tokio = { version = "1", features = ["macros"] }
tokio-util = { version = "0.7", features = ["compat"] }
tokio-test = "0.4"
assert_matches = "1.3"
mockall = "0.11.3"
multistream-select = "0.13.0"
rand = "0.8.5"
tempfile = "3.1.0"
tokio = { version = "1.22.0", features = ["macros"] }
tokio-util = { version = "0.7.4", features = ["compat"] }
tokio-test = "0.4.2"
sc-network-light = { version = "0.10.0-dev", path = "./light" }
sc-network-sync = { version = "0.10.0-dev", path = "./sync" }
sp-test-primitives = { version = "2", path = "../../primitives/test-primitives" }
Expand Down
8 changes: 4 additions & 4 deletions client/network/bitswap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ prost-build = "0.11"

[dependencies]
async-channel = "1.8.0"
cid = "0.9"
futures = "0.3"
libp2p-identity = { version = "0.1", features = ["peerid"] }
log = "0.4"
cid = "0.9.0"
futures = "0.3.21"
libp2p-identity = { version = "0.2.0", features = ["peerid"] }
log = "0.4.17"
prost = "0.11"
thiserror = "1.0"
unsigned-varint = { version = "0.7.1", features = ["futures", "asynchronous_codec"] }
Expand Down
Loading

0 comments on commit 6fc5b71

Please sign in to comment.