From 6352780d6aaa705a8f1927c2c56c2dd06bb15265 Mon Sep 17 00:00:00 2001 From: Antioch Peverell Date: Tue, 30 Apr 2019 20:25:19 +0100 Subject: [PATCH] Bump rand crate to 0.6 (was 0.5) (#2790) shuffle was deprecated, fix this up --- Cargo.lock | 18 +++++++++--------- chain/Cargo.toml | 2 +- config/Cargo.toml | 2 +- core/Cargo.toml | 2 +- keychain/Cargo.toml | 2 +- p2p/Cargo.toml | 3 +-- p2p/src/peers.rs | 9 +++++---- p2p/src/store.rs | 5 +++-- pool/Cargo.toml | 2 +- servers/Cargo.toml | 2 +- servers/src/grin/seed.rs | 5 +++-- store/Cargo.toml | 2 +- util/Cargo.toml | 2 +- 13 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5a11e8991..0e13c3fd1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -698,7 +698,7 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", @@ -714,7 +714,7 @@ dependencies = [ "grin_servers 1.1.0-beta.2", "grin_util 1.1.0-beta.2", "pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -738,7 +738,7 @@ dependencies = [ "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", @@ -758,7 +758,7 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "pbkdf2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "ripemd160 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", @@ -783,7 +783,7 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -802,7 +802,7 @@ dependencies = [ "grin_store 1.1.0-beta.2", "grin_util 1.1.0-beta.2", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -842,7 +842,7 @@ dependencies = [ "itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "lmdb-zero 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", @@ -866,7 +866,7 @@ dependencies = [ "lmdb-zero 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -883,7 +883,7 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "log4rs 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/chain/Cargo.toml b/chain/Cargo.toml index 8cdeeee09..cc39000ef 100644 --- a/chain/Cargo.toml +++ b/chain/Cargo.toml @@ -30,4 +30,4 @@ grin_util = { path = "../util", version = "1.1.0-beta.2" } [dev-dependencies] env_logger = "0.5" -rand = "0.5" +rand = "0.6" diff --git a/config/Cargo.toml b/config/Cargo.toml index a3f256822..bb14ee88d 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -10,7 +10,7 @@ workspace = ".." edition = "2018" [dependencies] -rand = "0.5" +rand = "0.6" serde = "1" serde_derive = "1" toml = "0.4" diff --git a/core/Cargo.toml b/core/Cargo.toml index a3618702e..dcb53fab3 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -20,7 +20,7 @@ lazy_static = "1" lru-cache = "0.1" num = "0.2" num-bigint = "0.2" -rand = "0.5" +rand = "0.6" serde = "1" serde_derive = "1" siphasher = "0.2" diff --git a/keychain/Cargo.toml b/keychain/Cargo.toml index 52232f1b3..f9fbc6fa5 100644 --- a/keychain/Cargo.toml +++ b/keychain/Cargo.toml @@ -12,7 +12,7 @@ edition = "2018" [dependencies] byteorder = "1" blake2-rfc = "0.2" -rand = "0.5" +rand = "0.6" log = "0.4" serde = "1" serde_derive = "1" diff --git a/p2p/Cargo.toml b/p2p/Cargo.toml index c1a2d0021..1779617f9 100644 --- a/p2p/Cargo.toml +++ b/p2p/Cargo.toml @@ -15,7 +15,7 @@ bytes = "0.4" enum_primitive = "0.1" net2 = "0.2" num = "0.1" -rand = "0.5" +rand = "0.6" serde = "1" serde_derive = "1" log = "0.4" @@ -28,4 +28,3 @@ grin_chain = { path = "../chain", version = "1.1.0-beta.2" } [dev-dependencies] grin_pool = { path = "../pool", version = "1.1.0-beta.2" } - diff --git a/p2p/src/peers.rs b/p2p/src/peers.rs index 6b5986b6b..3865f8c45 100644 --- a/p2p/src/peers.rs +++ b/p2p/src/peers.rs @@ -18,7 +18,8 @@ use std::fs::File; use std::path::PathBuf; use std::sync::Arc; -use rand::{thread_rng, Rng}; +use rand::seq::SliceRandom; +use rand::thread_rng; use crate::chain; use crate::core::core; @@ -100,7 +101,7 @@ impl Peers { .filter(|p| p.is_connected()) .cloned() .collect::>(); - thread_rng().shuffle(&mut res); + res.shuffle(&mut thread_rng()); res } @@ -141,7 +142,7 @@ impl Peers { .filter(|x| x.info.total_difficulty() > total_difficulty) .collect::>(); - thread_rng().shuffle(&mut max_peers); + max_peers.shuffle(&mut thread_rng()); Ok(max_peers) } @@ -190,7 +191,7 @@ impl Peers { .filter(|x| x.info.total_difficulty() == max_total_difficulty) .collect::>(); - thread_rng().shuffle(&mut max_peers); + max_peers.shuffle(&mut thread_rng()); max_peers } diff --git a/p2p/src/store.rs b/p2p/src/store.rs index 46faa6dc6..9c75b56e6 100644 --- a/p2p/src/store.rs +++ b/p2p/src/store.rs @@ -16,7 +16,8 @@ use chrono::Utc; use num::FromPrimitive; -use rand::{thread_rng, Rng}; +use rand::seq::SliceRandom; +use rand::thread_rng; use crate::core::ser::{self, Readable, Reader, Writeable, Writer}; use crate::types::{Capabilities, PeerAddr, ReasonForBan}; @@ -158,7 +159,7 @@ impl PeerStore { .map(|(_, v)| v) .filter(|p| p.flags == state && p.capabilities.contains(cap)) .collect::>(); - thread_rng().shuffle(&mut peers[..]); + peers[..].shuffle(&mut thread_rng()); Ok(peers.iter().take(count).cloned().collect()) } diff --git a/pool/Cargo.toml b/pool/Cargo.toml index 979fad272..5b6902de8 100644 --- a/pool/Cargo.toml +++ b/pool/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" [dependencies] blake2-rfc = "0.2" -rand = "0.5" +rand = "0.6" serde = "1" serde_derive = "1" log = "0.4" diff --git a/servers/Cargo.toml b/servers/Cargo.toml index 0d19846c0..867cbffef 100644 --- a/servers/Cargo.toml +++ b/servers/Cargo.toml @@ -17,7 +17,7 @@ futures = "0.1" http = "0.1" itertools = "0.7" lmdb-zero = "0.4.4" -rand = "0.5" +rand = "0.6" serde = "1" log = "0.4" serde_derive = "1" diff --git a/servers/src/grin/seed.rs b/servers/src/grin/seed.rs index 703718775..cda246254 100644 --- a/servers/src/grin/seed.rs +++ b/servers/src/grin/seed.rs @@ -19,7 +19,8 @@ use chrono::prelude::{DateTime, Utc}; use chrono::{Duration, MIN_DATE}; -use rand::{thread_rng, Rng}; +use rand::seq::SliceRandom; +use rand::thread_rng; use std::collections::HashMap; use std::net::ToSocketAddrs; use std::sync::{mpsc, Arc}; @@ -221,7 +222,7 @@ fn monitor_peers( // take a random defunct peer and mark it healthy: over a long period any // peer will see another as defunct eventually, gives us a chance to retry if defuncts.len() > 0 { - thread_rng().shuffle(&mut defuncts); + defuncts.shuffle(&mut thread_rng()); let _ = peers.update_state(defuncts[0].addr, p2p::State::Healthy); } diff --git a/store/Cargo.toml b/store/Cargo.toml index 4c4c05cd8..fdff6954b 100644 --- a/store/Cargo.toml +++ b/store/Cargo.toml @@ -27,5 +27,5 @@ grin_util = { path = "../util", version = "1.1.0-beta.2" } [dev-dependencies] chrono = "0.4.4" -rand = "0.5" +rand = "0.6" filetime = "0.2" diff --git a/util/Cargo.toml b/util/Cargo.toml index 537f36025..d256bd2ab 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -14,7 +14,7 @@ backtrace = "0.3" base64 = "0.9" byteorder = "1" lazy_static = "1" -rand = "0.5" +rand = "0.6" serde = "1" serde_derive = "1" log4rs = { version = "0.8.1", features = ["rolling_file_appender", "compound_policy", "size_trigger", "fixed_window_roller"] }