* Add clippy config and remove .cargo from gitignore

* first fixes

* Clippyfied

* Add clippy CI job

* comment out rusty-cachier

* minor

* fix ci

* remove DAG from check-dependent-project

* add DAG to clippy

Co-authored-by: alvicsam <alvicsam@gmail.com>
This commit is contained in:
alexgparity
2022-11-30 09:34:06 +01:00
committed by GitHub
parent b76086c617
commit 9ea14e66c8
67 changed files with 338 additions and 351 deletions
@@ -309,7 +309,7 @@ enum MessageSource {
impl MessageSource {
fn peer_id(&self) -> Option<PeerId> {
match self {
Self::Peer(id) => Some(id.clone()),
Self::Peer(id) => Some(*id),
Self::Local => None,
}
}
@@ -389,7 +389,7 @@ impl State {
) {
let mut new_hashes = HashSet::new();
for meta in &metas {
match self.blocks.entry(meta.hash.clone()) {
match self.blocks.entry(meta.hash) {
hash_map::Entry::Vacant(entry) => {
let candidates_count = meta.candidates.len();
let mut candidates = Vec::with_capacity(candidates_count);
@@ -398,7 +398,7 @@ impl State {
entry.insert(BlockEntry {
known_by: HashMap::new(),
number: meta.number,
parent_hash: meta.parent_hash.clone(),
parent_hash: meta.parent_hash,
knowledge: Knowledge::default(),
candidates,
session: meta.session,
@@ -406,7 +406,7 @@ impl State {
self.topologies.inc_session_refs(meta.session);
new_hashes.insert(meta.hash.clone());
new_hashes.insert(meta.hash);
// In case there are duplicates, we should only set this if the entry
// was vacant.
@@ -433,7 +433,7 @@ impl State {
&mut self.blocks,
&self.topologies,
self.peer_views.len(),
peer_id.clone(),
*peer_id,
view_intersection,
rng,
)
@@ -563,10 +563,8 @@ impl State {
"Pending assignment",
);
pending.push((
peer_id.clone(),
PendingMessage::Assignment(assignment, claimed_index),
));
pending
.push((peer_id, PendingMessage::Assignment(assignment, claimed_index)));
continue
}
@@ -574,7 +572,7 @@ impl State {
self.import_and_circulate_assignment(
ctx,
metrics,
MessageSource::Peer(peer_id.clone()),
MessageSource::Peer(peer_id),
assignment,
claimed_index,
rng,
@@ -604,7 +602,7 @@ impl State {
"Pending approval",
);
pending.push((peer_id.clone(), PendingMessage::Approval(approval_vote)));
pending.push((peer_id, PendingMessage::Approval(approval_vote)));
continue
}
@@ -612,7 +610,7 @@ impl State {
self.import_and_circulate_approval(
ctx,
metrics,
MessageSource::Peer(peer_id.clone()),
MessageSource::Peer(peer_id),
approval_vote,
)
.await;
@@ -663,7 +661,7 @@ impl State {
&mut self.blocks,
&self.topologies,
self.peer_views.len(),
peer_id.clone(),
peer_id,
view,
rng,
)
@@ -709,7 +707,7 @@ impl State {
) where
R: CryptoRng + Rng,
{
let block_hash = assignment.block_hash.clone();
let block_hash = assignment.block_hash;
let validator_index = assignment.validator;
let entry = match self.blocks.get_mut(&block_hash) {
@@ -737,7 +735,7 @@ impl State {
if let Some(peer_id) = source.peer_id() {
// check if our knowledge of the peer already contains this assignment
match entry.known_by.entry(peer_id.clone()) {
match entry.known_by.entry(peer_id) {
hash_map::Entry::Occupied(mut peer_knowledge) => {
let peer_knowledge = peer_knowledge.get_mut();
if peer_knowledge.contains(&message_subject, message_kind) {
@@ -761,13 +759,13 @@ impl State {
?message_subject,
"Assignment from a peer is out of view",
);
modify_reputation(ctx.sender(), peer_id.clone(), COST_UNEXPECTED_MESSAGE).await;
modify_reputation(ctx.sender(), peer_id, COST_UNEXPECTED_MESSAGE).await;
},
}
// if the assignment is known to be valid, reward the peer
if entry.knowledge.contains(&message_subject, message_kind) {
modify_reputation(ctx.sender(), peer_id.clone(), BENEFIT_VALID_MESSAGE).await;
modify_reputation(ctx.sender(), peer_id, BENEFIT_VALID_MESSAGE).await;
if let Some(peer_knowledge) = entry.known_by.get_mut(&peer_id) {
gum::trace!(target: LOG_TARGET, ?peer_id, ?message_subject, "Known assignment");
peer_knowledge.received.insert(message_subject, message_kind);
@@ -803,8 +801,7 @@ impl State {
);
match result {
AssignmentCheckResult::Accepted => {
modify_reputation(ctx.sender(), peer_id.clone(), BENEFIT_VALID_MESSAGE_FIRST)
.await;
modify_reputation(ctx.sender(), peer_id, BENEFIT_VALID_MESSAGE_FIRST).await;
entry.knowledge.known_messages.insert(message_subject.clone(), message_kind);
if let Some(peer_knowledge) = entry.known_by.get_mut(&peer_id) {
peer_knowledge.received.insert(message_subject.clone(), message_kind);
@@ -970,7 +967,7 @@ impl State {
source: MessageSource,
vote: IndirectSignedApprovalVote,
) {
let block_hash = vote.block_hash.clone();
let block_hash = vote.block_hash;
let validator_index = vote.validator;
let candidate_index = vote.candidate_index;
@@ -1003,7 +1000,7 @@ impl State {
}
// check if our knowledge of the peer already contains this approval
match entry.known_by.entry(peer_id.clone()) {
match entry.known_by.entry(peer_id) {
hash_map::Entry::Occupied(mut knowledge) => {
let peer_knowledge = knowledge.get_mut();
if peer_knowledge.contains(&message_subject, message_kind) {
@@ -1027,14 +1024,14 @@ impl State {
?message_subject,
"Approval from a peer is out of view",
);
modify_reputation(ctx.sender(), peer_id.clone(), COST_UNEXPECTED_MESSAGE).await;
modify_reputation(ctx.sender(), peer_id, COST_UNEXPECTED_MESSAGE).await;
},
}
// if the approval is known to be valid, reward the peer
if entry.knowledge.contains(&message_subject, message_kind) {
gum::trace!(target: LOG_TARGET, ?peer_id, ?message_subject, "Known approval");
modify_reputation(ctx.sender(), peer_id.clone(), BENEFIT_VALID_MESSAGE).await;
modify_reputation(ctx.sender(), peer_id, BENEFIT_VALID_MESSAGE).await;
if let Some(peer_knowledge) = entry.known_by.get_mut(&peer_id) {
peer_knowledge.received.insert(message_subject.clone(), message_kind);
}
@@ -1065,8 +1062,7 @@ impl State {
);
match result {
ApprovalCheckResult::Accepted => {
modify_reputation(ctx.sender(), peer_id.clone(), BENEFIT_VALID_MESSAGE_FIRST)
.await;
modify_reputation(ctx.sender(), peer_id, BENEFIT_VALID_MESSAGE_FIRST).await;
entry.knowledge.insert(message_subject.clone(), message_kind);
if let Some(peer_knowledge) = entry.known_by.get_mut(&peer_id) {
@@ -1301,7 +1297,7 @@ impl State {
break
}
let peer_knowledge = entry.known_by.entry(peer_id.clone()).or_default();
let peer_knowledge = entry.known_by.entry(peer_id).or_default();
let topology = topologies.get_topology(entry.session);
@@ -1335,13 +1331,12 @@ impl State {
}
}
let message_subject =
MessageSubject(block.clone(), candidate_index, validator.clone());
let message_subject = MessageSubject(block, candidate_index, *validator);
let assignment_message = (
IndirectAssignmentCert {
block_hash: block.clone(),
validator: validator.clone(),
block_hash: block,
validator: *validator,
cert: message_state.approval_state.assignment_cert().clone(),
},
candidate_index,
@@ -1350,8 +1345,8 @@ impl State {
let approval_message =
message_state.approval_state.approval_signature().map(|signature| {
IndirectSignedApprovalVote {
block_hash: block.clone(),
validator: validator.clone(),
block_hash: block,
validator: *validator,
candidate_index,
signature,
}
@@ -1374,7 +1369,7 @@ impl State {
}
}
block = entry.parent_hash.clone();
block = entry.parent_hash;
}
}
@@ -1388,7 +1383,7 @@ impl State {
sender
.send_message(NetworkBridgeTxMessage::SendValidationMessage(
vec![peer_id.clone()],
vec![peer_id],
Versioned::V1(protocol_v1::ValidationProtocol::ApprovalDistribution(
protocol_v1::ApprovalDistributionMessage::Assignments(assignments_to_send),
)),
@@ -1558,13 +1553,12 @@ async fn adjust_required_routing_and_propagate<Context, BlockFilter, RoutingModi
};
// Propagate the message to all peers in the required routing set.
let message_subject =
MessageSubject(block_hash.clone(), candidate_index, validator.clone());
let message_subject = MessageSubject(*block_hash, candidate_index, *validator);
let assignment_message = (
IndirectAssignmentCert {
block_hash: block_hash.clone(),
validator: validator.clone(),
block_hash: *block_hash,
validator: *validator,
cert: message_state.approval_state.assignment_cert().clone(),
},
candidate_index,
@@ -1572,8 +1566,8 @@ async fn adjust_required_routing_and_propagate<Context, BlockFilter, RoutingModi
let approval_message =
message_state.approval_state.approval_signature().map(|signature| {
IndirectSignedApprovalVote {
block_hash: block_hash.clone(),
validator: validator.clone(),
block_hash: *block_hash,
validator: *validator,
candidate_index,
signature,
}
@@ -1590,7 +1584,7 @@ async fn adjust_required_routing_and_propagate<Context, BlockFilter, RoutingModi
if !peer_knowledge.contains(&message_subject, MessageKind::Assignment) {
peer_knowledge.sent.insert(message_subject.clone(), MessageKind::Assignment);
peer_assignments
.entry(peer.clone())
.entry(*peer)
.or_insert_with(Vec::new)
.push(assignment_message.clone());
}
@@ -1599,7 +1593,7 @@ async fn adjust_required_routing_and_propagate<Context, BlockFilter, RoutingModi
if !peer_knowledge.contains(&message_subject, MessageKind::Approval) {
peer_knowledge.sent.insert(message_subject.clone(), MessageKind::Approval);
peer_approvals
.entry(peer.clone())
.entry(*peer)
.or_insert_with(Vec::new)
.push(approval_message.clone());
}