mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 14:27:57 +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:
@@ -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()));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ impl BlockWeights {
|
||||
// Make sure that if total is set it's greater than base_block &&
|
||||
// base_for_class
|
||||
error_assert!(
|
||||
(max_for_class > self.base_block && max_for_class > base_for_class)
|
||||
(max_for_class.all_gt(self.base_block) && max_for_class.all_gt(base_for_class))
|
||||
|| max_for_class == Weight::zero(),
|
||||
&mut error,
|
||||
"[{:?}] {:?} (total) has to be greater than {:?} (base block) & {:?} (base extrinsic)",
|
||||
@@ -237,8 +237,10 @@ impl BlockWeights {
|
||||
);
|
||||
// Max extrinsic can't be greater than max_for_class.
|
||||
error_assert!(
|
||||
weights.max_extrinsic.unwrap_or(Weight::zero()) <=
|
||||
max_for_class.saturating_sub(base_for_class),
|
||||
weights
|
||||
.max_extrinsic
|
||||
.unwrap_or(Weight::zero())
|
||||
.all_lte(max_for_class.saturating_sub(base_for_class)),
|
||||
&mut error,
|
||||
"[{:?}] {:?} (max_extrinsic) can't be greater than {:?} (max for class)",
|
||||
class,
|
||||
@@ -247,14 +249,14 @@ impl BlockWeights {
|
||||
);
|
||||
// Max extrinsic should not be 0
|
||||
error_assert!(
|
||||
weights.max_extrinsic.unwrap_or_else(Weight::max_value) > Weight::zero(),
|
||||
weights.max_extrinsic.unwrap_or_else(Weight::max_value).all_gt(Weight::zero()),
|
||||
&mut error,
|
||||
"[{:?}] {:?} (max_extrinsic) must not be 0. Check base cost and average initialization cost.",
|
||||
class, weights.max_extrinsic,
|
||||
);
|
||||
// Make sure that if reserved is set it's greater than base_for_class.
|
||||
error_assert!(
|
||||
reserved > base_for_class || reserved == Weight::zero(),
|
||||
reserved.all_gt(base_for_class) || reserved == Weight::zero(),
|
||||
&mut error,
|
||||
"[{:?}] {:?} (reserved) has to be greater than {:?} (base extrinsic) if set",
|
||||
class,
|
||||
@@ -263,7 +265,7 @@ impl BlockWeights {
|
||||
);
|
||||
// Make sure max block is greater than max_total if it's set.
|
||||
error_assert!(
|
||||
self.max_block >= weights.max_total.unwrap_or(Weight::zero()),
|
||||
self.max_block.all_gte(weights.max_total.unwrap_or(Weight::zero())),
|
||||
&mut error,
|
||||
"[{:?}] {:?} (max block) has to be greater than {:?} (max for class)",
|
||||
class,
|
||||
@@ -272,7 +274,7 @@ impl BlockWeights {
|
||||
);
|
||||
// Make sure we can fit at least one extrinsic.
|
||||
error_assert!(
|
||||
self.max_block > base_for_class + self.base_block,
|
||||
self.max_block.all_gt(base_for_class + self.base_block),
|
||||
&mut error,
|
||||
"[{:?}] {:?} (max block) must fit at least one extrinsic {:?} (base weight)",
|
||||
class,
|
||||
@@ -400,7 +402,7 @@ impl BlockWeightsBuilder {
|
||||
// compute max block size.
|
||||
for class in DispatchClass::all() {
|
||||
weights.max_block = match weights.per_class.get(*class).max_total {
|
||||
Some(max) if max > weights.max_block => max,
|
||||
Some(max) => max.max(weights.max_block),
|
||||
_ => weights.max_block,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user