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
+12 -12
View File
@@ -62,7 +62,7 @@ benchmarks! {
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
let (preimage, hash) = sized_preimage_and_hash::<T>(s);
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash.clone()));
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
}: note_preimage(RawOrigin::Signed(caller), preimage)
verify {
assert!(Preimage::<T>::have_preimage(&hash));
@@ -71,7 +71,7 @@ benchmarks! {
note_no_deposit_preimage {
let s in 0 .. T::MaxSize::get();
let (preimage, hash) = sized_preimage_and_hash::<T>(s);
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash.clone()));
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
}: note_preimage<T::Origin>(T::ManagerOrigin::successful_origin(), preimage)
verify {
assert!(Preimage::<T>::have_preimage(&hash));
@@ -83,7 +83,7 @@ benchmarks! {
whitelist_account!(caller);
let (preimage, hash) = preimage_and_hash::<T>();
assert_ok!(Preimage::<T>::note_preimage(RawOrigin::Signed(caller.clone()).into(), preimage));
}: _(RawOrigin::Signed(caller), hash.clone())
}: _(RawOrigin::Signed(caller), hash)
verify {
assert!(!Preimage::<T>::have_preimage(&hash));
}
@@ -91,7 +91,7 @@ benchmarks! {
unnote_no_deposit_preimage {
let (preimage, hash) = preimage_and_hash::<T>();
assert_ok!(Preimage::<T>::note_preimage(T::ManagerOrigin::successful_origin(), preimage));
}: unnote_preimage<T::Origin>(T::ManagerOrigin::successful_origin(), hash.clone())
}: unnote_preimage<T::Origin>(T::ManagerOrigin::successful_origin(), hash)
verify {
assert!(!Preimage::<T>::have_preimage(&hash));
}
@@ -124,7 +124,7 @@ benchmarks! {
// Cheap request - the preimage is already requested, so just a counter bump.
request_requested_preimage {
let (_, hash) = preimage_and_hash::<T>();
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash.clone()));
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
}: request_preimage<T::Origin>(T::ManagerOrigin::successful_origin(), hash)
verify {
assert_eq!(StatusFor::<T>::get(&hash), Some(RequestStatus::Requested(2)));
@@ -133,26 +133,26 @@ benchmarks! {
// Expensive unrequest - last reference and it's noted, so will destroy the preimage.
unrequest_preimage {
let (preimage, hash) = preimage_and_hash::<T>();
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash.clone()));
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
assert_ok!(Preimage::<T>::note_preimage(T::ManagerOrigin::successful_origin(), preimage));
}: _<T::Origin>(T::ManagerOrigin::successful_origin(), hash.clone())
}: _<T::Origin>(T::ManagerOrigin::successful_origin(), hash)
verify {
assert_eq!(StatusFor::<T>::get(&hash), None);
}
// Cheap unrequest - last reference, but it's not noted.
unrequest_unnoted_preimage {
let (_, hash) = preimage_and_hash::<T>();
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash.clone()));
}: unrequest_preimage<T::Origin>(T::ManagerOrigin::successful_origin(), hash.clone())
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
}: unrequest_preimage<T::Origin>(T::ManagerOrigin::successful_origin(), hash)
verify {
assert_eq!(StatusFor::<T>::get(&hash), None);
}
// Cheap unrequest - not the last reference.
unrequest_multi_referenced_preimage {
let (_, hash) = preimage_and_hash::<T>();
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash.clone()));
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash.clone()));
}: unrequest_preimage<T::Origin>(T::ManagerOrigin::successful_origin(), hash.clone())
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
}: unrequest_preimage<T::Origin>(T::ManagerOrigin::successful_origin(), hash)
verify {
assert_eq!(StatusFor::<T>::get(&hash), Some(RequestStatus::Requested(1)));
}
+8 -10
View File
@@ -215,7 +215,8 @@ impl<T: Config> Pallet<T> {
// previously requested. This also allows the tx to pay no fee.
let was_requested = match (StatusFor::<T>::get(hash), maybe_depositor) {
(Some(RequestStatus::Requested(..)), _) => true,
(Some(RequestStatus::Unrequested(..)), _) => Err(Error::<T>::AlreadyNoted)?,
(Some(RequestStatus::Unrequested(..)), _) =>
return Err(Error::<T>::AlreadyNoted.into()),
(None, None) => {
StatusFor::<T>::insert(hash, RequestStatus::Unrequested(None));
false
@@ -256,7 +257,7 @@ impl<T: Config> Pallet<T> {
});
StatusFor::<T>::insert(hash, RequestStatus::Requested(count));
if count == 1 {
Self::deposit_event(Event::Requested { hash: hash.clone() });
Self::deposit_event(Event::Requested { hash: *hash });
}
}
@@ -270,20 +271,17 @@ impl<T: Config> Pallet<T> {
) -> DispatchResult {
match StatusFor::<T>::get(hash).ok_or(Error::<T>::NotNoted)? {
RequestStatus::Unrequested(Some((owner, deposit))) => {
ensure!(
maybe_check_owner.map_or(true, |c| &c == &owner),
Error::<T>::NotAuthorized
);
ensure!(maybe_check_owner.map_or(true, |c| c == owner), Error::<T>::NotAuthorized);
T::Currency::unreserve(&owner, deposit);
},
RequestStatus::Unrequested(None) => {
ensure!(maybe_check_owner.is_none(), Error::<T>::NotAuthorized);
},
RequestStatus::Requested(_) => Err(Error::<T>::Requested)?,
RequestStatus::Requested(_) => return Err(Error::<T>::Requested.into()),
}
StatusFor::<T>::remove(hash);
PreimageFor::<T>::remove(hash);
Self::deposit_event(Event::Cleared { hash: hash.clone() });
Self::deposit_event(Event::Cleared { hash: *hash });
Ok(())
}
@@ -298,9 +296,9 @@ impl<T: Config> Pallet<T> {
debug_assert!(count == 1, "preimage request counter at zero?");
PreimageFor::<T>::remove(hash);
StatusFor::<T>::remove(hash);
Self::deposit_event(Event::Cleared { hash: hash.clone() });
Self::deposit_event(Event::Cleared { hash: *hash });
},
RequestStatus::Unrequested(_) => Err(Error::<T>::NotRequested)?,
RequestStatus::Unrequested(_) => return Err(Error::<T>::NotRequested.into()),
}
Ok(())
}