Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 10 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 4 additions & 6 deletions chain/ethereum/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,9 @@ impl EthereumNetworkAdapters {
required_capabilities: &NodeCapabilities,
retest_percent: f64,
) -> Result<Arc<EthereumAdapter>, 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
Expand Down Expand Up @@ -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,
)
Expand All @@ -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)
}
Expand Down
9 changes: 6 additions & 3 deletions graph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.8.4"
rand.workspace = true
regex = "1.5.4"
semver = { version = "1.0.23", features = ["serde"] }
serde = { workspace = true }
Expand Down Expand Up @@ -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"
Expand Down
42 changes: 28 additions & 14 deletions graph/examples/stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -563,7 +574,10 @@ fn maybe_rng<'a>(opt: &'a Opt, rng: &'a mut SmallRng) -> Option<&'a mut SmallRng

fn stress<T: Template>(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),
};

Expand Down Expand Up @@ -624,7 +638,7 @@ fn stress<T: Template>(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));
Expand All @@ -638,7 +652,7 @@ fn stress<T: Template>(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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions graph/src/data/graphql/load_manager.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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";
Expand Down
8 changes: 3 additions & 5 deletions graph/src/data/subgraph/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion graph/src/util/backoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.workspace = true


[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions runtime/test/src/test_padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion store/postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.workspace = true
serde = { workspace = true }
serde_json = { workspace = true }
stable-hash_legacy = { git = "https://github.com/graphprotocol/stable-hash", branch = "old", package = "stable-hash" }
Expand Down
Loading