mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 07:01:03 +00:00
Remove Ord impl for Weights V2 and add comparison fns (#12183)
* Remove Ord impl for Weights V2 and add comparison fns * Remove TODO * Update frame/multisig/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/election-provider-multi-phase/src/unsigned.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Remove unused import * cargo fmt * Fix tests * Fix more tests * cargo fmt * Fix more tests * Update frame/contracts/src/wasm/mod.rs Co-authored-by: Alexander Theißen <alex.theissen@me.com> * Update weight benchmarking templates Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
@@ -985,7 +985,7 @@ pub mod pallet {
|
||||
let size = Self::snapshot_metadata().ok_or(Error::<T>::MissingSnapshotMetadata)?;
|
||||
|
||||
ensure!(
|
||||
Self::solution_weight_of(&raw_solution, size) < T::SignedMaxWeight::get(),
|
||||
Self::solution_weight_of(&raw_solution, size).all_lt(T::SignedMaxWeight::get()),
|
||||
Error::<T>::SignedTooMuchWeight,
|
||||
);
|
||||
|
||||
@@ -2299,8 +2299,8 @@ mod tests {
|
||||
};
|
||||
|
||||
let mut active = 1;
|
||||
while weight_with(active) <=
|
||||
<Runtime as frame_system::Config>::BlockWeights::get().max_block ||
|
||||
while weight_with(active)
|
||||
.all_lte(<Runtime as frame_system::Config>::BlockWeights::get().max_block) ||
|
||||
active == all_voters
|
||||
{
|
||||
active += 1;
|
||||
|
||||
@@ -34,7 +34,7 @@ use sp_runtime::{
|
||||
offchain::storage::{MutateStorageError, StorageValueRef},
|
||||
DispatchError, SaturatedConversion,
|
||||
};
|
||||
use sp_std::{cmp::Ordering, prelude::*};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
/// Storage key used to store the last block number at which offchain worker ran.
|
||||
pub(crate) const OFFCHAIN_LAST_BLOCK: &[u8] = b"parity/multi-phase-unsigned-election";
|
||||
@@ -638,16 +638,17 @@ impl<T: MinerConfig> Miner<T> {
|
||||
};
|
||||
|
||||
let next_voters = |current_weight: Weight, voters: u32, step: u32| -> Result<u32, ()> {
|
||||
match current_weight.cmp(&max_weight) {
|
||||
Ordering::Less => {
|
||||
let next_voters = voters.checked_add(step);
|
||||
match next_voters {
|
||||
Some(voters) if voters < max_voters => Ok(voters),
|
||||
_ => Err(()),
|
||||
}
|
||||
},
|
||||
Ordering::Greater => voters.checked_sub(step).ok_or(()),
|
||||
Ordering::Equal => Ok(voters),
|
||||
if current_weight.all_lt(max_weight) {
|
||||
let next_voters = voters.checked_add(step);
|
||||
match next_voters {
|
||||
Some(voters) if voters < max_voters => Ok(voters),
|
||||
_ => Err(()),
|
||||
}
|
||||
} else if current_weight.any_gt(max_weight) {
|
||||
voters.checked_sub(step).ok_or(())
|
||||
} else {
|
||||
// If any of the constituent weights is equal to the max weight, we're at max
|
||||
Ok(voters)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -672,16 +673,16 @@ impl<T: MinerConfig> Miner<T> {
|
||||
|
||||
// Time to finish. We might have reduced less than expected due to rounding error. Increase
|
||||
// one last time if we have any room left, the reduce until we are sure we are below limit.
|
||||
while voters < max_voters && weight_with(voters + 1) < max_weight {
|
||||
while voters < max_voters && weight_with(voters + 1).all_lt(max_weight) {
|
||||
voters += 1;
|
||||
}
|
||||
while voters.checked_sub(1).is_some() && weight_with(voters) > max_weight {
|
||||
while voters.checked_sub(1).is_some() && weight_with(voters).any_gt(max_weight) {
|
||||
voters -= 1;
|
||||
}
|
||||
|
||||
let final_decision = voters.min(size.voters);
|
||||
debug_assert!(
|
||||
weight_with(final_decision) <= max_weight,
|
||||
weight_with(final_decision).all_lte(max_weight),
|
||||
"weight_with({}) <= {}",
|
||||
final_decision,
|
||||
max_weight,
|
||||
|
||||
Reference in New Issue
Block a user