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
@@ -491,7 +491,7 @@ frame_benchmarking::benchmarks! {
// sort assignments by decreasing voter stake
assignments.sort_by_key(|crate::unsigned::Assignment::<T> { who, .. }| {
let stake = cache.get(&who).map(|idx| {
let stake = cache.get(who).map(|idx| {
let (_, stake, _) = voters[*idx];
stake
}).unwrap_or_default();
@@ -264,7 +264,7 @@ mod mock;
#[macro_use]
pub mod helpers;
const LOG_TARGET: &'static str = "runtime::election-provider";
const LOG_TARGET: &str = "runtime::election-provider";
pub mod signed;
pub mod unsigned;
@@ -1446,7 +1446,7 @@ impl<T: Config> Pallet<T> {
ensure!(winners.len() as u32 == desired_targets, FeasibilityError::WrongWinnerCount);
// Ensure that the solution's score can pass absolute min-score.
let submitted_score = raw_solution.score.clone();
let submitted_score = raw_solution.score;
ensure!(
Self::minimum_untrusted_score().map_or(true, |min_score| {
submitted_score.strict_threshold_better(min_score, Perbill::zero())
@@ -1471,29 +1471,26 @@ impl<T: Config> Pallet<T> {
.map_err::<FeasibilityError, _>(Into::into)?;
// Ensure that assignments is correct.
let _ = assignments
.iter()
.map(|ref assignment| {
// Check that assignment.who is actually a voter (defensive-only).
// NOTE: while using the index map from `voter_index` is better than a blind linear
// search, this *still* has room for optimization. Note that we had the index when
// we did `solution -> assignment` and we lost it. Ideal is to keep the index
// around.
let _ = assignments.iter().try_for_each(|assignment| {
// Check that assignment.who is actually a voter (defensive-only).
// NOTE: while using the index map from `voter_index` is better than a blind linear
// search, this *still* has room for optimization. Note that we had the index when
// we did `solution -> assignment` and we lost it. Ideal is to keep the index
// around.
// Defensive-only: must exist in the snapshot.
let snapshot_index =
voter_index(&assignment.who).ok_or(FeasibilityError::InvalidVoter)?;
// Defensive-only: index comes from the snapshot, must exist.
let (_voter, _stake, targets) =
snapshot_voters.get(snapshot_index).ok_or(FeasibilityError::InvalidVoter)?;
// Defensive-only: must exist in the snapshot.
let snapshot_index =
voter_index(&assignment.who).ok_or(FeasibilityError::InvalidVoter)?;
// Defensive-only: index comes from the snapshot, must exist.
let (_voter, _stake, targets) =
snapshot_voters.get(snapshot_index).ok_or(FeasibilityError::InvalidVoter)?;
// Check that all of the targets are valid based on the snapshot.
if assignment.distribution.iter().any(|(d, _)| !targets.contains(d)) {
return Err(FeasibilityError::InvalidVote)
}
Ok(())
})
.collect::<Result<(), FeasibilityError>>()?;
// Check that all of the targets are valid based on the snapshot.
if assignment.distribution.iter().any(|(d, _)| !targets.contains(d)) {
return Err(FeasibilityError::InvalidVote)
}
Ok(())
})?;
// ----- Start building support. First, we need one more closure.
let stake_of = helpers::stake_of_fn::<T>(&snapshot_voters, &cache);
@@ -99,7 +99,7 @@ impl<T: Config> From<FeasibilityError> for MinerError<T> {
/// Save a given call into OCW storage.
fn save_solution<T: Config>(call: &Call<T>) -> Result<(), MinerError<T>> {
log!(debug, "saving a call to the offchain storage.");
let storage = StorageValueRef::persistent(&OFFCHAIN_CACHED_CALL);
let storage = StorageValueRef::persistent(OFFCHAIN_CACHED_CALL);
match storage.mutate::<_, (), _>(|_| Ok(call.clone())) {
Ok(_) => Ok(()),
Err(MutateStorageError::ConcurrentModification(_)) =>
@@ -116,7 +116,7 @@ fn save_solution<T: Config>(call: &Call<T>) -> Result<(), MinerError<T>> {
/// Get a saved solution from OCW storage if it exists.
fn restore_solution<T: Config>() -> Result<Call<T>, MinerError<T>> {
StorageValueRef::persistent(&OFFCHAIN_CACHED_CALL)
StorageValueRef::persistent(OFFCHAIN_CACHED_CALL)
.get()
.ok()
.flatten()
@@ -126,7 +126,7 @@ fn restore_solution<T: Config>() -> Result<Call<T>, MinerError<T>> {
/// Clear a saved solution from OCW storage.
pub(super) fn kill_ocw_solution<T: Config>() {
log!(debug, "clearing offchain call cache storage.");
let mut storage = StorageValueRef::persistent(&OFFCHAIN_CACHED_CALL);
let mut storage = StorageValueRef::persistent(OFFCHAIN_CACHED_CALL);
storage.clear();
}
@@ -135,14 +135,14 @@ pub(super) fn kill_ocw_solution<T: Config>() {
/// After calling this, the next offchain worker is guaranteed to work, with respect to the
/// frequency repeat.
fn clear_offchain_repeat_frequency() {
let mut last_block = StorageValueRef::persistent(&OFFCHAIN_LAST_BLOCK);
let mut last_block = StorageValueRef::persistent(OFFCHAIN_LAST_BLOCK);
last_block.clear();
}
/// `true` when OCW storage contains a solution
#[cfg(test)]
fn ocw_solution_exists<T: Config>() -> bool {
matches!(StorageValueRef::persistent(&OFFCHAIN_CACHED_CALL).get::<Call<T>>(), Ok(Some(_)))
matches!(StorageValueRef::persistent(OFFCHAIN_CACHED_CALL).get::<Call<T>>(), Ok(Some(_)))
}
impl<T: Config> Pallet<T> {
@@ -206,9 +206,8 @@ impl<T: Config> Pallet<T> {
// get the solution, with a load of checks to ensure if submitted, IT IS ABSOLUTELY VALID.
let (raw_solution, witness) = Self::mine_and_check()?;
let score = raw_solution.score.clone();
let call: Call<T> =
Call::submit_unsigned { raw_solution: Box::new(raw_solution), witness }.into();
let score = raw_solution.score;
let call: Call<T> = Call::submit_unsigned { raw_solution: Box::new(raw_solution), witness };
log!(
debug,
@@ -532,7 +531,7 @@ impl<T: Config> Pallet<T> {
// we found the right value - early exit the function.
Ok(next) => return next,
}
step = step / 2;
step /= 2;
current_weight = weight_with(voters);
}
@@ -566,7 +565,7 @@ impl<T: Config> Pallet<T> {
/// is returned, `now` is written in storage and will be used in further calls as the baseline.
pub fn ensure_offchain_repeat_frequency(now: T::BlockNumber) -> Result<(), MinerError<T>> {
let threshold = T::OffchainRepeat::get();
let last_block = StorageValueRef::persistent(&OFFCHAIN_LAST_BLOCK);
let last_block = StorageValueRef::persistent(OFFCHAIN_LAST_BLOCK);
let mutate_stat = last_block.mutate::<_, &'static str, _>(
|maybe_head: Result<Option<T::BlockNumber>, _>| {