Skip to content

Commit

Permalink
protocols/gossipsub: Fix minor lints and spelling (#2079)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgeManning committed May 26, 2021
1 parent bf0cdbb commit a472819
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
28 changes: 12 additions & 16 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use std::{
collections::VecDeque,
collections::{BTreeSet, HashMap},
fmt,
iter::FromIterator,
net::IpAddr,
sync::Arc,
task::{Context, Poll},
Expand Down Expand Up @@ -1246,7 +1245,7 @@ where
if self.explicit_peers.contains(peer_id) {
warn!("GRAFT: ignoring request from direct peer {}", peer_id);
// this is possibly a bug from non-reciprocal configuration; send a PRUNE for all topics
to_prune_topics = HashSet::from_iter(topics.into_iter());
to_prune_topics = topics.into_iter().collect();
// but don't PX
do_px = false
} else {
Expand Down Expand Up @@ -1779,15 +1778,12 @@ where

// if the mesh needs peers add the peer to the mesh
if !self.explicit_peers.contains(propagation_source)
&& match self
.connected_peers
.get(propagation_source)
.map(|v| &v.kind)
{
Some(PeerKind::Gossipsubv1_1) => true,
Some(PeerKind::Gossipsub) => true,
_ => false,
}
&& matches!(
self.connected_peers
.get(propagation_source)
.map(|v| &v.kind),
Some(PeerKind::Gossipsubv1_1) | Some(PeerKind::Gossipsub)
)
&& !Self::score_below_threshold_from_scores(
&self.peer_score,
propagation_source,
Expand Down Expand Up @@ -1860,7 +1856,7 @@ where
let topics_joined = topics_to_graft.iter().collect::<Vec<_>>();
if !topics_joined.is_empty() {
peer_added_to_mesh(
propagation_source.clone(),
*propagation_source,
topics_joined,
&self.mesh,
self.peer_topics.get(propagation_source),
Expand Down Expand Up @@ -2426,7 +2422,7 @@ where
remaining_prunes.push(prune);
// inform the handler
peer_removed_from_mesh(
peer.clone(),
*peer,
topic_hash,
&self.mesh,
self.peer_topics.get(&peer),
Expand Down Expand Up @@ -2647,7 +2643,7 @@ where
// error and drop the message (all individual messages should be small enough to fit in the
// max_transmit_size)

let messages = self.fragment_message(message.into())?;
let messages = self.fragment_message(message)?;

for message in messages {
self.events
Expand Down Expand Up @@ -2803,7 +2799,7 @@ where
self.config.protocol_id_prefix().clone(),
self.config.max_transmit_size(),
self.config.validation_mode().clone(),
self.config.idle_timeout().clone(),
self.config.idle_timeout(),
self.config.support_floodsub(),
)
}
Expand Down Expand Up @@ -3008,7 +3004,7 @@ where
if mesh_peers.contains(peer_id) {
self.events
.push_back(NetworkBehaviourAction::NotifyHandler {
peer_id: peer_id.clone(),
peer_id: *peer_id,
event: Arc::new(GossipsubHandlerIn::JoinedMesh),
handler: NotifyHandler::One(connections.connections[0]),
});
Expand Down
8 changes: 5 additions & 3 deletions protocols/gossipsub/src/behaviour/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1833,9 +1833,11 @@ mod tests {
assert_eq!(dials_set.len(), config.prune_peers());

//all dial peers must be in px
assert!(dials_set.is_subset(&HashSet::from_iter(
px.iter().map(|i| i.peer_id.as_ref().unwrap().clone())
)));
assert!(dials_set.is_subset(
&px.iter()
.map(|i| i.peer_id.as_ref().unwrap().clone())
.collect::<HashSet<_>>()
));
}

#[test]
Expand Down
10 changes: 5 additions & 5 deletions protocols/gossipsub/src/peer_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl PeerScore {
let p3 = deficit * deficit;
topic_score += p3 * topic_params.mesh_message_deliveries_weight;
debug!(
"The peer {} has a mesh message delivieries deficit of {} in topic\
"The peer {} has a mesh message deliveries deficit of {} in topic\
{} and will get penalized by {}",
peer_id,
deficit,
Expand Down Expand Up @@ -726,7 +726,7 @@ impl PeerScore {
match self.params.topics.entry(topic_hash.clone()) {
Occupied(mut entry) => {
let first_message_deliveries_cap = params.first_message_deliveries_cap;
let mesh_message_delivieries_cap = params.mesh_message_deliveries_cap;
let mesh_message_deliveries_cap = params.mesh_message_deliveries_cap;
let old_params = entry.insert(params);

if old_params.first_message_deliveries_cap > first_message_deliveries_cap {
Expand All @@ -739,11 +739,11 @@ impl PeerScore {
}
}

if old_params.mesh_message_deliveries_cap > mesh_message_delivieries_cap {
if old_params.mesh_message_deliveries_cap > mesh_message_deliveries_cap {
for stats in self.peer_stats.values_mut() {
if let Some(tstats) = stats.topics.get_mut(&topic_hash) {
if tstats.mesh_message_deliveries > mesh_message_delivieries_cap {
tstats.mesh_message_deliveries = mesh_message_delivieries_cap;
if tstats.mesh_message_deliveries > mesh_message_deliveries_cap {
tstats.mesh_message_deliveries = mesh_message_deliveries_cap;
}
}
}
Expand Down

0 comments on commit a472819

Please sign in to comment.