Skip to content

Commit a472819

Browse files
authored
protocols/gossipsub: Fix minor lints and spelling (#2079)
1 parent bf0cdbb commit a472819

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

protocols/gossipsub/src/behaviour.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use std::{
2424
collections::VecDeque,
2525
collections::{BTreeSet, HashMap},
2626
fmt,
27-
iter::FromIterator,
2827
net::IpAddr,
2928
sync::Arc,
3029
task::{Context, Poll},
@@ -1246,7 +1245,7 @@ where
12461245
if self.explicit_peers.contains(peer_id) {
12471246
warn!("GRAFT: ignoring request from direct peer {}", peer_id);
12481247
// this is possibly a bug from non-reciprocal configuration; send a PRUNE for all topics
1249-
to_prune_topics = HashSet::from_iter(topics.into_iter());
1248+
to_prune_topics = topics.into_iter().collect();
12501249
// but don't PX
12511250
do_px = false
12521251
} else {
@@ -1779,15 +1778,12 @@ where
17791778

17801779
// if the mesh needs peers add the peer to the mesh
17811780
if !self.explicit_peers.contains(propagation_source)
1782-
&& match self
1783-
.connected_peers
1784-
.get(propagation_source)
1785-
.map(|v| &v.kind)
1786-
{
1787-
Some(PeerKind::Gossipsubv1_1) => true,
1788-
Some(PeerKind::Gossipsub) => true,
1789-
_ => false,
1790-
}
1781+
&& matches!(
1782+
self.connected_peers
1783+
.get(propagation_source)
1784+
.map(|v| &v.kind),
1785+
Some(PeerKind::Gossipsubv1_1) | Some(PeerKind::Gossipsub)
1786+
)
17911787
&& !Self::score_below_threshold_from_scores(
17921788
&self.peer_score,
17931789
propagation_source,
@@ -1860,7 +1856,7 @@ where
18601856
let topics_joined = topics_to_graft.iter().collect::<Vec<_>>();
18611857
if !topics_joined.is_empty() {
18621858
peer_added_to_mesh(
1863-
propagation_source.clone(),
1859+
*propagation_source,
18641860
topics_joined,
18651861
&self.mesh,
18661862
self.peer_topics.get(propagation_source),
@@ -2426,7 +2422,7 @@ where
24262422
remaining_prunes.push(prune);
24272423
// inform the handler
24282424
peer_removed_from_mesh(
2429-
peer.clone(),
2425+
*peer,
24302426
topic_hash,
24312427
&self.mesh,
24322428
self.peer_topics.get(&peer),
@@ -2647,7 +2643,7 @@ where
26472643
// error and drop the message (all individual messages should be small enough to fit in the
26482644
// max_transmit_size)
26492645

2650-
let messages = self.fragment_message(message.into())?;
2646+
let messages = self.fragment_message(message)?;
26512647

26522648
for message in messages {
26532649
self.events
@@ -2803,7 +2799,7 @@ where
28032799
self.config.protocol_id_prefix().clone(),
28042800
self.config.max_transmit_size(),
28052801
self.config.validation_mode().clone(),
2806-
self.config.idle_timeout().clone(),
2802+
self.config.idle_timeout(),
28072803
self.config.support_floodsub(),
28082804
)
28092805
}
@@ -3008,7 +3004,7 @@ where
30083004
if mesh_peers.contains(peer_id) {
30093005
self.events
30103006
.push_back(NetworkBehaviourAction::NotifyHandler {
3011-
peer_id: peer_id.clone(),
3007+
peer_id: *peer_id,
30123008
event: Arc::new(GossipsubHandlerIn::JoinedMesh),
30133009
handler: NotifyHandler::One(connections.connections[0]),
30143010
});

protocols/gossipsub/src/behaviour/tests.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,9 +1833,11 @@ mod tests {
18331833
assert_eq!(dials_set.len(), config.prune_peers());
18341834

18351835
//all dial peers must be in px
1836-
assert!(dials_set.is_subset(&HashSet::from_iter(
1837-
px.iter().map(|i| i.peer_id.as_ref().unwrap().clone())
1838-
)));
1836+
assert!(dials_set.is_subset(
1837+
&px.iter()
1838+
.map(|i| i.peer_id.as_ref().unwrap().clone())
1839+
.collect::<HashSet<_>>()
1840+
));
18391841
}
18401842

18411843
#[test]

protocols/gossipsub/src/peer_score.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl PeerScore {
264264
let p3 = deficit * deficit;
265265
topic_score += p3 * topic_params.mesh_message_deliveries_weight;
266266
debug!(
267-
"The peer {} has a mesh message delivieries deficit of {} in topic\
267+
"The peer {} has a mesh message deliveries deficit of {} in topic\
268268
{} and will get penalized by {}",
269269
peer_id,
270270
deficit,
@@ -726,7 +726,7 @@ impl PeerScore {
726726
match self.params.topics.entry(topic_hash.clone()) {
727727
Occupied(mut entry) => {
728728
let first_message_deliveries_cap = params.first_message_deliveries_cap;
729-
let mesh_message_delivieries_cap = params.mesh_message_deliveries_cap;
729+
let mesh_message_deliveries_cap = params.mesh_message_deliveries_cap;
730730
let old_params = entry.insert(params);
731731

732732
if old_params.first_message_deliveries_cap > first_message_deliveries_cap {
@@ -739,11 +739,11 @@ impl PeerScore {
739739
}
740740
}
741741

742-
if old_params.mesh_message_deliveries_cap > mesh_message_delivieries_cap {
742+
if old_params.mesh_message_deliveries_cap > mesh_message_deliveries_cap {
743743
for stats in self.peer_stats.values_mut() {
744744
if let Some(tstats) = stats.topics.get_mut(&topic_hash) {
745-
if tstats.mesh_message_deliveries > mesh_message_delivieries_cap {
746-
tstats.mesh_message_deliveries = mesh_message_delivieries_cap;
745+
if tstats.mesh_message_deliveries > mesh_message_deliveries_cap {
746+
tstats.mesh_message_deliveries = mesh_message_deliveries_cap;
747747
}
748748
}
749749
}

0 commit comments

Comments
 (0)