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
+156 -53
View File
@@ -30,7 +30,7 @@ use substrate_test_utils::assert_eq_uvec;
#[test]
fn basic_scheduling_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log { i: 42, weight: 1000 });
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_ok!(Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.into()));
run_to_block(3);
@@ -45,7 +45,7 @@ fn basic_scheduling_works() {
#[test]
fn scheduling_with_preimages_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log { i: 42, weight: 1000 });
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
let hash = <Test as frame_system::Config>::Hashing::hash_of(&call);
let hashed = MaybeHashed::Hash(hash);
assert_ok!(Preimage::note_preimage(Origin::signed(0), call.encode()));
@@ -65,7 +65,7 @@ fn scheduling_with_preimages_works() {
#[test]
fn scheduling_with_preimage_postpones_correctly() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log { i: 42, weight: 1000 });
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
let hash = <Test as frame_system::Config>::Hashing::hash_of(&call);
let hashed = MaybeHashed::Hash(hash);
@@ -98,7 +98,7 @@ fn scheduling_with_preimage_postpones_correctly() {
fn schedule_after_works() {
new_test_ext().execute_with(|| {
run_to_block(2);
let call = Call::Logger(LoggerCall::log { i: 42, weight: 1000 });
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
// This will schedule the call 3 blocks after the next block... so block 3 + 3 = 6
assert_ok!(Scheduler::do_schedule(DispatchTime::After(3), None, 127, root(), call.into()));
@@ -115,7 +115,7 @@ fn schedule_after_works() {
fn schedule_after_zero_works() {
new_test_ext().execute_with(|| {
run_to_block(2);
let call = Call::Logger(LoggerCall::log { i: 42, weight: 1000 });
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_ok!(Scheduler::do_schedule(DispatchTime::After(0), None, 127, root(), call.into()));
// Will trigger on the next block.
@@ -135,7 +135,7 @@ fn periodic_scheduling_works() {
Some((3, 3)),
127,
root(),
Call::Logger(logger::Call::log { i: 42, weight: 1000 }).into()
Call::Logger(logger::Call::log { i: 42, weight: Weight::from_ref_time(1000) }).into()
));
run_to_block(3);
assert!(logger::log().is_empty());
@@ -157,7 +157,7 @@ fn periodic_scheduling_works() {
#[test]
fn reschedule_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log { i: 42, weight: 1000 });
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_eq!(
Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.into()).unwrap(),
@@ -188,7 +188,7 @@ fn reschedule_works() {
#[test]
fn reschedule_named_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log { i: 42, weight: 1000 });
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_eq!(
Scheduler::do_schedule_named(
@@ -230,7 +230,7 @@ fn reschedule_named_works() {
#[test]
fn reschedule_named_perodic_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log { i: 42, weight: 1000 });
let call = Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_eq!(
Scheduler::do_schedule_named(
@@ -292,7 +292,7 @@ fn cancel_named_scheduling_works_with_normal_cancel() {
None,
127,
root(),
Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
Call::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) }).into(),
)
.unwrap();
let i = Scheduler::do_schedule(
@@ -300,7 +300,7 @@ fn cancel_named_scheduling_works_with_normal_cancel() {
None,
127,
root(),
Call::Logger(LoggerCall::log { i: 42, weight: 1000 }).into(),
Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }).into(),
)
.unwrap();
run_to_block(3);
@@ -322,7 +322,7 @@ fn cancel_named_periodic_scheduling_works() {
Some((3, 3)),
127,
root(),
Call::Logger(LoggerCall::log { i: 42, weight: 1000 }).into(),
Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }).into(),
)
.unwrap();
// same id results in error.
@@ -332,7 +332,7 @@ fn cancel_named_periodic_scheduling_works() {
None,
127,
root(),
Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
Call::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) }).into(),
)
.is_err());
// different id is ok.
@@ -342,7 +342,7 @@ fn cancel_named_periodic_scheduling_works() {
None,
127,
root(),
Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
Call::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) }).into(),
)
.unwrap();
run_to_block(3);
@@ -458,8 +458,11 @@ fn scheduler_respects_priority_ordering_with_soft_deadlines() {
None,
126,
root(),
Call::Logger(LoggerCall::log { i: 2600, weight: max_weight / 2 - item_weight + 1 })
.into(),
Call::Logger(LoggerCall::log {
i: 2600,
weight: max_weight / 2 - item_weight + Weight::one()
})
.into(),
));
// 2600 does not fit with 69 or 42, but has higher priority, so will go through
@@ -484,7 +487,7 @@ fn on_initialize_weight_is_correct() {
None,
255,
root(),
Call::Logger(LoggerCall::log { i: 3, weight: call_weight + 1 }).into(),
Call::Logger(LoggerCall::log { i: 3, weight: call_weight + Weight::one() }).into(),
));
// Anon Periodic
assert_ok!(Scheduler::do_schedule(
@@ -492,7 +495,8 @@ fn on_initialize_weight_is_correct() {
Some((1000, 3)),
128,
root(),
Call::Logger(LoggerCall::log { i: 42, weight: call_weight + 2 }).into(),
Call::Logger(LoggerCall::log { i: 42, weight: call_weight + Weight::from_ref_time(2) })
.into(),
));
// Anon
assert_ok!(Scheduler::do_schedule(
@@ -500,7 +504,8 @@ fn on_initialize_weight_is_correct() {
None,
127,
root(),
Call::Logger(LoggerCall::log { i: 69, weight: call_weight + 3 }).into(),
Call::Logger(LoggerCall::log { i: 69, weight: call_weight + Weight::from_ref_time(3) })
.into(),
));
// Named Periodic
assert_ok!(Scheduler::do_schedule_named(
@@ -509,7 +514,11 @@ fn on_initialize_weight_is_correct() {
Some((1000, 3)),
126,
root(),
Call::Logger(LoggerCall::log { i: 2600, weight: call_weight + 4 }).into(),
Call::Logger(LoggerCall::log {
i: 2600,
weight: call_weight + Weight::from_ref_time(4)
})
.into(),
));
// Will include the named periodic only
@@ -517,7 +526,8 @@ fn on_initialize_weight_is_correct() {
assert_eq!(
actual_weight,
base_weight +
call_weight + 4 + <() as MarginalWeightInfo>::item(true, true, Some(false))
call_weight + Weight::from_ref_time(4) +
<() as MarginalWeightInfo>::item(true, true, Some(false))
);
assert_eq!(logger::log(), vec![(root(), 2600u32)]);
@@ -526,8 +536,10 @@ fn on_initialize_weight_is_correct() {
assert_eq!(
actual_weight,
base_weight +
call_weight + 2 + <() as MarginalWeightInfo>::item(false, false, Some(false)) +
call_weight + 3 + <() as MarginalWeightInfo>::item(true, false, Some(false))
call_weight + Weight::from_ref_time(2) +
<() as MarginalWeightInfo>::item(false, false, Some(false)) +
call_weight + Weight::from_ref_time(3) +
<() as MarginalWeightInfo>::item(true, false, Some(false))
);
assert_eq!(logger::log(), vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]);
@@ -536,7 +548,8 @@ fn on_initialize_weight_is_correct() {
assert_eq!(
actual_weight,
base_weight +
call_weight + 1 + <() as MarginalWeightInfo>::item(false, true, Some(false))
call_weight + Weight::from_ref_time(1) +
<() as MarginalWeightInfo>::item(false, true, Some(false))
);
assert_eq!(
logger::log(),
@@ -552,8 +565,12 @@ fn on_initialize_weight_is_correct() {
#[test]
fn root_calls_works() {
new_test_ext().execute_with(|| {
let call = Box::new(Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into());
let call2 = Box::new(Call::Logger(LoggerCall::log { i: 42, weight: 1000 }).into());
let call = Box::new(
Call::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) }).into(),
);
let call2 = Box::new(
Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }).into(),
);
assert_ok!(Scheduler::schedule_named(Origin::root(), 1u32.encode(), 4, None, 127, call,));
assert_ok!(Scheduler::schedule(Origin::root(), 4, None, 127, call2));
run_to_block(3);
@@ -573,9 +590,15 @@ fn fails_to_schedule_task_in_the_past() {
new_test_ext().execute_with(|| {
run_to_block(3);
let call1 = Box::new(Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into());
let call2 = Box::new(Call::Logger(LoggerCall::log { i: 42, weight: 1000 }).into());
let call3 = Box::new(Call::Logger(LoggerCall::log { i: 42, weight: 1000 }).into());
let call1 = Box::new(
Call::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) }).into(),
);
let call2 = Box::new(
Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }).into(),
);
let call3 = Box::new(
Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }).into(),
);
assert_err!(
Scheduler::schedule_named(Origin::root(), 1u32.encode(), 2, None, 127, call1),
@@ -597,8 +620,12 @@ fn fails_to_schedule_task_in_the_past() {
#[test]
fn should_use_orign() {
new_test_ext().execute_with(|| {
let call = Box::new(Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into());
let call2 = Box::new(Call::Logger(LoggerCall::log { i: 42, weight: 1000 }).into());
let call = Box::new(
Call::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) }).into(),
);
let call2 = Box::new(
Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }).into(),
);
assert_ok!(Scheduler::schedule_named(
system::RawOrigin::Signed(1).into(),
1u32.encode(),
@@ -623,8 +650,12 @@ fn should_use_orign() {
#[test]
fn should_check_orign() {
new_test_ext().execute_with(|| {
let call = Box::new(Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into());
let call2 = Box::new(Call::Logger(LoggerCall::log { i: 42, weight: 1000 }).into());
let call = Box::new(
Call::Logger(LoggerCall::log { i: 69, weight: Weight::from_ref_time(1000) }).into(),
);
let call2 = Box::new(
Call::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }).into(),
);
assert_noop!(
Scheduler::schedule_named(
system::RawOrigin::Signed(2).into(),
@@ -646,10 +677,20 @@ fn should_check_orign() {
#[test]
fn should_check_orign_for_cancel() {
new_test_ext().execute_with(|| {
let call =
Box::new(Call::Logger(LoggerCall::log_without_filter { i: 69, weight: 1000 }).into());
let call2 =
Box::new(Call::Logger(LoggerCall::log_without_filter { i: 42, weight: 1000 }).into());
let call = Box::new(
Call::Logger(LoggerCall::log_without_filter {
i: 69,
weight: Weight::from_ref_time(1000),
})
.into(),
);
let call2 = Box::new(
Call::Logger(LoggerCall::log_without_filter {
i: 42,
weight: Weight::from_ref_time(1000),
})
.into(),
);
assert_ok!(Scheduler::schedule_named(
system::RawOrigin::Signed(1).into(),
1u32.encode(),
@@ -693,14 +734,20 @@ fn migration_to_v3_works() {
Some(ScheduledV1 {
maybe_id: None,
priority: i as u8 + 10,
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }),
call: Call::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100),
}),
maybe_periodic: None,
}),
None,
Some(ScheduledV1 {
maybe_id: Some(b"test".to_vec()),
priority: 123,
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }),
call: Call::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000),
}),
maybe_periodic: Some((456u64, 10)),
}),
];
@@ -718,7 +765,11 @@ fn migration_to_v3_works() {
Some(ScheduledV3Of::<Test> {
maybe_id: None,
priority: 10,
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }).into(),
call: Call::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100)
})
.into(),
maybe_periodic: None,
origin: root(),
_phantom: PhantomData::<u64>::default(),
@@ -727,7 +778,11 @@ fn migration_to_v3_works() {
Some(ScheduledV3Of::<Test> {
maybe_id: Some(b"test".to_vec()),
priority: 123,
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
call: Call::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000)
})
.into(),
maybe_periodic: Some((456u64, 10)),
origin: root(),
_phantom: PhantomData::<u64>::default(),
@@ -740,7 +795,11 @@ fn migration_to_v3_works() {
Some(ScheduledV3Of::<Test> {
maybe_id: None,
priority: 11,
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }).into(),
call: Call::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100)
})
.into(),
maybe_periodic: None,
origin: root(),
_phantom: PhantomData::<u64>::default(),
@@ -749,7 +808,11 @@ fn migration_to_v3_works() {
Some(ScheduledV3Of::<Test> {
maybe_id: Some(b"test".to_vec()),
priority: 123,
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
call: Call::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000)
})
.into(),
maybe_periodic: Some((456u64, 10)),
origin: root(),
_phantom: PhantomData::<u64>::default(),
@@ -762,7 +825,11 @@ fn migration_to_v3_works() {
Some(ScheduledV3Of::<Test> {
maybe_id: None,
priority: 12,
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }).into(),
call: Call::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100)
})
.into(),
maybe_periodic: None,
origin: root(),
_phantom: PhantomData::<u64>::default(),
@@ -771,7 +838,11 @@ fn migration_to_v3_works() {
Some(ScheduledV3Of::<Test> {
maybe_id: Some(b"test".to_vec()),
priority: 123,
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
call: Call::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000)
})
.into(),
maybe_periodic: Some((456u64, 10)),
origin: root(),
_phantom: PhantomData::<u64>::default(),
@@ -794,7 +865,11 @@ fn test_migrate_origin() {
Some(Scheduled {
maybe_id: None,
priority: i as u8 + 10,
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }).into(),
call: Call::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100),
})
.into(),
origin: 3u32,
maybe_periodic: None,
_phantom: Default::default(),
@@ -804,7 +879,11 @@ fn test_migrate_origin() {
maybe_id: Some(b"test".to_vec()),
priority: 123,
origin: 2u32,
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
call: Call::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000),
})
.into(),
maybe_periodic: Some((456u64, 10)),
_phantom: Default::default(),
}),
@@ -833,7 +912,11 @@ fn test_migrate_origin() {
Some(ScheduledV2::<CallOrHashOf<Test>, u64, OriginCaller, u64> {
maybe_id: None,
priority: 10,
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }).into(),
call: Call::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100)
})
.into(),
maybe_periodic: None,
origin: system::RawOrigin::Root.into(),
_phantom: PhantomData::<u64>::default(),
@@ -842,7 +925,11 @@ fn test_migrate_origin() {
Some(ScheduledV2 {
maybe_id: Some(b"test".to_vec()),
priority: 123,
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
call: Call::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000)
})
.into(),
maybe_periodic: Some((456u64, 10)),
origin: system::RawOrigin::None.into(),
_phantom: PhantomData::<u64>::default(),
@@ -855,7 +942,11 @@ fn test_migrate_origin() {
Some(ScheduledV2 {
maybe_id: None,
priority: 11,
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }).into(),
call: Call::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100)
})
.into(),
maybe_periodic: None,
origin: system::RawOrigin::Root.into(),
_phantom: PhantomData::<u64>::default(),
@@ -864,7 +955,11 @@ fn test_migrate_origin() {
Some(ScheduledV2 {
maybe_id: Some(b"test".to_vec()),
priority: 123,
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
call: Call::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000)
})
.into(),
maybe_periodic: Some((456u64, 10)),
origin: system::RawOrigin::None.into(),
_phantom: PhantomData::<u64>::default(),
@@ -877,7 +972,11 @@ fn test_migrate_origin() {
Some(ScheduledV2 {
maybe_id: None,
priority: 12,
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }).into(),
call: Call::Logger(LoggerCall::log {
i: 96,
weight: Weight::from_ref_time(100)
})
.into(),
maybe_periodic: None,
origin: system::RawOrigin::Root.into(),
_phantom: PhantomData::<u64>::default(),
@@ -886,7 +985,11 @@ fn test_migrate_origin() {
Some(ScheduledV2 {
maybe_id: Some(b"test".to_vec()),
priority: 123,
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
call: Call::Logger(LoggerCall::log {
i: 69,
weight: Weight::from_ref_time(1000)
})
.into(),
maybe_periodic: Some((456u64, 10)),
origin: system::RawOrigin::None.into(),
_phantom: PhantomData::<u64>::default(),