Skip to content

Commit fbe47cb

Browse files
committed
update gossipsub dependencies
1 parent c137d57 commit fbe47cb

File tree

6 files changed

+42
-43
lines changed

6 files changed

+42
-43
lines changed

Cargo.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protocols/gossipsub/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ wasm-bindgen = ["getrandom/js", "futures-timer/wasm-bindgen"]
1515
metrics = ["prometheus-client"]
1616

1717
[dependencies]
18-
async-channel = "2.3.1"
18+
async-channel = "2.5.0"
1919
asynchronous-codec = { workspace = true }
2020
base64 = "0.22.1"
2121
byteorder = "1.5.0"
22-
bytes = "1.6"
23-
either = "1.11"
22+
bytes = "1.11"
23+
either = "1.15"
2424
fnv = "1.0.7"
2525
futures = { workspace = true }
26-
futures-timer = "3.0.2"
26+
futures-timer = "3.0.3"
2727
getrandom = { workspace = true }
2828
hashlink = { workspace = true }
2929
hex_fmt = "0.3.0"
@@ -33,10 +33,10 @@ libp2p-identity = { workspace = true, features = ["rand"] }
3333
libp2p-swarm = { workspace = true }
3434
quick-protobuf = "0.8"
3535
quick-protobuf-codec = { workspace = true }
36-
rand = "0.8"
37-
regex = "1.10.5"
36+
rand = "0.9"
37+
regex = "1.12.3"
3838
serde = { version = "1", optional = true, features = ["derive"] }
39-
sha2 = "0.10.8"
39+
sha2 = "0.10.9"
4040
tracing = { workspace = true }
4141

4242
# Metrics dependencies

protocols/gossipsub/src/behaviour.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use libp2p_swarm::{
4848
#[cfg(feature = "metrics")]
4949
use prometheus_client::registry::Registry;
5050
use quick_protobuf::{MessageWrite, Writer};
51-
use rand::{seq::SliceRandom, thread_rng};
51+
use rand::{rng, seq::SliceRandom};
5252
use web_time::{Instant, SystemTime};
5353

5454
#[cfg(feature = "metrics")]
@@ -1274,8 +1274,7 @@ where
12741274

12751275
// Ask in random order
12761276
let mut iwant_ids_vec: Vec<_> = iwant_ids.into_iter().collect();
1277-
let mut rng = thread_rng();
1278-
iwant_ids_vec.partial_shuffle(&mut rng, iask);
1277+
iwant_ids_vec.partial_shuffle(&mut rng(), iask);
12791278

12801279
iwant_ids_vec.truncate(iask);
12811280
*iasked += iask;
@@ -1622,8 +1621,7 @@ where
16221621
px.retain(|p| p.peer_id.is_some());
16231622
if px.len() > n {
16241623
// only use at most prune_peers many random peers
1625-
let mut rng = thread_rng();
1626-
px.partial_shuffle(&mut rng, n);
1624+
px.partial_shuffle(&mut rng(), n);
16271625
px = px.into_iter().take(n).collect();
16281626
}
16291627

@@ -2222,7 +2220,7 @@ where
22222220
let excess_peer_no = peers.len() - mesh_n;
22232221

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

35113509
// we have more peers than needed, shuffle them and return n of them
3512-
let mut rng = thread_rng();
3513-
gossip_peers.partial_shuffle(&mut rng, n);
3510+
gossip_peers.partial_shuffle(&mut rng(), n);
35143511

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

protocols/gossipsub/src/behaviour/tests/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,15 @@ pub(super) fn flush_events<D: DataTransform, F: TopicSubscriptionFilter>(
599599
/// * `seq` - Mutable sequence counter (incremented each call)
600600
/// * `topics` - Pool of topics to randomly select from
601601
pub(super) fn random_message(seq: &mut u64, topics: &[TopicHash]) -> RawMessage {
602-
let mut rng = rand::thread_rng();
602+
let mut rng = rand::rng();
603603
*seq += 1;
604604
RawMessage {
605605
source: Some(PeerId::random()),
606-
data: (0..rng.gen_range(10..10024)).map(|_| rng.gen()).collect(),
606+
data: (0..rng.random_range(10..10024))
607+
.map(|_| rng.random())
608+
.collect(),
607609
sequence_number: Some(*seq),
608-
topic: topics[rng.gen_range(0..topics.len())].clone(),
610+
topic: topics[rng.random_range(0..topics.len())].clone(),
609611
signature: None,
610612
key: None,
611613
validated: true,

protocols/gossipsub/src/rpc_proto.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,27 @@ mod test {
3939

4040
let new_message1 = super::proto::Message {
4141
from: Some(PeerId::random().to_bytes()),
42-
data: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
43-
seqno: Some(rand::thread_rng().gen::<[u8; 8]>().to_vec()),
42+
data: Some(rand::rng().random::<[u8; 32]>().to_vec()),
43+
seqno: Some(rand::rng().random::<[u8; 8]>().to_vec()),
4444
topic: topic1.clone().into_string(),
45-
signature: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
46-
key: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
45+
signature: Some(rand::rng().random::<[u8; 32]>().to_vec()),
46+
key: Some(rand::rng().random::<[u8; 32]>().to_vec()),
4747
};
4848
let old_message1 = compat::pb::Message {
4949
from: Some(PeerId::random().to_bytes()),
50-
data: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
51-
seqno: Some(rand::thread_rng().gen::<[u8; 8]>().to_vec()),
50+
data: Some(rand::rng().random::<[u8; 32]>().to_vec()),
51+
seqno: Some(rand::rng().random::<[u8; 8]>().to_vec()),
5252
topic_ids: vec![topic1.clone().into_string()],
53-
signature: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
54-
key: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
53+
signature: Some(rand::rng().random::<[u8; 32]>().to_vec()),
54+
key: Some(rand::rng().random::<[u8; 32]>().to_vec()),
5555
};
5656
let old_message2 = compat::pb::Message {
5757
from: Some(PeerId::random().to_bytes()),
58-
data: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
59-
seqno: Some(rand::thread_rng().gen::<[u8; 8]>().to_vec()),
58+
data: Some(rand::rng().random::<[u8; 32]>().to_vec()),
59+
seqno: Some(rand::rng().random::<[u8; 8]>().to_vec()),
6060
topic_ids: vec![topic1.clone().into_string(), topic2.clone().into_string()],
61-
signature: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
62-
key: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()),
61+
signature: Some(rand::rng().random::<[u8; 32]>().to_vec()),
62+
key: Some(rand::rng().random::<[u8; 32]>().to_vec()),
6363
};
6464

6565
let mut new_message1b = Vec::with_capacity(new_message1.get_size());

protocols/gossipsub/tests/smoke.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use libp2p_gossipsub::{MessageAuthenticity, ValidationMode};
2929
use libp2p_swarm::Swarm;
3030
use libp2p_swarm_test::SwarmExt as _;
3131
use quickcheck::{QuickCheck, TestResult};
32-
use rand::{seq::SliceRandom, SeedableRng};
32+
use rand::{seq::IndexedMutRandom, SeedableRng};
3333
use tokio::{runtime::Runtime, time};
3434
use tracing_subscriber::EnvFilter;
3535

0 commit comments

Comments
 (0)