Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): Bump rand to 0.8 and quickcheck to 1 #2857

Merged
merged 37 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e482d91
Upgrade to rand 0.8
kpp Aug 30, 2022
23c65e7
Fix compiler warning
kpp Aug 30, 2022
94634c2
Upgrade tests to quickcheck=1
kpp Aug 31, 2022
7ac75e9
cargo fmt
kpp Aug 31, 2022
f1e4833
Remove rand dep from dev workspace
kpp Aug 31, 2022
a36e551
Remove Rng param from fn random_peers
kpp Aug 31, 2022
cff5192
Fix kad:rand_distance test
kpp Sep 1, 2022
7dd2ab6
Fix kad:bucket_contains_range test
kpp Sep 1, 2022
d805059
Fix kad:closest_and_disjoint_closest_yield_same_result test
kpp Sep 1, 2022
c092d1b
Fix swarm:score_retention test
kpp Sep 2, 2022
ea2e1ab
Merge branch 'master' into rand08
kpp Sep 2, 2022
f6f6899
Apply suggestions from code review for over/under-flow
kpp Sep 2, 2022
55ed655
cargo fmt
kpp Sep 2, 2022
cc64494
Introduce quickcheck-ext crate with Gen::gen_range
kpp Sep 6, 2022
3757134
Use ::gen_range to generate a random number in .. range
kpp Sep 6, 2022
b48c9a1
cargo fmt
kpp Sep 6, 2022
821bb52
Fix multistream:encode_decode_message test
kpp Sep 6, 2022
3e84211
Add a license to quickcheck-ext
kpp Sep 6, 2022
b0a8cda
Merge branch 'master' into rand08
kpp Sep 6, 2022
f695aac
More unsigned types for gen_range
kpp Sep 6, 2022
f79b939
Add T: Unsigned for gen_range
kpp Sep 6, 2022
7cb1c80
More unsigned types for gen_range
kpp Sep 6, 2022
a3fa247
Merge branch 'master' into rand08
thomaseizinger Sep 8, 2022
25f87c5
Fix build error
thomaseizinger Sep 8, 2022
6a34f5c
Merge branch 'master' into rand08
kpp Sep 12, 2022
49d2aa3
Bump versions and add changelog entries
kpp Sep 12, 2022
1b08ba5
Apply suggestions from code review: CHANGELOG [unreleased]
kpp Sep 15, 2022
17182b9
Bump versions and add changelog entries
kpp Sep 15, 2022
8205887
Merge branch 'master' into rand08
kpp Sep 15, 2022
c4d6e6e
Make kad:closest tests deterministic
kpp Sep 15, 2022
e0d783e
Make kad:closest:disjoint:random_peers deterministic
kpp Sep 15, 2022
bc77431
Make kad:closest:disjoint tests deterministic
kpp Sep 15, 2022
aa5427e
::choose_multiple returns an iter instead of vec
kpp Sep 16, 2022
5bd92fc
Make kad:disjoint:PeerVec::arbitrary deterministic
kpp Sep 16, 2022
a14caab
Merge branch 'master' into rand08
kpp Sep 16, 2022
fa17190
Merge branch 'master' into rand08
kpp Sep 21, 2022
44e80e2
Fix kad:rand_distance test
kpp Sep 21, 2022
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
# 0.49.0 - [unreleased]

- Update to [`libp2p-tcp` `v0.37.0`](transports/tcp/CHANGELOG.md#0370).
- Update individual crates.
- Update to [`libp2p-kad` `v0.40.1`](protocols/kad/CHANGELOG.md#???).
- Update to [`libp2p-ping` `v0.39.1`](protocols/ping/CHANGELOG.md#???).
- Update to [`libp2p-request-response` `v0.21.1`](protocols/request-response/CHANGELOG.md#???).
- Update to [`libp2p-pnet` `v0.22.1`](transports/pnet/CHANGELOG.md#???).
- Update to [`libp2p-mplex` `v0.36.1`](muxers/mplex/CHANGELOG.md#???).
- Update to [`libp2p-swarm` `v0.39.1`](swarm/CHANGELOG.md#???).

# 0.48.0

Expand Down
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ rendezvous = ["dep:libp2p-rendezvous"]
tcp-async-io = ["dep:libp2p-tcp", "libp2p-tcp?/async-io"]
tcp-tokio = ["dep:libp2p-tcp", "libp2p-tcp?/tokio"]
uds = ["dep:libp2p-uds"]
wasm-bindgen = ["futures-timer/wasm-bindgen", "instant/wasm-bindgen", "getrandom/js", "rand/wasm-bindgen"]
wasm-bindgen = ["futures-timer/wasm-bindgen", "instant/wasm-bindgen", "getrandom/js"]
wasm-ext = ["dep:libp2p-wasm-ext"]
wasm-ext-websocket = ["wasm-ext", "libp2p-wasm-ext?/websocket"]
websocket = ["dep:libp2p-websocket"]
Expand All @@ -85,25 +85,24 @@ libp2p-core = { version = "0.36.0", path = "core", default-features = false }
libp2p-dcutr = { version = "0.6.0", path = "protocols/dcutr", optional = true }
libp2p-floodsub = { version = "0.39.0", path = "protocols/floodsub", optional = true }
libp2p-identify = { version = "0.39.0", path = "protocols/identify", optional = true }
libp2p-kad = { version = "0.40.0", path = "protocols/kad", optional = true }
libp2p-kad = { version = "0.40.1", path = "protocols/kad", optional = true }
libp2p-metrics = { version = "0.9.0", path = "misc/metrics", optional = true }
libp2p-mplex = { version = "0.36.0", path = "muxers/mplex", optional = true }
libp2p-mplex = { version = "0.36.1", path = "muxers/mplex", optional = true }
libp2p-noise = { version = "0.39.0", path = "transports/noise", optional = true }
libp2p-ping = { version = "0.39.0", path = "protocols/ping", optional = true }
libp2p-ping = { version = "0.39.1", path = "protocols/ping", optional = true }
libp2p-plaintext = { version = "0.36.0", path = "transports/plaintext", optional = true }
libp2p-pnet = { version = "0.22.0", path = "transports/pnet", optional = true }
libp2p-pnet = { version = "0.22.1", path = "transports/pnet", optional = true }
libp2p-relay = { version = "0.12.0", path = "protocols/relay", optional = true }
libp2p-rendezvous = { version = "0.9.0", path = "protocols/rendezvous", optional = true }
libp2p-request-response = { version = "0.21.0", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.39.0", path = "swarm" }
libp2p-request-response = { version = "0.21.1", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.39.1", path = "swarm" }
libp2p-swarm-derive = { version = "0.30.0", path = "swarm-derive" }
libp2p-uds = { version = "0.35.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.36.0", path = "transports/wasm-ext", default-features = false, optional = true }
libp2p-yamux = { version = "0.40.0", path = "muxers/yamux", optional = true }
multiaddr = { version = "0.14.0" }
parking_lot = "0.12.0"
pin-project = "1.0.0"
rand = "0.7.3" # Explicit dependency to be used in `wasm-bindgen` feature
smallvec = "1.6.1"

[target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies]
Expand Down Expand Up @@ -131,6 +130,7 @@ members = [
"misc/rw-stream-sink",
"misc/keygen",
"misc/prost-codec",
"misc/quickcheck-ext",
"muxers/mplex",
"muxers/yamux",
"protocols/dcutr",
Expand Down
3 changes: 1 addition & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ libp2p-mplex = { path = "../muxers/mplex" }
libp2p-noise = { path = "../transports/noise" }
libp2p-tcp = { path = "../transports/tcp" }
multihash = { version = "0.16", default-features = false, features = ["arb"] }
quickcheck = "0.9.0"
rand07 = { package = "rand", version = "0.7" }
quickcheck = { package = "quickcheck-ext", path = "../misc/quickcheck-ext" }
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
rmp-serde = "1.0"
serde_json = "1.0"

Expand Down
5 changes: 2 additions & 3 deletions core/src/identity/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ impl DerDecodable<'_> for Asn1SubjectPublicKeyInfo {
mod tests {
use super::*;
use quickcheck::*;
use rand07::seq::SliceRandom;
use std::fmt;

const KEY1: &'static [u8] = include_bytes!("test/rsa-2048.pk8");
Expand All @@ -323,8 +322,8 @@ mod tests {
}

impl Arbitrary for SomeKeypair {
fn arbitrary<G: Gen>(g: &mut G) -> SomeKeypair {
let mut key = [KEY1, KEY2, KEY3].choose(g).unwrap().to_vec();
fn arbitrary(g: &mut Gen) -> SomeKeypair {
let mut key = g.choose(&[KEY1, KEY2, KEY3]).unwrap().to_vec();
SomeKeypair(Keypair::from_pkcs8(&mut key).unwrap())
}
}
Expand Down
4 changes: 2 additions & 2 deletions misc/multistream-select/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ libp2p-core = { path = "../../core", default-features = false }
libp2p-swarm = { path = "../../swarm", default-features = false }
libp2p-mplex = { path = "../../muxers/mplex" }
libp2p-plaintext = { path = "../../transports/plaintext" }
quickcheck = "0.9.0"
rand = "0.7.2"
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
rand = "0.8"
rw-stream-sink = { version = "0.3.0", path = "../../misc/rw-stream-sink" }
13 changes: 6 additions & 7 deletions misc/multistream-select/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,24 +455,23 @@ impl fmt::Display for ProtocolError {
mod tests {
use super::*;
use quickcheck::*;
use rand::distributions::Alphanumeric;
use rand::Rng;
use std::iter;

impl Arbitrary for Protocol {
fn arbitrary<G: Gen>(g: &mut G) -> Protocol {
let n = g.gen_range(1, g.size());
fn arbitrary(g: &mut Gen) -> Protocol {
let n = g.gen_range(1..g.size());
let p: String = iter::repeat(())
.map(|()| g.sample(Alphanumeric))
.map(|()| char::arbitrary(g))
.filter(|&c| c.is_ascii_alphanumeric())
.take(n)
.collect();
Protocol(Bytes::from(format!("/{}", p)))
}
}

impl Arbitrary for Message {
fn arbitrary<G: Gen>(g: &mut G) -> Message {
match g.gen_range(0, 5) {
fn arbitrary(g: &mut Gen) -> Message {
match g.gen_range(0..5u8) {
0 => Message::Header(HeaderLine::V1),
1 => Message::NotAvailable,
2 => Message::ListProtocols,
Expand Down
10 changes: 10 additions & 0 deletions misc/quickcheck-ext/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "quickcheck-ext"
version = "0.1.0"
edition = "2021"
publish = false
license = "Unlicense/MIT"

[dependencies]
quickcheck = "1"
num-traits = "0.2"
14 changes: 14 additions & 0 deletions misc/quickcheck-ext/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub use quickcheck::*;

use core::ops::Range;
use num_traits::sign::Unsigned;

pub trait GenRange {
fn gen_range<T: Unsigned + Arbitrary + Copy>(&mut self, _range: Range<T>) -> T;
}

impl GenRange for Gen {
fn gen_range<T: Unsigned + Arbitrary + Copy>(&mut self, range: Range<T>) -> T {
<T as Arbitrary>::arbitrary(self) % (range.end - range.start) + range.start
}
}
6 changes: 6 additions & 0 deletions muxers/mplex/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.36.1
kpp marked this conversation as resolved.
Show resolved Hide resolved

- Bump rand to 0.8 and quickcheck to 1. See [PR 2857].

[PR 2857]: https://github.com/libp2p/rust-libp2p/pull/2857

# 0.36.0

- Update to `libp2p-core` `v0.36.0`
Expand Down
7 changes: 3 additions & 4 deletions muxers/mplex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-mplex"
edition = "2021"
rust-version = "1.56.1"
description = "Mplex multiplexing protocol for libp2p"
version = "0.36.0"
version = "0.36.1"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -18,7 +18,7 @@ libp2p-core = { version = "0.36.0", path = "../../core", default-features = fals
log = "0.4"
nohash-hasher = "0.2"
parking_lot = "0.12"
rand = "0.7"
rand = "0.8"
kpp marked this conversation as resolved.
Show resolved Hide resolved
smallvec = "1.6.1"
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }

Expand All @@ -29,8 +29,7 @@ env_logger = "0.9"
futures = "0.3"
libp2p-tcp = { path = "../../transports/tcp" }
libp2p-plaintext = { path = "../../transports/plaintext" }
quickcheck = "0.9"
rand = "0.7"
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }

[[bench]]
name = "split_send_size"
Expand Down
14 changes: 6 additions & 8 deletions muxers/mplex/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,27 +1105,25 @@ mod tests {
use asynchronous_codec::{Decoder, Encoder};
use bytes::BytesMut;
use quickcheck::*;
use rand::prelude::*;
use std::collections::HashSet;
use std::num::NonZeroU8;
use std::ops::DerefMut;
use std::pin::Pin;

impl Arbitrary for MaxBufferBehaviour {
fn arbitrary<G: Gen>(g: &mut G) -> MaxBufferBehaviour {
*[MaxBufferBehaviour::Block, MaxBufferBehaviour::ResetStream]
.choose(g)
fn arbitrary(g: &mut Gen) -> MaxBufferBehaviour {
*g.choose(&[MaxBufferBehaviour::Block, MaxBufferBehaviour::ResetStream])
.unwrap()
}
}

impl Arbitrary for MplexConfig {
fn arbitrary<G: Gen>(g: &mut G) -> MplexConfig {
fn arbitrary(g: &mut Gen) -> MplexConfig {
MplexConfig {
max_substreams: g.gen_range(1, 100),
max_buffer_len: g.gen_range(1, 1000),
max_substreams: g.gen_range(1..100),
max_buffer_len: g.gen_range(1..1000),
max_buffer_behaviour: MaxBufferBehaviour::arbitrary(g),
split_send_size: g.gen_range(1, 10000),
split_send_size: g.gen_range(1..10000),
protocol_name: crate::config::DEFAULT_MPLEX_PROTOCOL_NAME,
}
}
Expand Down
2 changes: 1 addition & 1 deletion protocols/dcutr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ libp2p-identify = { path = "../identify" }
libp2p-plaintext = { path = "../../transports/plaintext" }
libp2p-relay = { path = "../relay" }
libp2p-yamux = { path = "../../muxers/yamux" }
rand = "0.7"
rand = "0.8"
clap = {version = "3.1.6", features = ["derive"]}
2 changes: 1 addition & 1 deletion protocols/floodsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ libp2p-core = { version = "0.36.0", path = "../../core", default-features = fals
libp2p-swarm = { version = "0.39.0", path = "../../swarm" }
log = "0.4"
prost = "0.11"
rand = "0.7"
rand = "0.8"
kpp marked this conversation as resolved.
Show resolved Hide resolved
smallvec = "1.6.1"

[build-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions protocols/gossipsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bytes = "1.0"
byteorder = "1.3.4"
fnv = "1.0.7"
futures = "0.3.5"
rand = "0.7.3"
rand = "0.8"
kpp marked this conversation as resolved.
Show resolved Hide resolved
asynchronous-codec = "0.6"
unsigned-varint = { version = "0.7.0", features = ["asynchronous_codec"] }
log = "0.4.11"
Expand All @@ -40,7 +40,7 @@ libp2p-plaintext = { path = "../../transports/plaintext" }
libp2p-yamux = { path = "../../muxers/yamux" }
libp2p-mplex = { path = "../../muxers/mplex" }
libp2p-noise = { path = "../../transports/noise" }
quickcheck = "0.9.2"
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }
hex = "0.4.2"
derive_builder = "0.11.1"

Expand Down
11 changes: 5 additions & 6 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3204,7 +3204,7 @@ where
debug!("Peer disconnected: {}", peer_id);
{
let topics = match self.peer_topics.get(peer_id) {
Some(topics) => (topics),
Some(topics) => topics,
None => {
debug_assert!(
self.blacklisted_peers.contains(peer_id),
Expand Down Expand Up @@ -3667,7 +3667,6 @@ mod local_test {
use crate::IdentTopic;
use asynchronous_codec::Encoder;
use quickcheck::*;
use rand::Rng;

fn empty_rpc() -> GossipsubRpc {
GossipsubRpc {
Expand Down Expand Up @@ -3704,16 +3703,16 @@ mod local_test {
}

impl Arbitrary for GossipsubRpc {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut Gen) -> Self {
let mut rpc = empty_rpc();

for _ in 0..g.gen_range(0, 10) {
for _ in 0..g.gen_range(0..10u8) {
rpc.subscriptions.push(test_subscription());
}
for _ in 0..g.gen_range(0, 10) {
for _ in 0..g.gen_range(0..10u8) {
rpc.messages.push(test_message());
}
for _ in 0..g.gen_range(0, 10) {
for _ in 0..g.gen_range(0..10u8) {
rpc.control_msgs.push(test_control());
}
rpc
Expand Down
4 changes: 2 additions & 2 deletions protocols/gossipsub/src/behaviour/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3293,12 +3293,12 @@ mod tests {
*seq += 1;
RawGossipsubMessage {
source: Some(PeerId::random()),
data: (0..rng.gen_range(10, 30))
data: (0..rng.gen_range(10..30))
.into_iter()
.map(|_| rng.gen())
.collect(),
sequence_number: Some(*seq),
topic: topics[rng.gen_range(0, topics.len())].clone(),
topic: topics[rng.gen_range(0..topics.len())].clone(),
signature: None,
key: None,
validated: true,
Expand Down
19 changes: 9 additions & 10 deletions protocols/gossipsub/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,12 @@ mod tests {
use crate::IdentTopic as Topic;
use libp2p_core::identity::Keypair;
use quickcheck::*;
use rand::Rng;

#[derive(Clone, Debug)]
struct Message(RawGossipsubMessage);

impl Arbitrary for Message {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut Gen) -> Self {
let keypair = TestKeypair::arbitrary(g);

// generate an arbitrary GossipsubMessage using the behaviour signing functionality
Expand All @@ -588,8 +587,8 @@ mod tests {
config,
)
.unwrap();
let data = (0..g.gen_range(10, 10024))
.map(|_| g.gen())
let data = (0..g.gen_range(10..10024u32))
.map(|_| u8::arbitrary(g))
.collect::<Vec<_>>();
let topic_id = TopicId::arbitrary(g).0;
Message(gs.build_raw_message(topic_id, data).unwrap())
Expand All @@ -600,9 +599,9 @@ mod tests {
struct TopicId(TopicHash);

impl Arbitrary for TopicId {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
let topic_string: String = (0..g.gen_range(20, 1024))
.map(|_| g.gen::<char>())
fn arbitrary(g: &mut Gen) -> Self {
let topic_string: String = (0..g.gen_range(20..1024u32))
.map(|_| char::arbitrary(g))
.collect::<String>()
.into();
TopicId(Topic::new(topic_string).into())
Expand All @@ -614,8 +613,8 @@ mod tests {

impl Arbitrary for TestKeypair {
#[cfg(feature = "rsa")]
fn arbitrary<G: Gen>(g: &mut G) -> Self {
let keypair = if g.gen() {
fn arbitrary(g: &mut Gen) -> Self {
let keypair = if bool::arbitrary(g) {
// Small enough to be inlined.
Keypair::generate_ed25519()
} else {
Expand All @@ -627,7 +626,7 @@ mod tests {
}

#[cfg(not(feature = "rsa"))]
fn arbitrary<G: Gen>(_g: &mut G) -> Self {
fn arbitrary(_g: &mut Gen) -> Self {
// Small enough to be inlined.
TestKeypair(Keypair::generate_ed25519())
}
Expand Down
6 changes: 6 additions & 0 deletions protocols/kad/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.40.1
kpp marked this conversation as resolved.
Show resolved Hide resolved

- Bump rand to 0.8 and quickcheck to 1. See [PR 2857].

[PR 2857]: https://github.com/libp2p/rust-libp2p/pull/2857

# 0.40.0

- Add support for multiple protocol names. Update `Kademlia`, `KademliaConfig`,
Expand Down
Loading