mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-19 07:35:41 +00:00
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:
committed by
GitHub
parent
a990473cf9
commit
b581604aa7
@@ -49,13 +49,9 @@ where
|
||||
for<'r> FS: Fn(&'r A) -> VoteWeight,
|
||||
{
|
||||
let mut staked = assignment_ratio_to_staked(ratio, &stake_of);
|
||||
staked
|
||||
.iter_mut()
|
||||
.map(|a| {
|
||||
a.try_normalize(stake_of(&a.who).into())
|
||||
.map_err(|err| Error::ArithmeticError(err))
|
||||
})
|
||||
.collect::<Result<_, _>>()?;
|
||||
staked.iter_mut().try_for_each(|a| {
|
||||
a.try_normalize(stake_of(&a.who).into()).map_err(Error::ArithmeticError)
|
||||
})?;
|
||||
Ok(staked)
|
||||
}
|
||||
|
||||
@@ -74,7 +70,7 @@ pub fn assignment_staked_to_ratio_normalized<A: IdentifierT, P: PerThing128>(
|
||||
) -> Result<Vec<Assignment<A, P>>, Error> {
|
||||
let mut ratio = staked.into_iter().map(|a| a.into_assignment()).collect::<Vec<_>>();
|
||||
for assignment in ratio.iter_mut() {
|
||||
assignment.try_normalize().map_err(|err| Error::ArithmeticError(err))?;
|
||||
assignment.try_normalize().map_err(Error::ArithmeticError)?;
|
||||
}
|
||||
Ok(ratio)
|
||||
}
|
||||
|
||||
@@ -456,8 +456,8 @@ pub fn to_support_map<AccountId: IdentifierT>(
|
||||
let mut supports = <BTreeMap<AccountId, Support<AccountId>>>::new();
|
||||
|
||||
// build support struct.
|
||||
for StakedAssignment { who, distribution } in assignments.into_iter() {
|
||||
for (c, weight_extended) in distribution.into_iter() {
|
||||
for StakedAssignment { who, distribution } in assignments.iter() {
|
||||
for (c, weight_extended) in distribution.iter() {
|
||||
let mut support = supports.entry(c.clone()).or_default();
|
||||
support.total = support.total.saturating_add(*weight_extended);
|
||||
support.voters.push((who.clone(), *weight_extended));
|
||||
|
||||
@@ -97,8 +97,7 @@ pub fn seq_phragmen<AccountId: IdentifierT, P: PerThing128>(
|
||||
voters.into_iter().filter_map(|v| v.into_assignment()).collect::<Vec<_>>();
|
||||
let _ = assignments
|
||||
.iter_mut()
|
||||
.map(|a| a.try_normalize().map_err(|e| crate::Error::ArithmeticError(e)))
|
||||
.collect::<Result<(), _>>()?;
|
||||
.try_for_each(|a| a.try_normalize().map_err(crate::Error::ArithmeticError))?;
|
||||
let winners = winners
|
||||
.into_iter()
|
||||
.map(|w_ptr| (w_ptr.borrow().who.clone(), w_ptr.borrow().backed_stake))
|
||||
@@ -200,7 +199,7 @@ pub fn seq_phragmen_core<AccountId: IdentifierT>(
|
||||
// edge of all candidates that eventually have a non-zero weight must be elected.
|
||||
debug_assert!(voter.edges.iter().all(|e| e.candidate.borrow().elected));
|
||||
// inc budget to sum the budget.
|
||||
voter.try_normalize_elected().map_err(|e| crate::Error::ArithmeticError(e))?;
|
||||
voter.try_normalize_elected().map_err(crate::Error::ArithmeticError)?;
|
||||
}
|
||||
|
||||
Ok((candidates, voters))
|
||||
|
||||
@@ -70,9 +70,8 @@ pub fn phragmms<AccountId: IdentifierT, P: PerThing128>(
|
||||
voters.into_iter().filter_map(|v| v.into_assignment()).collect::<Vec<_>>();
|
||||
let _ = assignments
|
||||
.iter_mut()
|
||||
.map(|a| a.try_normalize())
|
||||
.collect::<Result<(), _>>()
|
||||
.map_err(|e| crate::Error::ArithmeticError(e))?;
|
||||
.try_for_each(|a| a.try_normalize())
|
||||
.map_err(crate::Error::ArithmeticError)?;
|
||||
let winners = winners
|
||||
.into_iter()
|
||||
.map(|w_ptr| (w_ptr.borrow().who.clone(), w_ptr.borrow().backed_stake))
|
||||
@@ -157,16 +156,14 @@ pub(crate) fn calculate_max_score<AccountId: IdentifierT, P: PerThing>(
|
||||
// `RationalInfinite` as the score type does not introduce significant overhead. Then we
|
||||
// can switch the score type to `RationalInfinite` and ensure compatibility with any
|
||||
// crazy token scale.
|
||||
let score_n = candidate
|
||||
.approval_stake
|
||||
.checked_mul(one)
|
||||
.unwrap_or_else(|| Bounded::max_value());
|
||||
let score_n =
|
||||
candidate.approval_stake.checked_mul(one).unwrap_or_else(Bounded::max_value);
|
||||
candidate.score = Rational128::from(score_n, score_d);
|
||||
|
||||
// check if we have a new winner.
|
||||
if !candidate.elected && candidate.score > best_score {
|
||||
best_score = candidate.score;
|
||||
best_candidate = Some(Rc::clone(&c_ptr));
|
||||
best_candidate = Some(Rc::clone(c_ptr));
|
||||
}
|
||||
} else {
|
||||
candidate.score = Rational128::zero();
|
||||
|
||||
@@ -212,7 +212,7 @@ fn validate_pjr_challenge_core<AccountId: IdentifierT>(
|
||||
None => return false,
|
||||
Some(candidate) => candidate.clone(),
|
||||
};
|
||||
pre_score(candidate, &voters, threshold) >= threshold
|
||||
pre_score(candidate, voters, threshold) >= threshold
|
||||
}
|
||||
|
||||
/// Convert the data types that the user runtime has into ones that can be used by this module.
|
||||
@@ -351,7 +351,7 @@ fn pre_score<AccountId: IdentifierT>(
|
||||
debug_assert!(!unelected.borrow().elected);
|
||||
voters
|
||||
.iter()
|
||||
.filter(|ref v| v.votes_for(&unelected.borrow().who))
|
||||
.filter(|v| v.votes_for(&unelected.borrow().who))
|
||||
.fold(Zero::zero(), |acc: ExtendedBalance, voter| acc.saturating_add(slack(voter, t)))
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ fn merge<A: IdentifierT>(voter_root_path: Vec<NodeRef<A>>, target_root_path: Vec
|
||||
shorter_path
|
||||
.iter()
|
||||
.zip(shorter_path.iter().skip(1))
|
||||
.for_each(|(voter, next)| Node::set_parent_of(&next, &voter));
|
||||
.for_each(|(voter, next)| Node::set_parent_of(next, voter));
|
||||
Node::set_parent_of(&shorter_path[0], &longer_path[0]);
|
||||
}
|
||||
|
||||
@@ -524,12 +524,10 @@ fn reduce_all<A: IdentifierT>(assignments: &mut Vec<StakedAssignment<A>>) -> u32
|
||||
} else {
|
||||
ass.distribution[idx].1.saturating_sub(min_value)
|
||||
}
|
||||
} else if start_operation_add {
|
||||
ass.distribution[idx].1.saturating_sub(min_value)
|
||||
} else {
|
||||
if start_operation_add {
|
||||
ass.distribution[idx].1.saturating_sub(min_value)
|
||||
} else {
|
||||
ass.distribution[idx].1.saturating_add(min_value)
|
||||
}
|
||||
ass.distribution[idx].1.saturating_add(min_value)
|
||||
};
|
||||
|
||||
if next_value.is_zero() {
|
||||
@@ -569,12 +567,10 @@ fn reduce_all<A: IdentifierT>(assignments: &mut Vec<StakedAssignment<A>>) -> u32
|
||||
} else {
|
||||
ass.distribution[idx].1.saturating_add(min_value)
|
||||
}
|
||||
} else if start_operation_add {
|
||||
ass.distribution[idx].1.saturating_add(min_value)
|
||||
} else {
|
||||
if start_operation_add {
|
||||
ass.distribution[idx].1.saturating_add(min_value)
|
||||
} else {
|
||||
ass.distribution[idx].1.saturating_sub(min_value)
|
||||
}
|
||||
ass.distribution[idx].1.saturating_sub(min_value)
|
||||
};
|
||||
|
||||
if next_value.is_zero() {
|
||||
|
||||
Reference in New Issue
Block a user