From 46056de6dc8d6b4fc3ff6dda41b1c7152476ecfb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Apr 2025 04:34:30 +0000 Subject: [PATCH 1/3] 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](https://github.com/rust-random/rand/compare/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] --- Cargo.lock | 6 +++--- graph/Cargo.toml | 2 +- runtime/test/Cargo.toml | 2 +- store/postgres/Cargo.toml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c47e24263ef..4422f7f048a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1903,7 +1903,7 @@ dependencies = [ "prometheus", "prost", "prost-types", - "rand 0.8.5", + "rand 0.9.0", "regex", "reqwest", "semver", @@ -2104,7 +2104,7 @@ dependencies = [ "graph-chain-ethereum", "graph-runtime-derive", "graph-runtime-wasm", - "rand 0.8.5", + "rand 0.9.0", "semver", "test-store", "wasmtime", @@ -2199,7 +2199,7 @@ dependencies = [ "postgres", "postgres-openssl", "pretty_assertions", - "rand 0.8.5", + "rand 0.9.0", "serde", "serde_json", "stable-hash 0.3.4", diff --git a/graph/Cargo.toml b/graph/Cargo.toml index 6547d0281c6..f582225f160 100644 --- a/graph/Cargo.toml +++ b/graph/Cargo.toml @@ -40,7 +40,7 @@ lazy_static = "1.5.0" num-bigint = { version = "=0.2.6", features = ["serde"] } num-integer = { version = "=0.1.46" } num-traits = "=0.2.19" -rand = "0.8.4" +rand = "0.9.0" regex = "1.5.4" semver = { version = "1.0.23", features = ["serde"] } serde = { workspace = true } diff --git a/runtime/test/Cargo.toml b/runtime/test/Cargo.toml index 57002d98c41..6c8c2612af2 100644 --- a/runtime/test/Cargo.toml +++ b/runtime/test/Cargo.toml @@ -10,7 +10,7 @@ graph = { path = "../../graph" } graph-chain-ethereum = { path = "../../chain/ethereum" } graph-runtime-derive = { path = "../derive" } graph-runtime-wasm = { path = "../wasm" } -rand = "0.8.5" +rand = "0.9.0" [dev-dependencies] diff --git a/store/postgres/Cargo.toml b/store/postgres/Cargo.toml index 160826ee601..d4ff8ba737a 100644 --- a/store/postgres/Cargo.toml +++ b/store/postgres/Cargo.toml @@ -23,7 +23,7 @@ maybe-owned = "0.3.4" postgres = "0.19.1" openssl = "0.10.72" postgres-openssl = "0.5.1" -rand = "0.8.4" +rand = "0.9.0" serde = { workspace = true } serde_json = { workspace = true } stable-hash_legacy = { git = "https://github.com/graphprotocol/stable-hash", branch = "old", package = "stable-hash" } From 197e1a0a7f1f9eb8075cec2df269626f7db811f2 Mon Sep 17 00:00:00 2001 From: Filipe Azevedo Date: Tue, 29 Apr 2025 15:22:17 +0900 Subject: [PATCH 2/3] fix api changes --- Cargo.lock | 41 +++++++------------------- Cargo.toml | 1 + chain/ethereum/src/network.rs | 10 +++---- graph/Cargo.toml | 9 ++++-- graph/src/data/graphql/load_manager.rs | 4 +-- graph/src/data/subgraph/schema.rs | 8 ++--- graph/src/util/backoff.rs | 2 +- runtime/test/Cargo.toml | 2 +- runtime/test/src/test_padding.rs | 4 +-- store/postgres/Cargo.toml | 2 +- store/postgres/src/deployment_store.rs | 4 +-- 11 files changed, 33 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4422f7f048a..4515f57f7b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,7 +45,7 @@ dependencies = [ "cfg-if 1.0.0", "once_cell", "version_check", - "zerocopy 0.7.35", + "zerocopy", ] [[package]] @@ -1903,7 +1903,7 @@ dependencies = [ "prometheus", "prost", "prost-types", - "rand 0.9.0", + "rand 0.9.1", "regex", "reqwest", "semver", @@ -2104,7 +2104,7 @@ dependencies = [ "graph-chain-ethereum", "graph-runtime-derive", "graph-runtime-wasm", - "rand 0.9.0", + "rand 0.9.1", "semver", "test-store", "wasmtime", @@ -2199,7 +2199,7 @@ dependencies = [ "postgres", "postgres-openssl", "pretty_assertions", - "rand 0.9.0", + "rand 0.9.1", "serde", "serde_json", "stable-hash 0.3.4", @@ -3800,7 +3800,7 @@ dependencies = [ "hmac", "md-5", "memchr", - "rand 0.9.0", + "rand 0.9.1", "sha2", "stringprep", ] @@ -4126,13 +4126,12 @@ dependencies = [ [[package]] name = "rand" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" dependencies = [ "rand_chacha 0.9.0", "rand_core 0.9.3", - "zerocopy 0.8.21", ] [[package]] @@ -5443,7 +5442,7 @@ dependencies = [ "pin-project-lite", "postgres-protocol", "postgres-types", - "rand 0.9.0", + "rand 0.9.1", "socket2", "tokio", "tokio-util 0.7.11", @@ -5812,7 +5811,7 @@ dependencies = [ "http 1.1.0", "httparse", "log", - "rand 0.9.0", + "rand 0.9.1", "sha1", "thiserror 2.0.12", "utf-8", @@ -6980,16 +6979,7 @@ version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ - "zerocopy-derive 0.7.35", -] - -[[package]] -name = "zerocopy" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf01143b2dd5d134f11f545cf9f1431b13b749695cb33bcce051e7568f99478" -dependencies = [ - "zerocopy-derive 0.8.21", + "zerocopy-derive", ] [[package]] @@ -7003,17 +6993,6 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "zerocopy-derive" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712c8386f4f4299382c9abee219bee7084f78fb939d88b6840fcc1320d5f6da2" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.87", -] - [[package]] name = "zerofrom" version = "0.1.6" diff --git a/Cargo.toml b/Cargo.toml index f180a44e9f0..78694e06d1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,6 +94,7 @@ wasmtime = "15.0.1" substreams = "=0.6.0" substreams-entity-change = "2" substreams-near-core = "=0.10.2" +rand = { version = "0.9.1", features = ["os_rng"] } # Incremental compilation on Rust 1.58 causes an ICE on build. As soon as graph node builds again, these can be removed. [profile.test] diff --git a/chain/ethereum/src/network.rs b/chain/ethereum/src/network.rs index d654db71276..59a698ab20b 100644 --- a/chain/ethereum/src/network.rs +++ b/chain/ethereum/src/network.rs @@ -196,11 +196,9 @@ impl EthereumNetworkAdapters { required_capabilities: &NodeCapabilities, retest_percent: f64, ) -> Result, Error> { - let retest_rng: f64 = (&mut rand::thread_rng()).gen(); + let retest_rng: f64 = (&mut rand::rng()).random(); - let cheapest = input - .into_iter() - .choose_multiple(&mut rand::thread_rng(), 3); + let cheapest = input.into_iter().choose_multiple(&mut rand::rng(), 3); let cheapest = cheapest.iter(); // If request falls below the retest threshold, use this request to try and @@ -231,7 +229,7 @@ impl EthereumNetworkAdapters { let cheapest = self.all_unverified_cheapest_with(required_capabilities); Self::cheapest_from( - cheapest.choose_multiple(&mut rand::thread_rng(), 3), + cheapest.choose_multiple(&mut rand::rng(), 3), required_capabilities, self.retest_percent, ) @@ -245,7 +243,7 @@ impl EthereumNetworkAdapters { let cheapest = self .all_cheapest_with(required_capabilities) .await - .choose_multiple(&mut rand::thread_rng(), 3); + .choose_multiple(&mut rand::rng(), 3); Self::cheapest_from(cheapest, required_capabilities, self.retest_percent) } diff --git a/graph/Cargo.toml b/graph/Cargo.toml index f582225f160..631edb29b71 100644 --- a/graph/Cargo.toml +++ b/graph/Cargo.toml @@ -12,7 +12,9 @@ atomic_refcell = "0.1.13" # We require this precise version of bigdecimal. Updating to later versions # has caused PoI differences; if you update this version, you will need to # make sure that it does not cause PoI changes -old_bigdecimal = { version = "=0.1.2", features = ["serde"], package = "bigdecimal" } +old_bigdecimal = { version = "=0.1.2", features = [ + "serde", +], package = "bigdecimal" } bytes = "1.0.1" bs58 = { workspace = true } cid = "0.11.1" @@ -40,7 +42,7 @@ lazy_static = "1.5.0" num-bigint = { version = "=0.2.6", features = ["serde"] } num-integer = { version = "=0.1.46" } num-traits = "=0.2.19" -rand = "0.9.0" +rand.workspace = true regex = "1.5.4" semver = { version = "1.0.23", features = ["serde"] } serde = { workspace = true } @@ -93,7 +95,8 @@ defer = "0.2" # Our fork contains patches to make some fields optional for Celo and Fantom compatibility. # Without the "arbitrary_precision" feature, we get the error `data did not match any variant of untagged enum Response`. web3 = { git = "https://github.com/graphprotocol/rust-web3", branch = "graph-patches-onto-0.18", features = [ - "arbitrary_precision", "test" + "arbitrary_precision", + "test", ] } serde_plain = "1.0.2" csv = "1.3.0" diff --git a/graph/src/data/graphql/load_manager.rs b/graph/src/data/graphql/load_manager.rs index 5e314d1607a..12fa565d321 100644 --- a/graph/src/data/graphql/load_manager.rs +++ b/graph/src/data/graphql/load_manager.rs @@ -1,7 +1,7 @@ //! Utilities to keep moving statistics about queries use prometheus::core::GenericCounter; -use rand::{prelude::Rng, thread_rng}; +use rand::{prelude::Rng, rng}; use std::collections::{HashMap, HashSet}; use std::iter::FromIterator; use std::sync::{Arc, RwLock}; @@ -439,7 +439,7 @@ impl LoadManager { // that cause at least 20% of the effort let kill_rate = self.update_kill_rate(shard, kill_rate, last_update, overloaded, wait_ms); let decline = - thread_rng().gen_bool((kill_rate * query_effort / total_effort).min(1.0).max(0.0)); + rng().random_bool((kill_rate * query_effort / total_effort).min(1.0).max(0.0)); if decline { if ENV_VARS.load_simulate { debug!(self.logger, "Declining query"; diff --git a/graph/src/data/subgraph/schema.rs b/graph/src/data/subgraph/schema.rs index ef2dbc4e47d..75922d810f2 100644 --- a/graph/src/data/subgraph/schema.rs +++ b/graph/src/data/subgraph/schema.rs @@ -4,7 +4,7 @@ use anyhow::{anyhow, bail, Error}; use chrono::{DateTime, Utc}; use hex; use rand::rngs::OsRng; -use rand::Rng; +use rand::TryRngCore as _; use std::collections::BTreeSet; use std::str::FromStr; use std::{fmt, fmt::Display}; @@ -272,11 +272,9 @@ impl_stable_hash!(SubgraphError { }); pub fn generate_entity_id() -> String { - // Fast crypto RNG from operating system - let mut rng = OsRng::default(); - // 128 random bits - let id_bytes: [u8; 16] = rng.gen(); + let mut id_bytes = [0u8; 16]; + OsRng.try_fill_bytes(&mut id_bytes).unwrap(); // 32 hex chars // Comparable to uuidv4, but without the hyphens, diff --git a/graph/src/util/backoff.rs b/graph/src/util/backoff.rs index ffe8d5bb5d3..6e6361e0d67 100644 --- a/graph/src/util/backoff.rs +++ b/graph/src/util/backoff.rs @@ -51,7 +51,7 @@ impl ExponentialBackoff { if delay > self.ceiling { delay = self.ceiling; } - let jitter = rand::Rng::gen_range(&mut rand::thread_rng(), -self.jitter..=self.jitter); + let jitter = rand::Rng::random_range(&mut rand::rng(), -self.jitter..=self.jitter); delay.mul_f64(1.0 + jitter) } diff --git a/runtime/test/Cargo.toml b/runtime/test/Cargo.toml index 6c8c2612af2..be03619a7a9 100644 --- a/runtime/test/Cargo.toml +++ b/runtime/test/Cargo.toml @@ -10,7 +10,7 @@ graph = { path = "../../graph" } graph-chain-ethereum = { path = "../../chain/ethereum" } graph-runtime-derive = { path = "../derive" } graph-runtime-wasm = { path = "../wasm" } -rand = "0.9.0" +rand.workspace = true [dev-dependencies] diff --git a/runtime/test/src/test_padding.rs b/runtime/test/src/test_padding.rs index a68f27f8c61..fc6e922692f 100644 --- a/runtime/test/src/test_padding.rs +++ b/runtime/test/src/test_padding.rs @@ -8,8 +8,8 @@ const WASM_FILE_NAME: &str = "test_padding.wasm"; //for tests, to run in parallel, sub graph name has be unique fn rnd_sub_graph_name(size: usize) -> String { - use rand::{distributions::Alphanumeric, Rng}; - rand::thread_rng() + use rand::{distr::Alphanumeric, Rng}; + rand::rng() .sample_iter(&Alphanumeric) .take(size) .map(char::from) diff --git a/store/postgres/Cargo.toml b/store/postgres/Cargo.toml index d4ff8ba737a..027a46414d9 100644 --- a/store/postgres/Cargo.toml +++ b/store/postgres/Cargo.toml @@ -23,7 +23,7 @@ maybe-owned = "0.3.4" postgres = "0.19.1" openssl = "0.10.72" postgres-openssl = "0.5.1" -rand = "0.9.0" +rand.workspace = true serde = { workspace = true } serde_json = { workspace = true } stable-hash_legacy = { git = "https://github.com/graphprotocol/stable-hash", branch = "old", package = "stable-hash" } diff --git a/store/postgres/src/deployment_store.rs b/store/postgres/src/deployment_store.rs index 1cb569730a0..b02d076fcb0 100644 --- a/store/postgres/src/deployment_store.rs +++ b/store/postgres/src/deployment_store.rs @@ -26,7 +26,7 @@ use graph::semver::Version; use graph::tokio::task::JoinHandle; use itertools::Itertools; use lru_time_cache::LruCache; -use rand::{seq::SliceRandom, thread_rng}; +use rand::{rng, seq::SliceRandom}; use std::collections::{BTreeMap, HashMap}; use std::convert::Into; use std::ops::{Bound, DerefMut}; @@ -156,7 +156,7 @@ impl DeploymentStore { vec![replica; *weight] }) .collect(); - let mut rng = thread_rng(); + let mut rng = rng(); replica_order.shuffle(&mut rng); debug!(logger, "Using postgres host order {:?}", replica_order); From cefe24363598f2fa321fb71b72ddd165dc7856ec Mon Sep 17 00:00:00 2001 From: Filipe Azevedo Date: Tue, 29 Apr 2025 15:43:47 +0900 Subject: [PATCH 3/3] fix example changes --- graph/examples/stress.rs | 42 ++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/graph/examples/stress.rs b/graph/examples/stress.rs index 7e96d914fea..5534f2263b3 100644 --- a/graph/examples/stress.rs +++ b/graph/examples/stress.rs @@ -9,8 +9,8 @@ use clap::Parser; use graph::data::value::{Object, Word}; use graph::object; use graph::prelude::{lazy_static, q, r, BigDecimal, BigInt, QueryResult}; -use rand::SeedableRng; use rand::{rngs::SmallRng, Rng}; +use rand::{RngCore, SeedableRng}; use graph::util::cache_weight::CacheWeight; use graph::util::lfu_cache::LfuCache; @@ -240,8 +240,8 @@ impl Template for BigInt { fn create(size: usize, rng: Option<&mut SmallRng>) -> Self { let f = match rng { Some(rng) => { - let mag = rng.gen_range(1..100); - if rng.gen_bool(0.5) { + let mag = rng.random_range(1..100); + if rng.random_bool(0.5) { mag } else { -mag @@ -261,8 +261,8 @@ impl Template for BigDecimal { fn create(size: usize, mut rng: Option<&mut SmallRng>) -> Self { let f = match rng.as_deref_mut() { Some(rng) => { - let mag = rng.gen_range(1i32..100); - if rng.gen_bool(0.5) { + let mag = rng.random_range(1i32..100); + if rng.random_bool(0.5) { mag } else { -mag @@ -271,7 +271,7 @@ impl Template for BigDecimal { None => 1, }; let exp = match rng { - Some(rng) => rng.gen_range(-100..=100), + Some(rng) => rng.random_range(-100..=100), None => 1, }; 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 { for i in 0..size { let kind = rng .as_deref_mut() - .map(|rng| rng.gen_range(0..modulus)) + .map(|rng| rng.random_range(0..modulus)) .unwrap_or(i % modulus); let value = match kind { @@ -334,7 +334,11 @@ fn make_object(size: usize, mut rng: Option<&mut SmallRng>) -> Object { _ => unreachable!(), }; - let key = rng.as_deref_mut().map(|rng| rng.gen()).unwrap_or(i) % modulus; + let key = rng + .as_deref_mut() + .map(|rng| rng.next_u32() as usize) + .unwrap_or(i) + % modulus; obj.push((Word::from(format!("val{}", key)), value)); } Object::from_iter(obj) @@ -406,7 +410,7 @@ impl ValueMap { for i in 0..size { let kind = rng .as_deref_mut() - .map(|rng| rng.gen_range(0..modulus)) + .map(|rng| rng.random_range(0..modulus)) .unwrap_or(i % modulus); let value = match kind { @@ -431,7 +435,11 @@ impl ValueMap { _ => unreachable!(), }; - let key = rng.as_deref_mut().map(|rng| rng.gen()).unwrap_or(i) % modulus; + let key = rng + .as_deref_mut() + .map(|rng| rng.next_u32() as usize) + .unwrap_or(i) + % modulus; map.insert(format!("val{}", key), value); } MapMeasure(map) @@ -466,7 +474,10 @@ impl UsizeMap { fn make_map(size: usize, mut rng: Option<&mut SmallRng>) -> Self { let mut map = BTreeMap::new(); for i in 0..size { - let key = rng.as_deref_mut().map(|rng| rng.gen()).unwrap_or(2 * i); + let key = rng + .as_deref_mut() + .map(|rng| rng.next_u32() as usize) + .unwrap_or(2 * i); map.insert(key, i * 3); } MapMeasure(map) @@ -563,7 +574,10 @@ fn maybe_rng<'a>(opt: &'a Opt, rng: &'a mut SmallRng) -> Option<&'a mut SmallRng fn stress(opt: &Opt) { let mut rng = match opt.seed { - None => SmallRng::from_entropy(), + None => { + let mut rng = rand::rng(); + SmallRng::from_rng(&mut rng) + } Some(seed) => SmallRng::seed_from_u64(seed), }; @@ -624,7 +638,7 @@ fn stress(opt: &Opt) { let size = if opt.fixed || opt.obj_size == 0 { opt.obj_size } else { - rng.gen_range(0..opt.obj_size) + rng.random_range(0..opt.obj_size) }; let before = ALLOCATED.load(SeqCst); let sample = template.sample(size, maybe_rng(opt, &mut rng)); @@ -638,7 +652,7 @@ fn stress(opt: &Opt) { cache.insert(key, Entry::from(*sample)); // Do a few random reads from the cache for _attempt in 0..5 { - let read = rng.gen_range(0..=key); + let read = rng.random_range(0..=key); let _v = cache.get(&read); } }