Properly set the max proof size weight on defaults and tests (#12383)

* Properly set the max proof size weight on defaults and tests

* cargo fmt

* Set proper max proof size for contracts pallet tests

* Properly set max proof size for node

* Properly set max proof size for frame system mock

* Update test expectations

* Update test expectations

* Properly set max proof size for balances mock

* Update test expectations

* Update test expectations

* Properly set max proof size for democracy mock

* Properly set max proof size for scheduler mock

* Properly set max proof size for fast unstake mock

* Properly set max proof size for tx payment mock

* Properly set max proof size for elections phragmen mock

* Properly set max proof size for node template
This commit is contained in:
Keith Yeung
2022-09-29 23:48:10 +08:00
committed by GitHub
parent 7bea0c0175
commit a4fb1d7096
22 changed files with 323 additions and 107 deletions
@@ -310,7 +310,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().all_gt(block_weight_limit()));
assert!(System::block_weight().total().ref_time() > block_weight_limit().ref_time());
});
check(|max, len| {
assert_ok!(CheckWeight::<Test>::do_validate(max, len));
@@ -367,7 +367,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().all_gt(block_weight_limit()));
assert!(System::block_weight().total().ref_time() > block_weight_limit().ref_time());
});
}
@@ -392,8 +392,8 @@ mod tests {
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
assert_eq!(System::block_weight().total(), Weight::from_ref_time(768));
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&rest_operational, len));
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024));
assert_eq!(System::block_weight().total(), block_weight_limit());
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024).set_proof_size(u64::MAX));
assert_eq!(System::block_weight().total(), block_weight_limit().set_proof_size(0));
// Checking single extrinsic should not take current block weight into account.
assert_eq!(CheckWeight::<Test>::check_extrinsic_weight(&rest_operational), Ok(()));
});
@@ -417,8 +417,8 @@ mod tests {
// Extra 20 here from block execution + base extrinsic weight
assert_eq!(System::block_weight().total(), Weight::from_ref_time(266));
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024));
assert_eq!(System::block_weight().total(), block_weight_limit());
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024).set_proof_size(u64::MAX));
assert_eq!(System::block_weight().total(), block_weight_limit().set_proof_size(0));
});
}
@@ -669,7 +669,7 @@ mod tests {
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
assert_eq!(System::block_weight().total(), Weight::from_ref_time(768));
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&mandatory, len));
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024));
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024).set_proof_size(u64::MAX));
assert_eq!(System::block_weight().total(), Weight::from_ref_time(1024 + 768));
assert_eq!(CheckWeight::<Test>::check_extrinsic_weight(&mandatory), Ok(()));
});
@@ -682,11 +682,11 @@ mod tests {
.base_block(Weight::zero())
.for_class(DispatchClass::non_mandatory(), |w| {
w.base_extrinsic = Weight::zero();
w.max_total = Some(Weight::from_ref_time(20));
w.max_total = Some(Weight::from_ref_time(20).set_proof_size(u64::MAX));
})
.for_class(DispatchClass::Mandatory, |w| {
w.base_extrinsic = Weight::zero();
w.reserved = Some(Weight::from_ref_time(5));
w.reserved = Some(Weight::from_ref_time(5).set_proof_size(u64::MAX));
w.max_total = None;
})
.build_or_panic();
@@ -695,7 +695,7 @@ mod tests {
DispatchClass::Operational => Weight::from_ref_time(10),
DispatchClass::Mandatory => Weight::zero(),
});
assert_eq!(maximum_weight.max_block, all_weight.total());
assert_eq!(maximum_weight.max_block, all_weight.total().set_proof_size(u64::MAX));
// fits into reserved
let mandatory1 = DispatchInfo {
+14 -10
View File
@@ -207,7 +207,10 @@ pub struct BlockWeights {
impl Default for BlockWeights {
fn default() -> Self {
Self::with_sensible_defaults(1u64 * constants::WEIGHT_PER_SECOND, DEFAULT_NORMAL_RATIO)
Self::with_sensible_defaults(
Weight::from_components(constants::WEIGHT_PER_SECOND.ref_time(), u64::MAX),
DEFAULT_NORMAL_RATIO,
)
}
}
@@ -224,7 +227,6 @@ 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);
@@ -233,16 +235,18 @@ impl BlockWeights {
// Make sure that if total is set it's greater than base_block &&
// base_for_class
error_assert!(
(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,
(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)",
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()).ref_time() <=
max_for_class.saturating_sub(base_for_class).ref_time(),
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,
@@ -251,14 +255,14 @@ impl BlockWeights {
);
// Max extrinsic should not be 0
error_assert!(
weights.max_extrinsic.unwrap_or_else(Weight::max_value).ref_time() > 0,
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.ref_time() > base_for_class.ref_time() || reserved.ref_time() == 0,
reserved.all_gt(base_for_class) || reserved == Weight::zero(),
&mut error,
"[{:?}] {:?} (reserved) has to be greater than {:?} (base extrinsic) if set",
class,
@@ -267,7 +271,7 @@ impl BlockWeights {
);
// Make sure max block is greater than max_total if it's set.
error_assert!(
self.max_block.ref_time() >= weights.max_total.unwrap_or(Weight::zero()).ref_time(),
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,
@@ -276,7 +280,7 @@ impl BlockWeights {
);
// Make sure we can fit at least one extrinsic.
error_assert!(
self.max_block.ref_time() > (base_for_class + self.base_block).ref_time(),
self.max_block.all_gt(base_for_class + self.base_block),
&mut error,
"[{:?}] {:?} (max block) must fit at least one extrinsic {:?} (base weight)",
class,
+1 -1
View File
@@ -41,7 +41,7 @@ frame_support::construct_runtime!(
);
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
const MAX_BLOCK_WEIGHT: Weight = Weight::from_ref_time(1024);
const MAX_BLOCK_WEIGHT: Weight = Weight::from_ref_time(1024).set_proof_size(u64::MAX);
parameter_types! {
pub Version: RuntimeVersion = RuntimeVersion {