mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-23 14:51:34 +00:00
chore: Implement latest clippy warnings (#3220)
As I do frequently, I corrected for the latest clippy warnings. This will make sure the CI won't complain in the future. We could automate this btw and maybe run the nightly version of clippy.
This commit is contained in:
@ -4767,8 +4767,8 @@ fn test_iwant_penalties() {
|
||||
assert!(i > 9);
|
||||
double_penalized += 1
|
||||
} else {
|
||||
println!("{}", peer);
|
||||
println!("{}", score);
|
||||
println!("{peer}");
|
||||
println!("{score}");
|
||||
panic!("Invalid score of peer");
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ pub enum PublishError {
|
||||
|
||||
impl std::fmt::Display for PublishError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
write!(f, "{self:?}")
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ pub enum SubscriptionError {
|
||||
|
||||
impl std::fmt::Display for SubscriptionError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
write!(f, "{self:?}")
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ pub enum ValidationError {
|
||||
|
||||
impl std::fmt::Display for ValidationError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
write!(f, "{self:?}")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,10 +174,7 @@ impl PeerScoreParams {
|
||||
pub fn validate(&self) -> Result<(), String> {
|
||||
for (topic, params) in self.topics.iter() {
|
||||
if let Err(e) = params.validate() {
|
||||
return Err(format!(
|
||||
"Invalid score parameters for topic {}: {}",
|
||||
topic, e
|
||||
));
|
||||
return Err(format!("Invalid score parameters for topic {topic}: {e}"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,8 +100,7 @@ fn test_score_time_in_mesh() {
|
||||
let score = peer_score.score(&peer_id);
|
||||
assert!(
|
||||
score == 0.0,
|
||||
"expected score to start at zero. Score found: {}",
|
||||
score
|
||||
"expected score to start at zero. Score found: {score}"
|
||||
);
|
||||
|
||||
// The time in mesh depends on how long the peer has been grafted
|
||||
@ -116,9 +115,7 @@ fn test_score_time_in_mesh() {
|
||||
* (elapsed.as_millis() / topic_params.time_in_mesh_quantum.as_millis()) as f64;
|
||||
assert!(
|
||||
score >= expected,
|
||||
"The score: {} should be greater than or equal to: {}",
|
||||
score,
|
||||
expected
|
||||
"The score: {score} should be greater than or equal to: {expected}"
|
||||
);
|
||||
}
|
||||
|
||||
@ -148,8 +145,7 @@ fn test_score_time_in_mesh_cap() {
|
||||
let score = peer_score.score(&peer_id);
|
||||
assert!(
|
||||
score == 0.0,
|
||||
"expected score to start at zero. Score found: {}",
|
||||
score
|
||||
"expected score to start at zero. Score found: {score}"
|
||||
);
|
||||
|
||||
// The time in mesh depends on how long the peer has been grafted
|
||||
@ -210,12 +206,7 @@ fn test_score_first_message_deliveries() {
|
||||
let score = peer_score.score(&peer_id);
|
||||
let expected =
|
||||
topic_params.topic_weight * topic_params.first_message_deliveries_weight * messages as f64;
|
||||
assert!(
|
||||
score == expected,
|
||||
"The score: {} should be {}",
|
||||
score,
|
||||
expected
|
||||
);
|
||||
assert!(score == expected, "The score: {score} should be {expected}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -256,12 +247,7 @@ fn test_score_first_message_deliveries_cap() {
|
||||
let expected = topic_params.topic_weight
|
||||
* topic_params.first_message_deliveries_weight
|
||||
* topic_params.first_message_deliveries_cap;
|
||||
assert!(
|
||||
score == expected,
|
||||
"The score: {} should be {}",
|
||||
score,
|
||||
expected
|
||||
);
|
||||
assert!(score == expected, "The score: {score} should be {expected}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -300,12 +286,7 @@ fn test_score_first_message_deliveries_decay() {
|
||||
* topic_params.first_message_deliveries_weight
|
||||
* topic_params.first_message_deliveries_decay
|
||||
* messages as f64;
|
||||
assert!(
|
||||
score == expected,
|
||||
"The score: {} should be {}",
|
||||
score,
|
||||
expected
|
||||
);
|
||||
assert!(score == expected, "The score: {score} should be {expected}");
|
||||
|
||||
// refreshing the scores applies the decay param
|
||||
let decay_intervals = 10;
|
||||
@ -314,12 +295,7 @@ fn test_score_first_message_deliveries_decay() {
|
||||
expected *= topic_params.first_message_deliveries_decay;
|
||||
}
|
||||
let score = peer_score.score(&peer_id);
|
||||
assert!(
|
||||
score == expected,
|
||||
"The score: {} should be {}",
|
||||
score,
|
||||
expected
|
||||
);
|
||||
assert!(score == expected, "The score: {score} should be {expected}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -368,8 +344,7 @@ fn test_score_mesh_message_deliveries() {
|
||||
let score = peer_score.score(peer_id);
|
||||
assert!(
|
||||
score >= 0.0,
|
||||
"expected no mesh delivery penalty before activation time, got score {}",
|
||||
score
|
||||
"expected no mesh delivery penalty before activation time, got score {score}"
|
||||
);
|
||||
}
|
||||
|
||||
@ -402,13 +377,11 @@ fn test_score_mesh_message_deliveries() {
|
||||
|
||||
assert!(
|
||||
score_a >= 0.0,
|
||||
"expected non-negative score for Peer A, got score {}",
|
||||
score_a
|
||||
"expected non-negative score for Peer A, got score {score_a}"
|
||||
);
|
||||
assert!(
|
||||
score_b >= 0.0,
|
||||
"expected non-negative score for Peer B, got score {}",
|
||||
score_b
|
||||
"expected non-negative score for Peer B, got score {score_b}"
|
||||
);
|
||||
|
||||
// the penalty is the difference between the threshold and the actual mesh deliveries, squared.
|
||||
@ -418,12 +391,7 @@ fn test_score_mesh_message_deliveries() {
|
||||
let expected =
|
||||
topic_params.topic_weight * topic_params.mesh_message_deliveries_weight * penalty;
|
||||
|
||||
assert!(
|
||||
score_c == expected,
|
||||
"Score: {}. Expected {}",
|
||||
score_c,
|
||||
expected
|
||||
);
|
||||
assert!(score_c == expected, "Score: {score_c}. Expected {expected}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -469,8 +437,7 @@ fn test_score_mesh_message_deliveries_decay() {
|
||||
let score_a = peer_score.score(&peer_id_a);
|
||||
assert!(
|
||||
score_a >= 0.0,
|
||||
"expected non-negative score for Peer A, got score {}",
|
||||
score_a
|
||||
"expected non-negative score for Peer A, got score {score_a}"
|
||||
);
|
||||
|
||||
let mut decayed_delivery_count = (messages as f64) * topic_params.mesh_message_deliveries_decay;
|
||||
@ -545,13 +512,11 @@ fn test_score_mesh_failure_penalty() {
|
||||
let score_b = peer_score.score(&peer_id_b);
|
||||
assert!(
|
||||
score_a >= 0.0,
|
||||
"expected non-negative score for Peer A, got score {}",
|
||||
score_a
|
||||
"expected non-negative score for Peer A, got score {score_a}"
|
||||
);
|
||||
assert!(
|
||||
score_b >= 0.0,
|
||||
"expected non-negative score for Peer B, got score {}",
|
||||
score_b
|
||||
"expected non-negative score for Peer B, got score {score_b}"
|
||||
);
|
||||
|
||||
// prune peer B to apply the penalty
|
||||
|
@ -107,11 +107,11 @@ impl ProtocolId {
|
||||
let protocol_id = match kind {
|
||||
PeerKind::Gossipsubv1_1 => match prefix {
|
||||
true => format!("/{}/{}", id, "1.1.0"),
|
||||
false => format!("{}", id),
|
||||
false => format!("{id}"),
|
||||
},
|
||||
PeerKind::Gossipsub => match prefix {
|
||||
true => format!("/{}/{}", id, "1.0.0"),
|
||||
false => format!("{}", id),
|
||||
false => format!("{id}"),
|
||||
},
|
||||
PeerKind::Floodsub => format!("/{}/{}", "floodsub", "1.0.0"),
|
||||
// NOTE: This is used for informing the behaviour of unsupported peers. We do not
|
||||
|
@ -354,7 +354,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_filter_incoming_too_many_subscriptions() {
|
||||
let t: Vec<_> = (0..4)
|
||||
.map(|i| TopicHash::from_raw(format!("t{}", i)))
|
||||
.map(|i| TopicHash::from_raw(format!("t{i}")))
|
||||
.collect();
|
||||
|
||||
let mut filter = MaxCountSubscriptionFilter {
|
||||
@ -383,7 +383,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_filter_incoming_max_subscribed_valid() {
|
||||
let t: Vec<_> = (0..5)
|
||||
.map(|i| TopicHash::from_raw(format!("t{}", i)))
|
||||
.map(|i| TopicHash::from_raw(format!("t{i}")))
|
||||
.collect();
|
||||
|
||||
let mut filter = MaxCountSubscriptionFilter {
|
||||
|
Reference in New Issue
Block a user