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:
Keith Yeung
2022-09-08 12:22:41 +08:00
committed by GitHub
parent 09ec484139
commit 6ce4d45175
23 changed files with 156 additions and 82 deletions
@@ -49,7 +49,8 @@ where
) -> Result<(), TransactionValidityError> {
let max = T::BlockWeights::get().get(info.class).max_extrinsic;
match max {
Some(max) if info.weight > max => Err(InvalidTransaction::ExhaustsResources.into()),
Some(max) if info.weight.any_gt(max) =>
Err(InvalidTransaction::ExhaustsResources.into()),
_ => Ok(()),
}
}
@@ -144,7 +145,8 @@ where
// Check if we don't exceed per-class allowance
match limit_per_class.max_total {
Some(max) if per_class > max => return Err(InvalidTransaction::ExhaustsResources.into()),
Some(max) if per_class.any_gt(max) =>
return Err(InvalidTransaction::ExhaustsResources.into()),
// There is no `max_total` limit (`None`),
// or we are below the limit.
_ => {},
@@ -152,10 +154,10 @@ where
// In cases total block weight is exceeded, we need to fall back
// to `reserved` pool if there is any.
if all_weight.total() > maximum_weight.max_block {
if all_weight.total().any_gt(maximum_weight.max_block) {
match limit_per_class.reserved {
// We are over the limit in reserved pool.
Some(reserved) if per_class > reserved =>
Some(reserved) if per_class.any_gt(reserved) =>
return Err(InvalidTransaction::ExhaustsResources.into()),
// There is either no limit in reserved pool (`None`),
// or we are below the limit.
@@ -238,7 +240,7 @@ where
}
let unspent = post_info.calc_unspent(info);
if unspent > Weight::zero() {
if unspent.any_gt(Weight::zero()) {
crate::BlockWeight::<T>::mutate(|current_weight| {
current_weight.sub(unspent, info.class);
})
@@ -310,7 +312,7 @@ mod tests {
check(|max, len| {
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(max, len));
assert_eq!(System::block_weight().total(), Weight::MAX);
assert!(System::block_weight().total() > block_weight_limit());
assert!(System::block_weight().total().all_gt(block_weight_limit()));
});
check(|max, len| {
assert_ok!(CheckWeight::<Test>::do_validate(max, len));
@@ -367,7 +369,7 @@ mod tests {
new_test_ext().execute_with(|| {
System::register_extra_weight_unchecked(Weight::MAX, DispatchClass::Normal);
assert_eq!(System::block_weight().total(), Weight::MAX);
assert!(System::block_weight().total() > block_weight_limit());
assert!(System::block_weight().total().all_gt(block_weight_limit()));
});
}