Apply some clippy lints (#11154)

* Apply some clippy hints

* Revert clippy ci changes

* Update client/cli/src/commands/generate.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/cli/src/commands/inspect_key.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/service/src/client/block_rules.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/service/src/client/block_rules.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/network/src/transactions.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/network/src/protocol.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Revert due to missing `or_default` function.

* Fix compilation and simplify code

* Undo change that corrupts benchmark.

* fix clippy

* Update client/service/test/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/state-db/src/noncanonical.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/state-db/src/noncanonical.rs

remove leftovers!

* Update client/tracing/src/logging/directives.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/fork-tree/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* added needed ref

* Update frame/referenda/src/benchmarking.rs

* Simplify byte-vec creation

* let's just not overlap the ranges

* Correction

* cargo fmt

* Update utils/frame/benchmarking-cli/src/shared/stats.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/frame/benchmarking-cli/src/pallet/command.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/frame/benchmarking-cli/src/pallet/command.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Giles Cope <gilescope@gmail.com>
This commit is contained in:
Falco Hirschenberger
2022-04-30 23:28:27 +02:00
committed by GitHub
parent a990473cf9
commit b581604aa7
368 changed files with 1927 additions and 2236 deletions
+32 -52
View File
@@ -374,7 +374,7 @@ where
let node = self.roots.swap_remove(position);
self.roots = node.children;
self.best_finalized_number = Some(node.number);
return node.data
node.data
}
/// Finalize a node in the tree. This method will make sure that the node
@@ -539,18 +539,17 @@ where
// tree, if we find a valid node that passes the predicate then we must
// ensure that we're not finalizing past any of its child nodes.
for node in self.node_iter() {
if predicate(&node.data) {
if node.hash == *hash || is_descendent_of(&node.hash, hash)? {
for child in node.children.iter() {
if child.number <= number &&
(child.hash == *hash || is_descendent_of(&child.hash, hash)?)
{
return Err(Error::UnfinalizedAncestor)
}
if predicate(&node.data) && (node.hash == *hash || is_descendent_of(&node.hash, hash)?)
{
for child in node.children.iter() {
if child.number <= number &&
(child.hash == *hash || is_descendent_of(&child.hash, hash)?)
{
return Err(Error::UnfinalizedAncestor)
}
return Ok(Some(self.roots.iter().any(|root| root.hash == node.hash)))
}
return Ok(Some(self.roots.iter().any(|root| root.hash == node.hash)))
}
}
@@ -587,19 +586,18 @@ where
// we're not finalizing past any children node.
let mut position = None;
for (i, root) in self.roots.iter().enumerate() {
if predicate(&root.data) {
if root.hash == *hash || is_descendent_of(&root.hash, hash)? {
for child in root.children.iter() {
if child.number <= number &&
(child.hash == *hash || is_descendent_of(&child.hash, hash)?)
{
return Err(Error::UnfinalizedAncestor)
}
if predicate(&root.data) && (root.hash == *hash || is_descendent_of(&root.hash, hash)?)
{
for child in root.children.iter() {
if child.number <= number &&
(child.hash == *hash || is_descendent_of(&child.hash, hash)?)
{
return Err(Error::UnfinalizedAncestor)
}
position = Some(i);
break
}
position = Some(i);
break
}
}
@@ -1071,16 +1069,13 @@ mod test {
let finalize_a = || {
let (mut tree, ..) = test_fork_tree();
assert_eq!(
tree.roots().map(|(h, n, _)| (h.clone(), n.clone())).collect::<Vec<_>>(),
vec![("A", 1)],
);
assert_eq!(tree.roots().map(|(h, n, _)| (*h, *n)).collect::<Vec<_>>(), vec![("A", 1)]);
// finalizing "A" opens up three possible forks
tree.finalize_root(&"A");
assert_eq!(
tree.roots().map(|(h, n, _)| (h.clone(), n.clone())).collect::<Vec<_>>(),
tree.roots().map(|(h, n, _)| (*h, *n)).collect::<Vec<_>>(),
vec![("B", 2), ("F", 2), ("J", 2)],
);
@@ -1093,10 +1088,7 @@ mod test {
// finalizing "B" will progress on its fork and remove any other competing forks
tree.finalize_root(&"B");
assert_eq!(
tree.roots().map(|(h, n, _)| (h.clone(), n.clone())).collect::<Vec<_>>(),
vec![("C", 3)],
);
assert_eq!(tree.roots().map(|(h, n, _)| (*h, *n)).collect::<Vec<_>>(), vec![("C", 3)],);
// all the other forks have been pruned
assert!(tree.roots.len() == 1);
@@ -1108,10 +1100,7 @@ mod test {
// finalizing "J" will progress on its fork and remove any other competing forks
tree.finalize_root(&"J");
assert_eq!(
tree.roots().map(|(h, n, _)| (h.clone(), n.clone())).collect::<Vec<_>>(),
vec![("K", 3)],
);
assert_eq!(tree.roots().map(|(h, n, _)| (*h, *n)).collect::<Vec<_>>(), vec![("K", 3)],);
// all the other forks have been pruned
assert!(tree.roots.len() == 1);
@@ -1136,7 +1125,7 @@ mod test {
);
assert_eq!(
tree.roots().map(|(h, n, _)| (h.clone(), n.clone())).collect::<Vec<_>>(),
tree.roots().map(|(h, n, _)| (*h, *n)).collect::<Vec<_>>(),
vec![("B", 2), ("F", 2), ("J", 2)],
);
@@ -1160,7 +1149,7 @@ mod test {
);
assert_eq!(
tree.roots().map(|(h, n, _)| (h.clone(), n.clone())).collect::<Vec<_>>(),
tree.roots().map(|(h, n, _)| (*h, *n)).collect::<Vec<_>>(),
vec![("L", 4), ("I", 4)],
);
@@ -1194,7 +1183,7 @@ mod test {
);
assert_eq!(
tree.roots().map(|(h, n, _)| (h.clone(), n.clone())).collect::<Vec<_>>(),
tree.roots().map(|(h, n, _)| (*h, *n)).collect::<Vec<_>>(),
vec![("B", 2), ("F", 2), ("J", 2)],
);
@@ -1208,7 +1197,7 @@ mod test {
);
assert_eq!(
tree.roots().map(|(h, n, _)| (h.clone(), n.clone())).collect::<Vec<_>>(),
tree.roots().map(|(h, n, _)| (*h, *n)).collect::<Vec<_>>(),
vec![("L", 4), ("I", 4)],
);
@@ -1224,10 +1213,7 @@ mod test {
Ok(FinalizationResult::Changed(None)),
);
assert_eq!(
tree.roots().map(|(h, n, _)| (h.clone(), n.clone())).collect::<Vec<_>>(),
vec![],
);
assert_eq!(tree.roots().map(|(h, n, _)| (*h, *n)).collect::<Vec<_>>(), vec![],);
assert_eq!(tree.best_finalized_number, Some(6));
}
@@ -1306,10 +1292,7 @@ mod test {
Ok(FinalizationResult::Changed(None)),
);
assert_eq!(
tree.roots().map(|(h, n, _)| (h.clone(), n.clone())).collect::<Vec<_>>(),
vec![("A0", 1)],
);
assert_eq!(tree.roots().map(|(h, n, _)| (*h, *n)).collect::<Vec<_>>(), vec![("A0", 1)],);
// finalizing "C" will finalize the node "A0" and prune it out of the tree
assert_eq!(
@@ -1327,10 +1310,7 @@ mod test {
Ok(FinalizationResult::Changed(Some(Change { effective: 5 }))),
);
assert_eq!(
tree.roots().map(|(h, n, _)| (h.clone(), n.clone())).collect::<Vec<_>>(),
vec![("D", 10)],
);
assert_eq!(tree.roots().map(|(h, n, _)| (*h, *n)).collect::<Vec<_>>(), vec![("D", 10)],);
// finalizing "F" will fail since it would finalize past "E" without finalizing "D" first
assert_eq!(
@@ -1359,7 +1339,7 @@ mod test {
fn iter_iterates_in_preorder() {
let (tree, ..) = test_fork_tree();
assert_eq!(
tree.iter().map(|(h, n, _)| (h.clone(), n.clone())).collect::<Vec<_>>(),
tree.iter().map(|(h, n, _)| (*h, *n)).collect::<Vec<_>>(),
vec![
("A", 1),
("B", 2),