Skip to content
Draft
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
22 changes: 11 additions & 11 deletions Cargo.lock

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

14 changes: 7 additions & 7 deletions protocols/gossipsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ wasm-bindgen = ["getrandom/js", "futures-timer/wasm-bindgen"]
metrics = ["prometheus-client"]

[dependencies]
async-channel = "2.3.1"
async-channel = "2.5.0"
asynchronous-codec = { workspace = true }
base64 = "0.22.1"
byteorder = "1.5.0"
bytes = "1.6"
either = "1.11"
bytes = "1.11"
either = "1.15"
fnv = "1.0.7"
futures = { workspace = true }
futures-timer = "3.0.2"
futures-timer = "3.0.3"
getrandom = { workspace = true }
hashlink = { workspace = true }
hex_fmt = "0.3.0"
Expand All @@ -33,10 +33,10 @@ libp2p-identity = { workspace = true, features = ["rand"] }
libp2p-swarm = { workspace = true }
quick-protobuf = "0.8"
quick-protobuf-codec = { workspace = true }
rand = "0.8"
regex = "1.10.5"
rand = "0.9"
regex = "1.12.3"
serde = { version = "1", optional = true, features = ["derive"] }
sha2 = "0.10.8"
sha2 = "0.10.9"
tracing = { workspace = true }

# Metrics dependencies
Expand Down
15 changes: 6 additions & 9 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use libp2p_swarm::{
#[cfg(feature = "metrics")]
use prometheus_client::registry::Registry;
use quick_protobuf::{MessageWrite, Writer};
use rand::{seq::SliceRandom, thread_rng};
use rand::{rng, seq::SliceRandom};
use web_time::{Instant, SystemTime};

#[cfg(feature = "metrics")]
Expand Down Expand Up @@ -1274,8 +1274,7 @@ where

// Ask in random order
let mut iwant_ids_vec: Vec<_> = iwant_ids.into_iter().collect();
let mut rng = thread_rng();
iwant_ids_vec.partial_shuffle(&mut rng, iask);
iwant_ids_vec.partial_shuffle(&mut rng(), iask);

iwant_ids_vec.truncate(iask);
*iasked += iask;
Expand Down Expand Up @@ -1622,8 +1621,7 @@ where
px.retain(|p| p.peer_id.is_some());
if px.len() > n {
// only use at most prune_peers many random peers
let mut rng = thread_rng();
px.partial_shuffle(&mut rng, n);
px.partial_shuffle(&mut rng(), n);
px = px.into_iter().take(n).collect();
}

Expand Down Expand Up @@ -2222,7 +2220,7 @@ where
let excess_peer_no = peers.len() - mesh_n;

// shuffle the peers and then sort by score ascending beginning with the worst
let mut rng = thread_rng();
let mut rng = rng();
let mut shuffled = peers.iter().copied().collect::<Vec<_>>();
shuffled.shuffle(&mut rng);
shuffled.sort_by(|p1, p2| {
Expand Down Expand Up @@ -2541,7 +2539,7 @@ where
/// Emits gossip - Send IHAVE messages to a random set of gossip peers. This is applied to mesh
/// and fanout peers
fn emit_gossip(&mut self) {
let mut rng = thread_rng();
let mut rng = rng();
let mut messages = Vec::new();
for (topic_hash, peers) in self.mesh.iter().chain(self.fanout.iter()) {
let mut message_ids = self.mcache.get_gossip_message_ids(topic_hash);
Expand Down Expand Up @@ -3509,8 +3507,7 @@ fn get_random_peers_dynamic(
}

// we have more peers than needed, shuffle them and return n of them
let mut rng = thread_rng();
gossip_peers.partial_shuffle(&mut rng, n);
gossip_peers.partial_shuffle(&mut rng(), n);

tracing::debug!("RANDOM PEERS: Got {:?} peers", n);

Expand Down
8 changes: 5 additions & 3 deletions protocols/gossipsub/src/behaviour/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,15 @@ pub(super) fn flush_events<D: DataTransform, F: TopicSubscriptionFilter>(
/// * `seq` - Mutable sequence counter (incremented each call)
/// * `topics` - Pool of topics to randomly select from
pub(super) fn random_message(seq: &mut u64, topics: &[TopicHash]) -> RawMessage {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
*seq += 1;
RawMessage {
source: Some(PeerId::random()),
data: (0..rng.gen_range(10..10024)).map(|_| rng.gen()).collect(),
data: (0..rng.random_range(10..10024))
.map(|_| rng.random())
.collect(),
sequence_number: Some(*seq),
topic: topics[rng.gen_range(0..topics.len())].clone(),
topic: topics[rng.random_range(0..topics.len())].clone(),
signature: None,
key: None,
validated: true,
Expand Down
24 changes: 12 additions & 12 deletions protocols/gossipsub/src/rpc_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,27 @@ mod test {

let new_message1 = super::proto::Message {
from: Some(PeerId::random().to_bytes()),
data: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
seqno: Some(rand::thread_rng().gen::<[u8; 8]>().to_vec()),
data: Some(rand::rng().random::<[u8; 32]>().to_vec()),
seqno: Some(rand::rng().random::<[u8; 8]>().to_vec()),
topic: topic1.clone().into_string(),
signature: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
key: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
signature: Some(rand::rng().random::<[u8; 32]>().to_vec()),
key: Some(rand::rng().random::<[u8; 32]>().to_vec()),
};
let old_message1 = compat::pb::Message {
from: Some(PeerId::random().to_bytes()),
data: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
seqno: Some(rand::thread_rng().gen::<[u8; 8]>().to_vec()),
data: Some(rand::rng().random::<[u8; 32]>().to_vec()),
seqno: Some(rand::rng().random::<[u8; 8]>().to_vec()),
topic_ids: vec![topic1.clone().into_string()],
signature: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
key: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
signature: Some(rand::rng().random::<[u8; 32]>().to_vec()),
key: Some(rand::rng().random::<[u8; 32]>().to_vec()),
};
let old_message2 = compat::pb::Message {
from: Some(PeerId::random().to_bytes()),
data: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
seqno: Some(rand::thread_rng().gen::<[u8; 8]>().to_vec()),
data: Some(rand::rng().random::<[u8; 32]>().to_vec()),
seqno: Some(rand::rng().random::<[u8; 8]>().to_vec()),
topic_ids: vec![topic1.clone().into_string(), topic2.clone().into_string()],
signature: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
key: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
signature: Some(rand::rng().random::<[u8; 32]>().to_vec()),
key: Some(rand::rng().random::<[u8; 32]>().to_vec()),
};

let mut new_message1b = Vec::with_capacity(new_message1.get_size());
Expand Down
2 changes: 1 addition & 1 deletion protocols/gossipsub/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use libp2p_gossipsub::{MessageAuthenticity, ValidationMode};
use libp2p_swarm::Swarm;
use libp2p_swarm_test::SwarmExt as _;
use quickcheck::{QuickCheck, TestResult};
use rand::{seq::SliceRandom, SeedableRng};
use rand::{seq::IndexedMutRandom, SeedableRng};
use tokio::{runtime::Runtime, time};
use tracing_subscriber::EnvFilter;

Expand Down
Loading