Skip to content

Commit f02dfa2

Browse files
build(deps): bump rand from 0.8.5 to 0.9.0 (#5964)
* build(deps): bump rand from 0.8.5 to 0.9.0 Bumps [rand](https://github.com/rust-random/rand) from 0.8.5 to 0.9.0. - [Release notes](https://github.com/rust-random/rand/releases) - [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md) - [Commits](rust-random/rand@0.8.5...0.9.0) --- updated-dependencies: - dependency-name: rand dependency-version: 0.9.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * fix api changes * fix example changes --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Filipe Azevedo <[email protected]>
1 parent fc08039 commit f02dfa2

File tree

12 files changed

+61
-68
lines changed

12 files changed

+61
-68
lines changed

Cargo.lock

+10-31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ wasmtime = "15.0.1"
9494
substreams = "=0.6.0"
9595
substreams-entity-change = "2"
9696
substreams-near-core = "=0.10.2"
97+
rand = { version = "0.9.1", features = ["os_rng"] }
9798

9899
# Incremental compilation on Rust 1.58 causes an ICE on build. As soon as graph node builds again, these can be removed.
99100
[profile.test]

chain/ethereum/src/network.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,9 @@ impl EthereumNetworkAdapters {
196196
required_capabilities: &NodeCapabilities,
197197
retest_percent: f64,
198198
) -> Result<Arc<EthereumAdapter>, Error> {
199-
let retest_rng: f64 = (&mut rand::thread_rng()).gen();
199+
let retest_rng: f64 = (&mut rand::rng()).random();
200200

201-
let cheapest = input
202-
.into_iter()
203-
.choose_multiple(&mut rand::thread_rng(), 3);
201+
let cheapest = input.into_iter().choose_multiple(&mut rand::rng(), 3);
204202
let cheapest = cheapest.iter();
205203

206204
// If request falls below the retest threshold, use this request to try and
@@ -231,7 +229,7 @@ impl EthereumNetworkAdapters {
231229
let cheapest = self.all_unverified_cheapest_with(required_capabilities);
232230

233231
Self::cheapest_from(
234-
cheapest.choose_multiple(&mut rand::thread_rng(), 3),
232+
cheapest.choose_multiple(&mut rand::rng(), 3),
235233
required_capabilities,
236234
self.retest_percent,
237235
)
@@ -245,7 +243,7 @@ impl EthereumNetworkAdapters {
245243
let cheapest = self
246244
.all_cheapest_with(required_capabilities)
247245
.await
248-
.choose_multiple(&mut rand::thread_rng(), 3);
246+
.choose_multiple(&mut rand::rng(), 3);
249247

250248
Self::cheapest_from(cheapest, required_capabilities, self.retest_percent)
251249
}

graph/Cargo.toml

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ atomic_refcell = "0.1.13"
1212
# We require this precise version of bigdecimal. Updating to later versions
1313
# has caused PoI differences; if you update this version, you will need to
1414
# make sure that it does not cause PoI changes
15-
old_bigdecimal = { version = "=0.1.2", features = ["serde"], package = "bigdecimal" }
15+
old_bigdecimal = { version = "=0.1.2", features = [
16+
"serde",
17+
], package = "bigdecimal" }
1618
bytes = "1.0.1"
1719
bs58 = { workspace = true }
1820
cid = "0.11.1"
@@ -40,7 +42,7 @@ lazy_static = "1.5.0"
4042
num-bigint = { version = "=0.2.6", features = ["serde"] }
4143
num-integer = { version = "=0.1.46" }
4244
num-traits = "=0.2.19"
43-
rand = "0.8.4"
45+
rand.workspace = true
4446
regex = "1.5.4"
4547
semver = { version = "1.0.23", features = ["serde"] }
4648
serde = { workspace = true }
@@ -93,7 +95,8 @@ defer = "0.2"
9395
# Our fork contains patches to make some fields optional for Celo and Fantom compatibility.
9496
# Without the "arbitrary_precision" feature, we get the error `data did not match any variant of untagged enum Response`.
9597
web3 = { git = "https://github.com/graphprotocol/rust-web3", branch = "graph-patches-onto-0.18", features = [
96-
"arbitrary_precision", "test"
98+
"arbitrary_precision",
99+
"test",
97100
] }
98101
serde_plain = "1.0.2"
99102
csv = "1.3.0"

graph/examples/stress.rs

+28-14
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use clap::Parser;
99
use graph::data::value::{Object, Word};
1010
use graph::object;
1111
use graph::prelude::{lazy_static, q, r, BigDecimal, BigInt, QueryResult};
12-
use rand::SeedableRng;
1312
use rand::{rngs::SmallRng, Rng};
13+
use rand::{RngCore, SeedableRng};
1414

1515
use graph::util::cache_weight::CacheWeight;
1616
use graph::util::lfu_cache::LfuCache;
@@ -240,8 +240,8 @@ impl Template for BigInt {
240240
fn create(size: usize, rng: Option<&mut SmallRng>) -> Self {
241241
let f = match rng {
242242
Some(rng) => {
243-
let mag = rng.gen_range(1..100);
244-
if rng.gen_bool(0.5) {
243+
let mag = rng.random_range(1..100);
244+
if rng.random_bool(0.5) {
245245
mag
246246
} else {
247247
-mag
@@ -261,8 +261,8 @@ impl Template for BigDecimal {
261261
fn create(size: usize, mut rng: Option<&mut SmallRng>) -> Self {
262262
let f = match rng.as_deref_mut() {
263263
Some(rng) => {
264-
let mag = rng.gen_range(1i32..100);
265-
if rng.gen_bool(0.5) {
264+
let mag = rng.random_range(1i32..100);
265+
if rng.random_bool(0.5) {
266266
mag
267267
} else {
268268
-mag
@@ -271,7 +271,7 @@ impl Template for BigDecimal {
271271
None => 1,
272272
};
273273
let exp = match rng {
274-
Some(rng) => rng.gen_range(-100..=100),
274+
Some(rng) => rng.random_range(-100..=100),
275275
None => 1,
276276
};
277277
let bi = BigInt::from(3u64).pow(size as u8).unwrap() * BigInt::from(f);
@@ -307,7 +307,7 @@ fn make_object(size: usize, mut rng: Option<&mut SmallRng>) -> Object {
307307
for i in 0..size {
308308
let kind = rng
309309
.as_deref_mut()
310-
.map(|rng| rng.gen_range(0..modulus))
310+
.map(|rng| rng.random_range(0..modulus))
311311
.unwrap_or(i % modulus);
312312

313313
let value = match kind {
@@ -334,7 +334,11 @@ fn make_object(size: usize, mut rng: Option<&mut SmallRng>) -> Object {
334334
_ => unreachable!(),
335335
};
336336

337-
let key = rng.as_deref_mut().map(|rng| rng.gen()).unwrap_or(i) % modulus;
337+
let key = rng
338+
.as_deref_mut()
339+
.map(|rng| rng.next_u32() as usize)
340+
.unwrap_or(i)
341+
% modulus;
338342
obj.push((Word::from(format!("val{}", key)), value));
339343
}
340344
Object::from_iter(obj)
@@ -406,7 +410,7 @@ impl ValueMap {
406410
for i in 0..size {
407411
let kind = rng
408412
.as_deref_mut()
409-
.map(|rng| rng.gen_range(0..modulus))
413+
.map(|rng| rng.random_range(0..modulus))
410414
.unwrap_or(i % modulus);
411415

412416
let value = match kind {
@@ -431,7 +435,11 @@ impl ValueMap {
431435
_ => unreachable!(),
432436
};
433437

434-
let key = rng.as_deref_mut().map(|rng| rng.gen()).unwrap_or(i) % modulus;
438+
let key = rng
439+
.as_deref_mut()
440+
.map(|rng| rng.next_u32() as usize)
441+
.unwrap_or(i)
442+
% modulus;
435443
map.insert(format!("val{}", key), value);
436444
}
437445
MapMeasure(map)
@@ -466,7 +474,10 @@ impl UsizeMap {
466474
fn make_map(size: usize, mut rng: Option<&mut SmallRng>) -> Self {
467475
let mut map = BTreeMap::new();
468476
for i in 0..size {
469-
let key = rng.as_deref_mut().map(|rng| rng.gen()).unwrap_or(2 * i);
477+
let key = rng
478+
.as_deref_mut()
479+
.map(|rng| rng.next_u32() as usize)
480+
.unwrap_or(2 * i);
470481
map.insert(key, i * 3);
471482
}
472483
MapMeasure(map)
@@ -563,7 +574,10 @@ fn maybe_rng<'a>(opt: &'a Opt, rng: &'a mut SmallRng) -> Option<&'a mut SmallRng
563574

564575
fn stress<T: Template>(opt: &Opt) {
565576
let mut rng = match opt.seed {
566-
None => SmallRng::from_entropy(),
577+
None => {
578+
let mut rng = rand::rng();
579+
SmallRng::from_rng(&mut rng)
580+
}
567581
Some(seed) => SmallRng::seed_from_u64(seed),
568582
};
569583

@@ -624,7 +638,7 @@ fn stress<T: Template>(opt: &Opt) {
624638
let size = if opt.fixed || opt.obj_size == 0 {
625639
opt.obj_size
626640
} else {
627-
rng.gen_range(0..opt.obj_size)
641+
rng.random_range(0..opt.obj_size)
628642
};
629643
let before = ALLOCATED.load(SeqCst);
630644
let sample = template.sample(size, maybe_rng(opt, &mut rng));
@@ -638,7 +652,7 @@ fn stress<T: Template>(opt: &Opt) {
638652
cache.insert(key, Entry::from(*sample));
639653
// Do a few random reads from the cache
640654
for _attempt in 0..5 {
641-
let read = rng.gen_range(0..=key);
655+
let read = rng.random_range(0..=key);
642656
let _v = cache.get(&read);
643657
}
644658
}

graph/src/data/graphql/load_manager.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Utilities to keep moving statistics about queries
22
33
use prometheus::core::GenericCounter;
4-
use rand::{prelude::Rng, thread_rng};
4+
use rand::{prelude::Rng, rng};
55
use std::collections::{HashMap, HashSet};
66
use std::iter::FromIterator;
77
use std::sync::{Arc, RwLock};
@@ -439,7 +439,7 @@ impl LoadManager {
439439
// that cause at least 20% of the effort
440440
let kill_rate = self.update_kill_rate(shard, kill_rate, last_update, overloaded, wait_ms);
441441
let decline =
442-
thread_rng().gen_bool((kill_rate * query_effort / total_effort).min(1.0).max(0.0));
442+
rng().random_bool((kill_rate * query_effort / total_effort).min(1.0).max(0.0));
443443
if decline {
444444
if ENV_VARS.load_simulate {
445445
debug!(self.logger, "Declining query";

graph/src/data/subgraph/schema.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use anyhow::{anyhow, bail, Error};
44
use chrono::{DateTime, Utc};
55
use hex;
66
use rand::rngs::OsRng;
7-
use rand::Rng;
7+
use rand::TryRngCore as _;
88
use std::collections::BTreeSet;
99
use std::str::FromStr;
1010
use std::{fmt, fmt::Display};
@@ -272,11 +272,9 @@ impl_stable_hash!(SubgraphError {
272272
});
273273

274274
pub fn generate_entity_id() -> String {
275-
// Fast crypto RNG from operating system
276-
let mut rng = OsRng::default();
277-
278275
// 128 random bits
279-
let id_bytes: [u8; 16] = rng.gen();
276+
let mut id_bytes = [0u8; 16];
277+
OsRng.try_fill_bytes(&mut id_bytes).unwrap();
280278

281279
// 32 hex chars
282280
// Comparable to uuidv4, but without the hyphens,

graph/src/util/backoff.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl ExponentialBackoff {
5151
if delay > self.ceiling {
5252
delay = self.ceiling;
5353
}
54-
let jitter = rand::Rng::gen_range(&mut rand::thread_rng(), -self.jitter..=self.jitter);
54+
let jitter = rand::Rng::random_range(&mut rand::rng(), -self.jitter..=self.jitter);
5555
delay.mul_f64(1.0 + jitter)
5656
}
5757

runtime/test/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ graph = { path = "../../graph" }
1010
graph-chain-ethereum = { path = "../../chain/ethereum" }
1111
graph-runtime-derive = { path = "../derive" }
1212
graph-runtime-wasm = { path = "../wasm" }
13-
rand = "0.8.5"
13+
rand.workspace = true
1414

1515

1616
[dev-dependencies]

runtime/test/src/test_padding.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const WASM_FILE_NAME: &str = "test_padding.wasm";
88

99
//for tests, to run in parallel, sub graph name has be unique
1010
fn rnd_sub_graph_name(size: usize) -> String {
11-
use rand::{distributions::Alphanumeric, Rng};
12-
rand::thread_rng()
11+
use rand::{distr::Alphanumeric, Rng};
12+
rand::rng()
1313
.sample_iter(&Alphanumeric)
1414
.take(size)
1515
.map(char::from)

store/postgres/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ maybe-owned = "0.3.4"
2323
postgres = "0.19.1"
2424
openssl = "0.10.72"
2525
postgres-openssl = "0.5.1"
26-
rand = "0.8.4"
26+
rand.workspace = true
2727
serde = { workspace = true }
2828
serde_json = { workspace = true }
2929
stable-hash_legacy = { git = "https://github.com/graphprotocol/stable-hash", branch = "old", package = "stable-hash" }

0 commit comments

Comments
 (0)