Add storage size component to weights (#12277)

* Add storage size component to weights

* Rename storage_size to proof_size

* Update primitives/weights/src/weight_v2.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fixes

* cargo fmt

* Implement custom Decode and CompactAs

* Add missing import

* Fixes

* Remove CompactAs implementation

* Properly migrate from 1D weight

* Remove #[pallet::compact] from Weight parameters

* More #[pallet::compact] removals

* Add unit tests

* Set appropriate default block proof size

* cargo fmt

* Remove nonsensical weight constant

* Test only for the reference time weight in frame_system::limits

* Only check for reference time weight on idle

* Use destructuring syntax

* Update test expectations

* Fixes

* Fixes

* Fixes

* Correctly migrate from 1D weights

* cargo fmt

* Migrate using extra extrinsics instead of custom Decode

* Fixes

* Silence dispatch call warnings that were previously allowed

* Fix gas_left test

* Use OldWeight instead of u64

* Fixes

* Only check for reference time weight in election provider

* Fix test expectations

* Fix test expectations

* Use only reference time weight in grandpa test

* Use only reference time weight in examples test

* Use only reference time weight in examples test

* Fix test expectations

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-28 18:21:53 +08:00
committed by GitHub
parent 9d41de645f
commit 0327258566
20 changed files with 531 additions and 128 deletions
+10 -11
View File
@@ -207,7 +207,7 @@ pub struct BlockWeights {
impl Default for BlockWeights {
fn default() -> Self {
Self::with_sensible_defaults(1u32 * constants::WEIGHT_PER_SECOND, DEFAULT_NORMAL_RATIO)
Self::with_sensible_defaults(1u64 * constants::WEIGHT_PER_SECOND, DEFAULT_NORMAL_RATIO)
}
}
@@ -224,6 +224,7 @@ impl BlockWeights {
}
let mut error = ValidationErrors::default();
// TODO: account for proof size weight in the assertions below
for class in DispatchClass::all() {
let weights = self.per_class.get(*class);
let max_for_class = or_max(weights.max_total);
@@ -232,18 +233,16 @@ impl BlockWeights {
// Make sure that if total is set it's greater than base_block &&
// base_for_class
error_assert!(
(max_for_class.all_gt(self.base_block) && max_for_class.all_gt(base_for_class))
|| max_for_class == Weight::zero(),
(max_for_class.ref_time() > self.base_block.ref_time() && max_for_class.ref_time() > base_for_class.ref_time())
|| max_for_class.ref_time() == 0,
&mut error,
"[{:?}] {:?} (total) has to be greater than {:?} (base block) & {:?} (base extrinsic)",
class, max_for_class, self.base_block, base_for_class,
);
// Max extrinsic can't be greater than max_for_class.
error_assert!(
weights
.max_extrinsic
.unwrap_or(Weight::zero())
.all_lte(max_for_class.saturating_sub(base_for_class)),
weights.max_extrinsic.unwrap_or(Weight::zero()).ref_time() <=
max_for_class.saturating_sub(base_for_class).ref_time(),
&mut error,
"[{:?}] {:?} (max_extrinsic) can't be greater than {:?} (max for class)",
class,
@@ -252,14 +251,14 @@ impl BlockWeights {
);
// Max extrinsic should not be 0
error_assert!(
weights.max_extrinsic.unwrap_or_else(Weight::max_value).all_gt(Weight::zero()),
weights.max_extrinsic.unwrap_or_else(Weight::max_value).ref_time() > 0,
&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.all_gt(base_for_class) || reserved == Weight::zero(),
reserved.ref_time() > base_for_class.ref_time() || reserved.ref_time() == 0,
&mut error,
"[{:?}] {:?} (reserved) has to be greater than {:?} (base extrinsic) if set",
class,
@@ -268,7 +267,7 @@ impl BlockWeights {
);
// Make sure max block is greater than max_total if it's set.
error_assert!(
self.max_block.all_gte(weights.max_total.unwrap_or(Weight::zero())),
self.max_block.ref_time() >= weights.max_total.unwrap_or(Weight::zero()).ref_time(),
&mut error,
"[{:?}] {:?} (max block) has to be greater than {:?} (max for class)",
class,
@@ -277,7 +276,7 @@ impl BlockWeights {
);
// Make sure we can fit at least one extrinsic.
error_assert!(
self.max_block.all_gt(base_for_class + self.base_block),
self.max_block.ref_time() > (base_for_class + self.base_block).ref_time(),
&mut error,
"[{:?}] {:?} (max block) must fit at least one extrinsic {:?} (base weight)",
class,