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
+17 -17
View File
@@ -52,7 +52,7 @@ fn add_proposal<T: Config>(n: u32) -> Result<T::Hash, &'static str> {
let value = T::MinimumDeposit::get();
let proposal_hash: T::Hash = T::Hashing::hash_of(&n);
Democracy::<T>::propose(RawOrigin::Signed(other).into(), proposal_hash, value.into())?;
Democracy::<T>::propose(RawOrigin::Signed(other).into(), proposal_hash, value)?;
Ok(proposal_hash)
}
@@ -98,7 +98,7 @@ benchmarks! {
let proposal_hash: T::Hash = T::Hashing::hash_of(&0);
let value = T::MinimumDeposit::get();
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller), proposal_hash, value.into())
}: _(RawOrigin::Signed(caller), proposal_hash, value)
verify {
assert_eq!(Democracy::<T>::public_props().len(), p as usize, "Proposals not created.");
}
@@ -133,7 +133,7 @@ benchmarks! {
// We need to create existing direct votes
for i in 0 .. r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote.clone())?;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote)?;
}
let votes = match VotingOf::<T>::get(&caller) {
Voting::Direct { votes, .. } => votes,
@@ -161,7 +161,7 @@ benchmarks! {
// We need to create existing direct votes
for i in 0 ..=r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote.clone())?;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote)?;
}
let votes = match VotingOf::<T>::get(&caller) {
Voting::Direct { votes, .. } => votes,
@@ -217,7 +217,7 @@ benchmarks! {
// Place our proposal in the external queue, too.
let hash = T::Hashing::hash_of(&0);
assert_ok!(
Democracy::<T>::external_propose(T::ExternalOrigin::successful_origin(), hash.clone())
Democracy::<T>::external_propose(T::ExternalOrigin::successful_origin(), hash)
);
let origin = T::BlacklistOrigin::successful_origin();
// Add a referendum of our proposal.
@@ -275,13 +275,13 @@ benchmarks! {
fast_track {
let origin_propose = T::ExternalDefaultOrigin::successful_origin();
let proposal_hash: T::Hash = T::Hashing::hash_of(&0);
Democracy::<T>::external_propose_default(origin_propose, proposal_hash.clone())?;
Democracy::<T>::external_propose_default(origin_propose, proposal_hash)?;
// NOTE: Instant origin may invoke a little bit more logic, but may not always succeed.
let origin_fast_track = T::FastTrackOrigin::successful_origin();
let voting_period = T::FastTrackVotingPeriod::get();
let delay = 0u32;
}: _<T::Origin>(origin_fast_track, proposal_hash, voting_period.into(), delay.into())
}: _<T::Origin>(origin_fast_track, proposal_hash, voting_period, delay.into())
verify {
assert_eq!(Democracy::<T>::referendum_count(), 1, "referendum not created")
}
@@ -293,7 +293,7 @@ benchmarks! {
let proposal_hash: T::Hash = T::Hashing::hash_of(&v);
let origin_propose = T::ExternalDefaultOrigin::successful_origin();
Democracy::<T>::external_propose_default(origin_propose, proposal_hash.clone())?;
Democracy::<T>::external_propose_default(origin_propose, proposal_hash)?;
let mut vetoers: Vec<T::AccountId> = Vec::new();
for i in 0 .. v {
@@ -499,7 +499,7 @@ benchmarks! {
// We need to create existing direct votes for the `new_delegate`
for i in 0..r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(new_delegate.clone()).into(), ref_idx, account_vote.clone())?;
Democracy::<T>::vote(RawOrigin::Signed(new_delegate.clone()).into(), ref_idx, account_vote)?;
}
let votes = match VotingOf::<T>::get(&new_delegate) {
Voting::Direct { votes, .. } => votes,
@@ -550,7 +550,7 @@ benchmarks! {
Democracy::<T>::vote(
RawOrigin::Signed(the_delegate.clone()).into(),
ref_idx,
account_vote.clone()
account_vote
)?;
}
let votes = match VotingOf::<T>::get(&the_delegate) {
@@ -619,17 +619,17 @@ benchmarks! {
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
let submitter = funded_account::<T>("submitter", b);
Democracy::<T>::note_preimage(RawOrigin::Signed(submitter.clone()).into(), encoded_proposal.clone())?;
Democracy::<T>::note_preimage(RawOrigin::Signed(submitter).into(), encoded_proposal.clone())?;
// We need to set this otherwise we get `Early` error.
let block_number = T::VotingPeriod::get() + T::EnactmentPeriod::get() + T::BlockNumber::one();
System::<T>::set_block_number(block_number.into());
System::<T>::set_block_number(block_number);
assert!(Preimages::<T>::contains_key(proposal_hash));
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller), proposal_hash.clone(), u32::MAX)
}: _(RawOrigin::Signed(caller), proposal_hash, u32::MAX)
verify {
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
assert!(!Preimages::<T>::contains_key(proposal_hash));
@@ -646,7 +646,7 @@ benchmarks! {
// Vote and immediately unvote
for i in 0 .. r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(locker.clone()).into(), ref_idx, small_vote.clone())?;
Democracy::<T>::vote(RawOrigin::Signed(locker.clone()).into(), ref_idx, small_vote)?;
Democracy::<T>::remove_vote(RawOrigin::Signed(locker.clone()).into(), ref_idx)?;
}
@@ -669,7 +669,7 @@ benchmarks! {
let small_vote = account_vote::<T>(base_balance);
for i in 0 .. r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(locker.clone()).into(), ref_idx, small_vote.clone())?;
Democracy::<T>::vote(RawOrigin::Signed(locker.clone()).into(), ref_idx, small_vote)?;
}
// Create a big vote so lock increases
@@ -711,7 +711,7 @@ benchmarks! {
for i in 0 .. r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote.clone())?;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote)?;
}
let votes = match VotingOf::<T>::get(&caller) {
@@ -740,7 +740,7 @@ benchmarks! {
for i in 0 .. r {
let ref_idx = add_referendum::<T>(i)?;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote.clone())?;
Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote)?;
}
let votes = match VotingOf::<T>::get(&caller) {
+11 -16
View File
@@ -670,8 +670,7 @@ pub mod pallet {
) -> DispatchResult {
let who = ensure_signed(origin)?;
let seconds =
Self::len_of_deposit_of(proposal).ok_or_else(|| Error::<T>::ProposalMissing)?;
let seconds = Self::len_of_deposit_of(proposal).ok_or(Error::<T>::ProposalMissing)?;
ensure!(seconds <= seconds_upper_bound, Error::<T>::WrongUpperBound);
let mut deposit = Self::deposit_of(proposal).ok_or(Error::<T>::ProposalMissing)?;
T::Currency::reserve(&who, deposit.1)?;
@@ -820,12 +819,10 @@ pub mod pallet {
// - `InstantAllowed` is `true` and `origin` is `InstantOrigin`.
let maybe_ensure_instant = if voting_period < T::FastTrackVotingPeriod::get() {
Some(origin)
} else if let Err(origin) = T::FastTrackOrigin::try_origin(origin) {
Some(origin)
} else {
if let Err(origin) = T::FastTrackOrigin::try_origin(origin) {
Some(origin)
} else {
None
}
None
};
if let Some(ensure_instant) = maybe_ensure_instant {
T::InstantOrigin::ensure_origin(ensure_instant)?;
@@ -867,7 +864,7 @@ pub mod pallet {
if let Some((e_proposal_hash, _)) = <NextExternal<T>>::get() {
ensure!(proposal_hash == e_proposal_hash, Error::<T>::ProposalMissing);
} else {
Err(Error::<T>::NoProposal)?;
return Err(Error::<T>::NoProposal.into())
}
let mut existing_vetoers =
@@ -966,7 +963,7 @@ pub mod pallet {
/// voted on. Weight is charged as if maximum votes.
// NOTE: weight must cover an incorrect voting of origin with max votes, this is ensure
// because a valid delegation cover decoding a direct voting with max votes.
#[pallet::weight(T::WeightInfo::undelegate(T::MaxVotes::get().into()))]
#[pallet::weight(T::WeightInfo::undelegate(T::MaxVotes::get()))]
pub fn undelegate(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
let votes = Self::try_undelegate(who)?;
@@ -1634,7 +1631,7 @@ impl<T: Config> Pallet<T> {
);
Ok(())
} else {
Err(Error::<T>::NoneWaiting)?
return Err(Error::<T>::NoneWaiting.into())
}
}
@@ -1667,7 +1664,7 @@ impl<T: Config> Pallet<T> {
}
Ok(())
} else {
Err(Error::<T>::NoneWaiting)?
return Err(Error::<T>::NoneWaiting.into())
}
}
@@ -1822,8 +1819,7 @@ impl<T: Config> Pallet<T> {
// To decode the enum variant we only need the first byte.
let mut buf = [0u8; 1];
let key = <Preimages<T>>::hashed_key_for(proposal_hash);
let bytes =
sp_io::storage::read(&key, &mut buf, 0).ok_or_else(|| Error::<T>::NotImminent)?;
let bytes = sp_io::storage::read(&key, &mut buf, 0).ok_or(Error::<T>::NotImminent)?;
// The value may be smaller that 1 byte.
let mut input = &buf[0..buf.len().min(bytes as usize)];
@@ -1851,8 +1847,7 @@ impl<T: Config> Pallet<T> {
// * at most 5 bytes to decode a `Compact<u32>`
let mut buf = [0u8; 6];
let key = <Preimages<T>>::hashed_key_for(proposal_hash);
let bytes =
sp_io::storage::read(&key, &mut buf, 0).ok_or_else(|| Error::<T>::PreimageMissing)?;
let bytes = sp_io::storage::read(&key, &mut buf, 0).ok_or(Error::<T>::PreimageMissing)?;
// The value may be smaller that 6 bytes.
let mut input = &buf[0..buf.len().min(bytes as usize)];
@@ -1931,7 +1926,7 @@ impl<T: Config> Pallet<T> {
fn decode_compact_u32_at(key: &[u8]) -> Option<u32> {
// `Compact<u32>` takes at most 5 bytes.
let mut buf = [0u8; 5];
let bytes = sp_io::storage::read(&key, &mut buf, 0)?;
let bytes = sp_io::storage::read(key, &mut buf, 0)?;
// The value may be smaller than 5 bytes.
let mut input = &buf[0..buf.len().min(bytes as usize)];
match codec::Compact::<u32>::decode(&mut input) {