Weight v1.5: Opaque Struct (#12138)

* initial idea

* update frame_support

* update a bunch more

* add ord

* adjust RuntimeDbWeight

* frame_system builds

* re-export

* frame_support tests pass

* frame_executive compile

* frame_executive builds

* frame_system tests passing

* pallet-utility tests pass

* fix a bunch of pallets

* more

* phragmen

* state-trie-migration

* scheduler and referenda

* pallet-election-provider-multi-phase

* aura

* staking

* more

* babe

* balances

* bunch more

* sudo

* transaction-payment

* asset-tx-payment

* last pallets

* fix alliance merge

* fix node template runtime

* fix pallet-contracts cc @athei

* fix node runtime

* fix compile on runtime-benchmarks feature

* comment

* fix frame-support-test

* fix more tests

* weight regex

* frame system works

* fix a bunch

* more

* more

* more

* more

* more

* more fixes

* update templates

* fix contracts benchmarks

* Update lib.rs

* Update lib.rs

* fix ui

* make scalar saturating mul const

* more const functions

* scalar div

* refactor using constant functions

* move impl

* fix overhead template

* use compactas

* Update lib.rs
This commit is contained in:
Shawn Tabrizi
2022-08-31 12:26:13 +01:00
committed by GitHub
parent 299f4ba541
commit 30951822ba
187 changed files with 5932 additions and 4930 deletions
@@ -101,7 +101,7 @@ impl<T: Config + Send + Sync> SignedExtension for CheckMortality<T> {
mod tests {
use super::*;
use crate::mock::{new_test_ext, System, Test, CALL};
use frame_support::weights::{DispatchClass, DispatchInfo, Pays};
use frame_support::weights::{DispatchClass, DispatchInfo, Pays, Weight};
use sp_core::H256;
#[test]
@@ -126,8 +126,11 @@ mod tests {
#[test]
fn signed_ext_check_era_should_change_longevity() {
new_test_ext().execute_with(|| {
let normal =
DispatchInfo { weight: 100, class: DispatchClass::Normal, pays_fee: Pays::Yes };
let normal = DispatchInfo {
weight: Weight::from_ref_time(100),
class: DispatchClass::Normal,
pays_fee: Pays::Yes,
};
let len = 0_usize;
let ext = (
crate::CheckWeight::<Test>::new(),
@@ -19,7 +19,7 @@ use crate::{limits::BlockWeights, Config, Pallet};
use codec::{Decode, Encode};
use frame_support::{
traits::Get,
weights::{DispatchClass, DispatchInfo, PostDispatchInfo},
weights::{DispatchClass, DispatchInfo, PostDispatchInfo, Weight},
};
use scale_info::TypeInfo;
use sp_runtime::{
@@ -238,7 +238,7 @@ where
}
let unspent = post_info.calc_unspent(info);
if unspent > 0 {
if unspent > Weight::zero() {
crate::BlockWeight::<T>::mutate(|current_weight| {
current_weight.sub(unspent, info.class);
})
@@ -297,7 +297,7 @@ mod tests {
fn check(call: impl FnOnce(&DispatchInfo, usize)) {
new_test_ext().execute_with(|| {
let max = DispatchInfo {
weight: Weight::max_value(),
weight: Weight::MAX,
class: DispatchClass::Mandatory,
..Default::default()
};
@@ -309,7 +309,7 @@ mod tests {
check(|max, len| {
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(max, len));
assert_eq!(System::block_weight().total(), Weight::max_value());
assert_eq!(System::block_weight().total(), Weight::MAX);
assert!(System::block_weight().total() > block_weight_limit());
});
check(|max, len| {
@@ -321,7 +321,8 @@ mod tests {
fn normal_extrinsic_limited_by_maximum_extrinsic_weight() {
new_test_ext().execute_with(|| {
let max = DispatchInfo {
weight: block_weights().get(DispatchClass::Normal).max_extrinsic.unwrap() + 1,
weight: block_weights().get(DispatchClass::Normal).max_extrinsic.unwrap() +
Weight::one(),
class: DispatchClass::Normal,
..Default::default()
};
@@ -347,7 +348,7 @@ mod tests {
let okay =
DispatchInfo { weight, class: DispatchClass::Operational, ..Default::default() };
let max = DispatchInfo {
weight: weight + 1,
weight: weight + Weight::one(),
class: DispatchClass::Operational,
..Default::default()
};
@@ -364,8 +365,8 @@ mod tests {
#[test]
fn register_extra_weight_unchecked_doesnt_care_about_limits() {
new_test_ext().execute_with(|| {
System::register_extra_weight_unchecked(Weight::max_value(), DispatchClass::Normal);
assert_eq!(System::block_weight().total(), Weight::max_value());
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());
});
}
@@ -378,9 +379,10 @@ mod tests {
// 10 is taken for block execution weight
// So normal extrinsic can be 758 weight (-5 for base extrinsic weight)
// And Operational can be 256 to produce a full block (-5 for base)
let max_normal = DispatchInfo { weight: 753, ..Default::default() };
let max_normal =
DispatchInfo { weight: Weight::from_ref_time(753), ..Default::default() };
let rest_operational = DispatchInfo {
weight: 251,
weight: Weight::from_ref_time(251),
class: DispatchClass::Operational,
..Default::default()
};
@@ -388,9 +390,9 @@ mod tests {
let len = 0_usize;
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
assert_eq!(System::block_weight().total(), 768);
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(), 1024);
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024));
assert_eq!(System::block_weight().total(), block_weight_limit());
// Checking single extrinsic should not take current block weight into account.
assert_eq!(CheckWeight::<Test>::check_extrinsic_weight(&rest_operational), Ok(()));
@@ -401,9 +403,10 @@ mod tests {
fn dispatch_order_does_not_effect_weight_logic() {
new_test_ext().execute_with(|| {
// We switch the order of `full_block_with_normal_and_operational`
let max_normal = DispatchInfo { weight: 753, ..Default::default() };
let max_normal =
DispatchInfo { weight: Weight::from_ref_time(753), ..Default::default() };
let rest_operational = DispatchInfo {
weight: 251,
weight: Weight::from_ref_time(251),
class: DispatchClass::Operational,
..Default::default()
};
@@ -412,9 +415,9 @@ mod tests {
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&rest_operational, len));
// Extra 15 here from block execution + base extrinsic weight
assert_eq!(System::block_weight().total(), 266);
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(), 1024);
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024));
assert_eq!(System::block_weight().total(), block_weight_limit());
});
}
@@ -423,11 +426,14 @@ mod tests {
fn operational_works_on_full_block() {
new_test_ext().execute_with(|| {
// An on_initialize takes up the whole block! (Every time!)
System::register_extra_weight_unchecked(Weight::max_value(), DispatchClass::Mandatory);
let dispatch_normal =
DispatchInfo { weight: 251, class: DispatchClass::Normal, ..Default::default() };
System::register_extra_weight_unchecked(Weight::MAX, DispatchClass::Mandatory);
let dispatch_normal = DispatchInfo {
weight: Weight::from_ref_time(251),
class: DispatchClass::Normal,
..Default::default()
};
let dispatch_operational = DispatchInfo {
weight: 251,
weight: Weight::from_ref_time(251),
class: DispatchClass::Operational,
..Default::default()
};
@@ -453,9 +459,9 @@ mod tests {
#[test]
fn signed_ext_check_weight_works_operational_tx() {
new_test_ext().execute_with(|| {
let normal = DispatchInfo { weight: 100, ..Default::default() };
let normal = DispatchInfo { weight: Weight::from_ref_time(100), ..Default::default() };
let op = DispatchInfo {
weight: 100,
weight: Weight::from_ref_time(100),
class: DispatchClass::Operational,
pays_fee: Pays::Yes,
};
@@ -489,7 +495,7 @@ mod tests {
fn signed_ext_check_weight_block_size_works() {
new_test_ext().execute_with(|| {
let normal = DispatchInfo::default();
let normal_limit = normal_weight_limit() as usize;
let normal_limit = normal_weight_limit().ref_time() as usize;
let reset_check_weight = |tx, s, f| {
AllExtrinsicsLen::<Test>::put(0);
let r = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, tx, s);
@@ -505,8 +511,11 @@ mod tests {
reset_check_weight(&normal, normal_limit + 1, true);
// Operational ones don't have this limit.
let op =
DispatchInfo { weight: 0, class: DispatchClass::Operational, pays_fee: Pays::Yes };
let op = DispatchInfo {
weight: Weight::zero(),
class: DispatchClass::Operational,
pays_fee: Pays::Yes,
};
reset_check_weight(&op, normal_limit, false);
reset_check_weight(&op, normal_limit + 100, false);
reset_check_weight(&op, 1024, false);
@@ -518,12 +527,14 @@ mod tests {
fn signed_ext_check_weight_works_normal_tx() {
new_test_ext().execute_with(|| {
let normal_limit = normal_weight_limit();
let small = DispatchInfo { weight: 100, ..Default::default() };
let small = DispatchInfo { weight: Weight::from_ref_time(100), ..Default::default() };
let base_extrinsic = block_weights().get(DispatchClass::Normal).base_extrinsic;
let medium =
DispatchInfo { weight: normal_limit - base_extrinsic, ..Default::default() };
let big =
DispatchInfo { weight: normal_limit - base_extrinsic + 1, ..Default::default() };
let big = DispatchInfo {
weight: normal_limit - base_extrinsic + Weight::one(),
..Default::default()
};
let len = 0_usize;
let reset_check_weight = |i, f, s| {
@@ -538,9 +549,9 @@ mod tests {
}
};
reset_check_weight(&small, false, 0);
reset_check_weight(&medium, false, 0);
reset_check_weight(&big, true, 1);
reset_check_weight(&small, false, Weight::zero());
reset_check_weight(&medium, false, Weight::zero());
reset_check_weight(&big, true, Weight::one());
})
}
@@ -548,49 +559,25 @@ mod tests {
fn signed_ext_check_weight_refund_works() {
new_test_ext().execute_with(|| {
// This is half of the max block weight
let info = DispatchInfo { weight: 512, ..Default::default() };
let post_info =
PostDispatchInfo { actual_weight: Some(128), pays_fee: Default::default() };
let info = DispatchInfo { weight: Weight::from_ref_time(512), ..Default::default() };
let post_info = PostDispatchInfo {
actual_weight: Some(Weight::from_ref_time(128)),
pays_fee: Default::default(),
};
let len = 0_usize;
let base_extrinsic = block_weights().get(DispatchClass::Normal).base_extrinsic;
// We allow 75% for normal transaction, so we put 25% - extrinsic base weight
BlockWeight::<Test>::mutate(|current_weight| {
current_weight.set(0, DispatchClass::Mandatory);
current_weight.set(256 - base_extrinsic, DispatchClass::Normal);
});
let pre = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &info, len).unwrap();
assert_eq!(BlockWeight::<Test>::get().total(), info.weight + 256);
assert_ok!(CheckWeight::<Test>::post_dispatch(
Some(pre),
&info,
&post_info,
len,
&Ok(())
));
assert_eq!(BlockWeight::<Test>::get().total(), post_info.actual_weight.unwrap() + 256);
})
}
#[test]
fn signed_ext_check_weight_actual_weight_higher_than_max_is_capped() {
new_test_ext().execute_with(|| {
let info = DispatchInfo { weight: 512, ..Default::default() };
let post_info =
PostDispatchInfo { actual_weight: Some(700), pays_fee: Default::default() };
let len = 0_usize;
BlockWeight::<Test>::mutate(|current_weight| {
current_weight.set(0, DispatchClass::Mandatory);
current_weight.set(128, DispatchClass::Normal);
current_weight.set(Weight::zero(), DispatchClass::Mandatory);
current_weight
.set(Weight::from_ref_time(256) - base_extrinsic, DispatchClass::Normal);
});
let pre = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &info, len).unwrap();
assert_eq!(
BlockWeight::<Test>::get().total(),
info.weight + 128 + block_weights().get(DispatchClass::Normal).base_extrinsic,
info.weight + Weight::from_ref_time(256)
);
assert_ok!(CheckWeight::<Test>::post_dispatch(
@@ -602,7 +589,46 @@ mod tests {
));
assert_eq!(
BlockWeight::<Test>::get().total(),
info.weight + 128 + block_weights().get(DispatchClass::Normal).base_extrinsic,
post_info.actual_weight.unwrap() + Weight::from_ref_time(256)
);
})
}
#[test]
fn signed_ext_check_weight_actual_weight_higher_than_max_is_capped() {
new_test_ext().execute_with(|| {
let info = DispatchInfo { weight: Weight::from_ref_time(512), ..Default::default() };
let post_info = PostDispatchInfo {
actual_weight: Some(Weight::from_ref_time(700)),
pays_fee: Default::default(),
};
let len = 0_usize;
BlockWeight::<Test>::mutate(|current_weight| {
current_weight.set(Weight::zero(), DispatchClass::Mandatory);
current_weight.set(Weight::from_ref_time(128), DispatchClass::Normal);
});
let pre = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &info, len).unwrap();
assert_eq!(
BlockWeight::<Test>::get().total(),
info.weight +
Weight::from_ref_time(128) +
block_weights().get(DispatchClass::Normal).base_extrinsic,
);
assert_ok!(CheckWeight::<Test>::post_dispatch(
Some(pre),
&info,
&post_info,
len,
&Ok(())
));
assert_eq!(
BlockWeight::<Test>::get().total(),
info.weight +
Weight::from_ref_time(128) +
block_weights().get(DispatchClass::Normal).base_extrinsic,
);
})
}
@@ -611,7 +637,7 @@ mod tests {
fn zero_weight_extrinsic_still_has_base_weight() {
new_test_ext().execute_with(|| {
let weights = block_weights();
let free = DispatchInfo { weight: 0, ..Default::default() };
let free = DispatchInfo { weight: Weight::zero(), ..Default::default() };
let len = 0_usize;
// Initial weight from `weights.base_block`
@@ -630,9 +656,10 @@ mod tests {
// Max block is 1024
// Max normal is 768 (75%)
// Max mandatory is unlimited
let max_normal = DispatchInfo { weight: 753, ..Default::default() };
let max_normal =
DispatchInfo { weight: Weight::from_ref_time(753), ..Default::default() };
let mandatory = DispatchInfo {
weight: 1019,
weight: Weight::from_ref_time(1019),
class: DispatchClass::Mandatory,
..Default::default()
};
@@ -640,10 +667,10 @@ mod tests {
let len = 0_usize;
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
assert_eq!(System::block_weight().total(), 768);
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(), 1024);
assert_eq!(System::block_weight().total(), 1024 + 768);
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024));
assert_eq!(System::block_weight().total(), Weight::from_ref_time(1024 + 768));
assert_eq!(CheckWeight::<Test>::check_extrinsic_weight(&mandatory), Ok(()));
});
}
@@ -652,30 +679,36 @@ mod tests {
fn no_max_total_should_still_be_limited_by_max_block() {
// given
let maximum_weight = BlockWeights::builder()
.base_block(0)
.base_block(Weight::zero())
.for_class(DispatchClass::non_mandatory(), |w| {
w.base_extrinsic = 0;
w.max_total = Some(20);
w.base_extrinsic = Weight::zero();
w.max_total = Some(Weight::from_ref_time(20));
})
.for_class(DispatchClass::Mandatory, |w| {
w.base_extrinsic = 0;
w.reserved = Some(5);
w.base_extrinsic = Weight::zero();
w.reserved = Some(Weight::from_ref_time(5));
w.max_total = None;
})
.build_or_panic();
let all_weight = crate::ConsumedWeight::new(|class| match class {
DispatchClass::Normal => 10,
DispatchClass::Operational => 10,
DispatchClass::Mandatory => 0,
DispatchClass::Normal => Weight::from_ref_time(10),
DispatchClass::Operational => Weight::from_ref_time(10),
DispatchClass::Mandatory => Weight::zero(),
});
assert_eq!(maximum_weight.max_block, all_weight.total());
// fits into reserved
let mandatory1 =
DispatchInfo { weight: 5, class: DispatchClass::Mandatory, ..Default::default() };
let mandatory1 = DispatchInfo {
weight: Weight::from_ref_time(5),
class: DispatchClass::Mandatory,
..Default::default()
};
// does not fit into reserved and the block is full.
let mandatory2 =
DispatchInfo { weight: 6, class: DispatchClass::Mandatory, ..Default::default() };
let mandatory2 = DispatchInfo {
weight: Weight::from_ref_time(6),
class: DispatchClass::Mandatory,
..Default::default()
};
// when
assert_ok!(calculate_consumed_weight::<<Test as Config>::Call>(
+6 -6
View File
@@ -1327,18 +1327,18 @@ impl<T: Config> Pallet<T> {
).deconstruct(),
Self::block_weight().get(DispatchClass::Normal),
sp_runtime::Percent::from_rational(
*Self::block_weight().get(DispatchClass::Normal),
T::BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap_or(Bounded::max_value())
Self::block_weight().get(DispatchClass::Normal).ref_time(),
T::BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap_or(Bounded::max_value()).ref_time()
).deconstruct(),
Self::block_weight().get(DispatchClass::Operational),
sp_runtime::Percent::from_rational(
*Self::block_weight().get(DispatchClass::Operational),
T::BlockWeights::get().get(DispatchClass::Operational).max_total.unwrap_or(Bounded::max_value())
Self::block_weight().get(DispatchClass::Operational).ref_time(),
T::BlockWeights::get().get(DispatchClass::Operational).max_total.unwrap_or(Bounded::max_value()).ref_time()
).deconstruct(),
Self::block_weight().get(DispatchClass::Mandatory),
sp_runtime::Percent::from_rational(
*Self::block_weight().get(DispatchClass::Mandatory),
T::BlockWeights::get().get(DispatchClass::Mandatory).max_total.unwrap_or(Bounded::max_value())
Self::block_weight().get(DispatchClass::Mandatory).ref_time(),
T::BlockWeights::get().get(DispatchClass::Mandatory).max_total.unwrap_or(Bounded::max_value()).ref_time()
).deconstruct(),
);
ExecutionPhase::<T>::kill();
+12 -10
View File
@@ -27,7 +27,7 @@
use frame_support::weights::{constants, DispatchClass, OneOrMany, PerDispatchClass, Weight};
use scale_info::TypeInfo;
use sp_runtime::{Perbill, RuntimeDebug};
use sp_runtime::{traits::Bounded, Perbill, RuntimeDebug};
/// Block length limit configuration.
#[derive(RuntimeDebug, Clone, codec::Encode, codec::Decode, TypeInfo)]
@@ -230,14 +230,15 @@ impl BlockWeights {
// base_for_class
error_assert!(
(max_for_class > self.base_block && max_for_class > base_for_class)
|| max_for_class == 0,
|| 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(0) <= max_for_class.saturating_sub(base_for_class),
weights.max_extrinsic.unwrap_or(Weight::zero()) <=
max_for_class.saturating_sub(base_for_class),
&mut error,
"[{:?}] {:?} (max_extrinsic) can't be greater than {:?} (max for class)",
class,
@@ -246,14 +247,14 @@ impl BlockWeights {
);
// Max extrinsic should not be 0
error_assert!(
weights.max_extrinsic.unwrap_or_else(Weight::max_value) > 0,
weights.max_extrinsic.unwrap_or_else(Weight::max_value) > 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 == 0,
reserved > base_for_class || reserved == Weight::zero(),
&mut error,
"[{:?}] {:?} (reserved) has to be greater than {:?} (base extrinsic) if set",
class,
@@ -262,7 +263,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(0),
self.max_block >= weights.max_total.unwrap_or(Weight::zero()),
&mut error,
"[{:?}] {:?} (max block) has to be greater than {:?} (max for class)",
class,
@@ -294,9 +295,9 @@ impl BlockWeights {
/// is not suitable for production deployments.
pub fn simple_max(block_weight: Weight) -> Self {
Self::builder()
.base_block(0)
.base_block(Weight::new())
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = 0;
weights.base_extrinsic = Weight::new();
})
.for_class(DispatchClass::non_mandatory(), |weights| {
weights.max_total = block_weight.into();
@@ -333,9 +334,10 @@ impl BlockWeights {
BlockWeightsBuilder {
weights: BlockWeights {
base_block: constants::BlockExecutionWeight::get(),
max_block: 0,
max_block: Weight::zero(),
per_class: PerDispatchClass::new(|class| {
let initial = if class == DispatchClass::Mandatory { None } else { Some(0) };
let initial =
if class == DispatchClass::Mandatory { None } else { Some(Weight::zero()) };
WeightsPerClass {
base_extrinsic: constants::ExtrinsicBaseWeight::get(),
max_extrinsic: None,
+3 -3
View File
@@ -81,7 +81,7 @@ pub fn migrate_from_single_u8_to_triple_ref_count<V: V2ToV3, T: Config>() -> Wei
);
<UpgradedToU32RefCount<T>>::put(true);
<UpgradedToTripleRefCount<T>>::put(true);
Weight::max_value()
Weight::MAX
}
/// Migrate from unique `u32` reference counting to triple `u32` reference counting.
@@ -99,7 +99,7 @@ pub fn migrate_from_single_to_triple_ref_count<V: V2ToV3, T: Config>() -> Weight
translated
);
<UpgradedToTripleRefCount<T>>::put(true);
Weight::max_value()
Weight::MAX
}
/// Migrate from dual `u32` reference counting to triple `u32` reference counting.
@@ -117,5 +117,5 @@ pub fn migrate_from_dual_to_triple_ref_count<V: V2ToV3, T: Config>() -> Weight {
translated
);
<UpgradedToTripleRefCount<T>>::put(true);
Weight::max_value()
Weight::MAX
}
+3 -3
View File
@@ -42,7 +42,7 @@ frame_support::construct_runtime!(
);
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
const MAX_BLOCK_WEIGHT: Weight = 1024;
const MAX_BLOCK_WEIGHT: Weight = Weight::from_ref_time(1024);
parameter_types! {
pub Version: RuntimeVersion = RuntimeVersion {
@@ -60,9 +60,9 @@ parameter_types! {
write: 100,
};
pub RuntimeBlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
.base_block(10)
.base_block(Weight::from_ref_time(10))
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = 5;
weights.base_extrinsic = Weight::from_ref_time(5);
})
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAX_BLOCK_WEIGHT);
+36 -15
View File
@@ -224,7 +224,7 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
System::initialize(&1, &[0u8; 32].into(), &Default::default());
System::note_finished_initialize();
let pre_info = DispatchInfo { weight: 1000, ..Default::default() };
let pre_info = DispatchInfo { weight: Weight::from_ref_time(1000), ..Default::default() };
System::note_applied_extrinsic(&Ok(Some(300).into()), pre_info);
System::note_applied_extrinsic(&Ok(Some(1000).into()), pre_info);
System::note_applied_extrinsic(
@@ -236,7 +236,10 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
System::note_applied_extrinsic(&Ok(Pays::No.into()), pre_info);
System::note_applied_extrinsic(&Ok((Some(2_500_000), Pays::No).into()), pre_info);
System::note_applied_extrinsic(&Ok((Some(500), Pays::No).into()), pre_info);
System::note_applied_extrinsic(&Err(DispatchError::BadOrigin.with_weight(999)), pre_info);
System::note_applied_extrinsic(
&Err(DispatchError::BadOrigin.with_weight(Weight::from_ref_time(999))),
pre_info,
);
System::note_applied_extrinsic(
&Err(DispatchErrorWithPostInfo {
@@ -247,14 +250,20 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
);
System::note_applied_extrinsic(
&Err(DispatchErrorWithPostInfo {
post_info: PostDispatchInfo { actual_weight: Some(800), pays_fee: Pays::Yes },
post_info: PostDispatchInfo {
actual_weight: Some(Weight::from_ref_time(800)),
pays_fee: Pays::Yes,
},
error: DispatchError::BadOrigin,
}),
pre_info,
);
System::note_applied_extrinsic(
&Err(DispatchErrorWithPostInfo {
post_info: PostDispatchInfo { actual_weight: Some(800), pays_fee: Pays::No },
post_info: PostDispatchInfo {
actual_weight: Some(Weight::from_ref_time(800)),
pays_fee: Pays::No,
},
error: DispatchError::BadOrigin,
}),
pre_info,
@@ -266,7 +275,10 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: SysEvent::ExtrinsicSuccess {
dispatch_info: DispatchInfo { weight: 300, ..Default::default() },
dispatch_info: DispatchInfo {
weight: Weight::from_ref_time(300),
..Default::default()
},
}
.into(),
topics: vec![]
@@ -274,7 +286,10 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: SysEvent::ExtrinsicSuccess {
dispatch_info: DispatchInfo { weight: 1000, ..Default::default() },
dispatch_info: DispatchInfo {
weight: Weight::from_ref_time(1000),
..Default::default()
},
}
.into(),
topics: vec![]
@@ -282,7 +297,10 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: SysEvent::ExtrinsicSuccess {
dispatch_info: DispatchInfo { weight: 1000, ..Default::default() },
dispatch_info: DispatchInfo {
weight: Weight::from_ref_time(1000),
..Default::default()
},
}
.into(),
topics: vec![]
@@ -291,7 +309,7 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
phase: Phase::ApplyExtrinsic(3),
event: SysEvent::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: 1000,
weight: Weight::from_ref_time(1000),
pays_fee: Pays::Yes,
..Default::default()
},
@@ -303,7 +321,7 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
phase: Phase::ApplyExtrinsic(4),
event: SysEvent::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: 1000,
weight: Weight::from_ref_time(1000),
pays_fee: Pays::No,
..Default::default()
},
@@ -315,7 +333,7 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
phase: Phase::ApplyExtrinsic(5),
event: SysEvent::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: 1000,
weight: Weight::from_ref_time(1000),
pays_fee: Pays::No,
..Default::default()
},
@@ -327,7 +345,7 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
phase: Phase::ApplyExtrinsic(6),
event: SysEvent::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: 500,
weight: Weight::from_ref_time(500),
pays_fee: Pays::No,
..Default::default()
},
@@ -339,7 +357,10 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
phase: Phase::ApplyExtrinsic(7),
event: SysEvent::ExtrinsicFailed {
dispatch_error: DispatchError::BadOrigin.into(),
dispatch_info: DispatchInfo { weight: 999, ..Default::default() },
dispatch_info: DispatchInfo {
weight: Weight::from_ref_time(999),
..Default::default()
},
}
.into(),
topics: vec![]
@@ -349,7 +370,7 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
event: SysEvent::ExtrinsicFailed {
dispatch_error: DispatchError::BadOrigin.into(),
dispatch_info: DispatchInfo {
weight: 1000,
weight: Weight::from_ref_time(1000),
pays_fee: Pays::Yes,
..Default::default()
},
@@ -362,7 +383,7 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
event: SysEvent::ExtrinsicFailed {
dispatch_error: DispatchError::BadOrigin.into(),
dispatch_info: DispatchInfo {
weight: 800,
weight: Weight::from_ref_time(800),
pays_fee: Pays::Yes,
..Default::default()
},
@@ -375,7 +396,7 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
event: SysEvent::ExtrinsicFailed {
dispatch_error: DispatchError::BadOrigin.into(),
dispatch_info: DispatchInfo {
weight: 800,
weight: Weight::from_ref_time(800),
pays_fee: Pays::No,
..Default::default()
},
+31 -31
View File
@@ -41,7 +41,7 @@
#![allow(unused_parens)]
#![allow(unused_imports)]
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use frame_support::{traits::Get, weights::{RefTimeWeight, Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;
/// Weight functions needed for frame_system.
@@ -59,44 +59,44 @@ pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
/// The range of component `b` is `[0, 3932160]`.
fn remark(_b: u32, ) -> Weight {
(1_000_000 as Weight)
Weight::from_ref_time(1_000_000 as RefTimeWeight)
}
/// The range of component `b` is `[0, 3932160]`.
fn remark_with_event(b: u32, ) -> Weight {
(0 as Weight)
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 0
.saturating_add((1_000 as Weight).saturating_mul(b as Weight))
.saturating_add(Weight::from_ref_time(1_000 as RefTimeWeight).scalar_saturating_mul(b as RefTimeWeight))
}
// Storage: System Digest (r:1 w:1)
// Storage: unknown [0x3a686561707061676573] (r:0 w:1)
fn set_heap_pages() -> Weight {
(5_367_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
Weight::from_ref_time(5_367_000 as RefTimeWeight)
.saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight))
.saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `i` is `[1, 1000]`.
fn set_storage(i: u32, ) -> Weight {
(0 as Weight)
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 1_000
.saturating_add((603_000 as Weight).saturating_mul(i as Weight))
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
.saturating_add(Weight::from_ref_time(603_000 as RefTimeWeight).scalar_saturating_mul(i as RefTimeWeight))
.saturating_add(T::DbWeight::get().writes((1 as RefTimeWeight).saturating_mul(i as RefTimeWeight)))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `i` is `[1, 1000]`.
fn kill_storage(i: u32, ) -> Weight {
(0 as Weight)
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 1_000
.saturating_add((513_000 as Weight).saturating_mul(i as Weight))
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
.saturating_add(Weight::from_ref_time(513_000 as RefTimeWeight).scalar_saturating_mul(i as RefTimeWeight))
.saturating_add(T::DbWeight::get().writes((1 as RefTimeWeight).saturating_mul(i as RefTimeWeight)))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `p` is `[1, 1000]`.
fn kill_prefix(p: u32, ) -> Weight {
(0 as Weight)
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 1_000
.saturating_add((1_026_000 as Weight).saturating_mul(p as Weight))
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight)))
.saturating_add(Weight::from_ref_time(1_026_000 as RefTimeWeight).scalar_saturating_mul(p as RefTimeWeight))
.saturating_add(T::DbWeight::get().writes((1 as RefTimeWeight).saturating_mul(p as RefTimeWeight)))
}
}
@@ -104,43 +104,43 @@ impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
impl WeightInfo for () {
/// The range of component `b` is `[0, 3932160]`.
fn remark(_b: u32, ) -> Weight {
(1_000_000 as Weight)
Weight::from_ref_time(1_000_000 as RefTimeWeight)
}
/// The range of component `b` is `[0, 3932160]`.
fn remark_with_event(b: u32, ) -> Weight {
(0 as Weight)
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 0
.saturating_add((1_000 as Weight).saturating_mul(b as Weight))
.saturating_add(Weight::from_ref_time(1_000 as RefTimeWeight).scalar_saturating_mul(b as RefTimeWeight))
}
// Storage: System Digest (r:1 w:1)
// Storage: unknown [0x3a686561707061676573] (r:0 w:1)
fn set_heap_pages() -> Weight {
(5_367_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
Weight::from_ref_time(5_367_000 as RefTimeWeight)
.saturating_add(RocksDbWeight::get().reads(1 as RefTimeWeight))
.saturating_add(RocksDbWeight::get().writes(2 as RefTimeWeight))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `i` is `[1, 1000]`.
fn set_storage(i: u32, ) -> Weight {
(0 as Weight)
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 1_000
.saturating_add((603_000 as Weight).saturating_mul(i as Weight))
.saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
.saturating_add(Weight::from_ref_time(603_000 as RefTimeWeight).scalar_saturating_mul(i as RefTimeWeight))
.saturating_add(RocksDbWeight::get().writes((1 as RefTimeWeight).saturating_mul(i as RefTimeWeight)))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `i` is `[1, 1000]`.
fn kill_storage(i: u32, ) -> Weight {
(0 as Weight)
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 1_000
.saturating_add((513_000 as Weight).saturating_mul(i as Weight))
.saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
.saturating_add(Weight::from_ref_time(513_000 as RefTimeWeight).scalar_saturating_mul(i as RefTimeWeight))
.saturating_add(RocksDbWeight::get().writes((1 as RefTimeWeight).saturating_mul(i as RefTimeWeight)))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `p` is `[1, 1000]`.
fn kill_prefix(p: u32, ) -> Weight {
(0 as Weight)
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 1_000
.saturating_add((1_026_000 as Weight).saturating_mul(p as Weight))
.saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(p as Weight)))
.saturating_add(Weight::from_ref_time(1_026_000 as RefTimeWeight).scalar_saturating_mul(p as RefTimeWeight))
.saturating_add(RocksDbWeight::get().writes((1 as RefTimeWeight).saturating_mul(p as RefTimeWeight)))
}
}