Use chacha12 instead of smallrng (#49)

This commit is contained in:
Daniel Sanchez 2024-11-09 03:47:11 +01:00 committed by GitHub
parent 29ce6e953e
commit cffd93ece9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 7 deletions

View File

@ -22,9 +22,9 @@ use nomos_mix::message_blend::{
}; };
use parking_lot::Mutex; use parking_lot::Mutex;
use rand::prelude::IteratorRandom; use rand::prelude::IteratorRandom;
use rand::rngs::SmallRng;
use rand::seq::SliceRandom; use rand::seq::SliceRandom;
use rand::{RngCore, SeedableRng}; use rand::{RngCore, SeedableRng};
use rand_chacha::ChaCha12Rng;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use serde::Serialize; use serde::Serialize;
// internal // internal
@ -73,7 +73,7 @@ impl SimulationApp {
.expect("Time went backwards") .expect("Time went backwards")
.as_secs() .as_secs()
}); });
let mut rng = SmallRng::seed_from_u64(seed); let mut rng = ChaCha12Rng::seed_from_u64(seed);
let mut node_ids: Vec<NodeId> = (0..settings.simulation_settings.node_count) let mut node_ids: Vec<NodeId> = (0..settings.simulation_settings.node_count)
.map(NodeId::from_index) .map(NodeId::from_index)
.collect(); .collect();

View File

@ -28,6 +28,7 @@ serde_with = "2.3"
serde_json = "1.0" serde_json = "1.0"
thiserror = "1" thiserror = "1"
tracing = { version = "0.1", default-features = false, features = ["log", "attributes"] } tracing = { version = "0.1", default-features = false, features = ["log", "attributes"] }
rand_chacha = "0.3"
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"] } getrandom = { version = "0.2", features = ["js"] }

View File

@ -12,7 +12,8 @@ use std::{
// crates // crates
use crossbeam::channel::{self, Receiver, Sender}; use crossbeam::channel::{self, Receiver, Sender};
use parking_lot::Mutex; use parking_lot::Mutex;
use rand::{rngs::SmallRng, Rng, SeedableRng}; use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha12Rng;
use rayon::prelude::*; use rayon::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
// internal // internal
@ -284,7 +285,7 @@ where
.messages .messages
.par_iter() .par_iter()
.filter(|(network_time, message)| { .filter(|(network_time, message)| {
let mut rng = SmallRng::seed_from_u64(self.seed); let mut rng = ChaCha12Rng::seed_from_u64(self.seed);
self.send_or_drop_message(&mut rng, network_time, message) self.send_or_drop_message(&mut rng, network_time, message)
}) })
.cloned() .cloned()

View File

@ -13,8 +13,8 @@ use crate::streaming::{
}; };
use crossbeam::channel::Sender; use crossbeam::channel::Sender;
use parking_lot::RwLock; use parking_lot::RwLock;
use rand::rngs::SmallRng;
use rand::{RngCore, SeedableRng}; use rand::{RngCore, SeedableRng};
use rand_chacha::ChaCha12Rng;
use rayon::prelude::*; use rayon::prelude::*;
use serde::Serialize; use serde::Serialize;
@ -72,7 +72,7 @@ where
{ {
network: Network<M>, network: Network<M>,
wards: Vec<Ward>, wards: Vec<Ward>,
rng: SmallRng, rng: ChaCha12Rng,
} }
impl<M> SimulationRunnerInner<M> impl<M> SimulationRunnerInner<M>
@ -136,7 +136,7 @@ where
// Store the settings to the producer so that we can collect them later // Store the settings to the producer so that we can collect them later
producer.send(R::from(settings.clone()))?; producer.send(R::from(settings.clone()))?;
let rng = SmallRng::seed_from_u64(seed); let rng = ChaCha12Rng::seed_from_u64(seed);
let nodes = Arc::new(RwLock::new(nodes)); let nodes = Arc::new(RwLock::new(nodes));
let SimulationSettings { let SimulationSettings {
wards, wards,