mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 15:41:02 +00:00
Preimage registrar and Scheduler integration (#10356)
* initial idea * more * fix compile * add clear and request logic * improve some docs * Add and implement trait * continuing to improve * refcount type * infallible system preimage upload * fmt * fix requests * Make it simple * Make it simple * Formatting * Initial draft * request when scheduled * Docs * Scheduler good * Scheduler good * Scheduler tests working * Add new files * Missing stuff * Repotting, add weights. * Add some tests to preimage pallet * More tests * Fix benchmarks * preimage benchmarks * All preimage benchmarks * Tidy cargo * Update weights.rs * Allow hash provision in benchmarks * Initial work on new benchmarks for Scheduler * Tests working, refactor looks good * Tests for new Scheduler functionality * Use real weight, make tests work with runtimes without Preimage * Rename * Update benchmarks * Formatting * Formatting * Fix weird formatting * Update frame/preimage/src/lib.rs * Fix try-runtime build * Fixes * Fixes * Update frame/support/src/traits/tokens/currency.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/support/src/traits/tokens/currency/reservable.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/support/src/traits/tokens/imbalance.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/preimage/src/mock.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update frame/scheduler/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update frame/preimage/src/lib.rs * Fixes * Fixes * Formatting * Fixes * Fixes * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_scheduler --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/scheduler/src/weights.rs --template=./.maintain/frame-weight-template.hbs * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_preimage --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/preimage/src/weights.rs --template=./.maintain/frame-weight-template.hbs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> Co-authored-by: Parity Bot <admin@parity.io>
This commit is contained in:
@@ -17,12 +17,14 @@
|
||||
|
||||
//! Scheduler pallet benchmarking.
|
||||
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use super::*;
|
||||
use frame_benchmarking::benchmarks;
|
||||
use frame_support::{ensure, traits::OnInitialize};
|
||||
use frame_support::{
|
||||
ensure,
|
||||
traits::{OnInitialize, PreimageProvider, PreimageRecipient},
|
||||
};
|
||||
use frame_system::RawOrigin;
|
||||
use sp_runtime::traits::Hash;
|
||||
use sp_std::{prelude::*, vec};
|
||||
|
||||
use crate::Pallet as Scheduler;
|
||||
@@ -30,37 +32,184 @@ use frame_system::Pallet as System;
|
||||
|
||||
const BLOCK_NUMBER: u32 = 2;
|
||||
|
||||
// Add `n` named items to the schedule
|
||||
fn fill_schedule<T: Config>(when: T::BlockNumber, n: u32) -> Result<(), &'static str> {
|
||||
// Essentially a no-op call.
|
||||
let call = frame_system::Call::set_storage { items: vec![] };
|
||||
/// Add `n` named items to the schedule.
|
||||
///
|
||||
/// For `resolved`:
|
||||
/// - `None`: aborted (hash without preimage)
|
||||
/// - `Some(true)`: hash resolves into call if possible, plain call otherwise
|
||||
/// - `Some(false)`: plain call
|
||||
fn fill_schedule<T: Config>(
|
||||
when: T::BlockNumber,
|
||||
n: u32,
|
||||
periodic: bool,
|
||||
named: bool,
|
||||
resolved: Option<bool>,
|
||||
) -> Result<(), &'static str> {
|
||||
for i in 0..n {
|
||||
// Named schedule is strictly heavier than anonymous
|
||||
Scheduler::<T>::do_schedule_named(
|
||||
i.encode(),
|
||||
DispatchTime::At(when),
|
||||
// Add periodicity
|
||||
Some((T::BlockNumber::one(), 100)),
|
||||
// HARD_DEADLINE priority means it gets executed no matter what
|
||||
0,
|
||||
frame_system::RawOrigin::Root.into(),
|
||||
call.clone().into(),
|
||||
)?;
|
||||
let (call, hash) = call_and_hash::<T>(i);
|
||||
let call_or_hash = match resolved {
|
||||
Some(true) => {
|
||||
T::PreimageProvider::note_preimage(call.encode().try_into().unwrap());
|
||||
if T::PreimageProvider::have_preimage(&hash) {
|
||||
CallOrHashOf::<T>::Hash(hash)
|
||||
} else {
|
||||
call.into()
|
||||
}
|
||||
},
|
||||
Some(false) => call.into(),
|
||||
None => CallOrHashOf::<T>::Hash(hash),
|
||||
};
|
||||
let period = match periodic {
|
||||
true => Some(((i + 100).into(), 100)),
|
||||
false => None,
|
||||
};
|
||||
let t = DispatchTime::At(when);
|
||||
let origin = frame_system::RawOrigin::Root.into();
|
||||
if named {
|
||||
Scheduler::<T>::do_schedule_named(i.encode(), t, period, 0, origin, call_or_hash)?;
|
||||
} else {
|
||||
Scheduler::<T>::do_schedule(t, period, 0, origin, call_or_hash)?;
|
||||
}
|
||||
}
|
||||
ensure!(Agenda::<T>::get(when).len() == n as usize, "didn't fill schedule");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn call_and_hash<T: Config>(i: u32) -> (<T as Config>::Call, T::Hash) {
|
||||
// Essentially a no-op call.
|
||||
let call: <T as Config>::Call = frame_system::Call::remark { remark: i.encode() }.into();
|
||||
let hash = T::Hashing::hash_of(&call);
|
||||
(call, hash)
|
||||
}
|
||||
|
||||
benchmarks! {
|
||||
on_initialize_periodic_named_resolved {
|
||||
let s in 1 .. T::MaxScheduledPerBlock::get();
|
||||
let when = BLOCK_NUMBER.into();
|
||||
fill_schedule::<T>(when, s, true, true, Some(true))?;
|
||||
}: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }
|
||||
verify {
|
||||
assert_eq!(System::<T>::event_count(), s * 2);
|
||||
for i in 0..s {
|
||||
assert_eq!(Agenda::<T>::get(when + (i + 100).into()).len(), 1 as usize);
|
||||
}
|
||||
}
|
||||
|
||||
on_initialize_named_resolved {
|
||||
let s in 1 .. T::MaxScheduledPerBlock::get();
|
||||
let when = BLOCK_NUMBER.into();
|
||||
fill_schedule::<T>(when, s, false, true, Some(true))?;
|
||||
}: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }
|
||||
verify {
|
||||
assert_eq!(System::<T>::event_count(), s * 2);
|
||||
assert!(Agenda::<T>::iter().count() == 0);
|
||||
}
|
||||
|
||||
on_initialize_periodic_resolved {
|
||||
let s in 1 .. T::MaxScheduledPerBlock::get();
|
||||
let when = BLOCK_NUMBER.into();
|
||||
fill_schedule::<T>(when, s, true, false, Some(true))?;
|
||||
}: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }
|
||||
verify {
|
||||
assert_eq!(System::<T>::event_count(), s * 2);
|
||||
for i in 0..s {
|
||||
assert_eq!(Agenda::<T>::get(when + (i + 100).into()).len(), 1 as usize);
|
||||
}
|
||||
}
|
||||
|
||||
on_initialize_resolved {
|
||||
let s in 1 .. T::MaxScheduledPerBlock::get();
|
||||
let when = BLOCK_NUMBER.into();
|
||||
fill_schedule::<T>(when, s, false, false, Some(true))?;
|
||||
}: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }
|
||||
verify {
|
||||
assert_eq!(System::<T>::event_count(), s * 2);
|
||||
assert!(Agenda::<T>::iter().count() == 0);
|
||||
}
|
||||
|
||||
on_initialize_named_aborted {
|
||||
let s in 1 .. T::MaxScheduledPerBlock::get();
|
||||
let when = BLOCK_NUMBER.into();
|
||||
fill_schedule::<T>(when, s, false, true, None)?;
|
||||
}: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }
|
||||
verify {
|
||||
assert_eq!(System::<T>::event_count(), 0);
|
||||
if let Some(delay) = T::NoPreimagePostponement::get() {
|
||||
assert_eq!(Agenda::<T>::get(when + delay).len(), s as usize);
|
||||
} else {
|
||||
assert!(Agenda::<T>::iter().count() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
on_initialize_aborted {
|
||||
let s in 1 .. T::MaxScheduledPerBlock::get();
|
||||
let when = BLOCK_NUMBER.into();
|
||||
fill_schedule::<T>(when, s, false, false, None)?;
|
||||
}: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }
|
||||
verify {
|
||||
assert_eq!(System::<T>::event_count(), 0);
|
||||
if let Some(delay) = T::NoPreimagePostponement::get() {
|
||||
assert_eq!(Agenda::<T>::get(when + delay).len(), s as usize);
|
||||
} else {
|
||||
assert!(Agenda::<T>::iter().count() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
on_initialize_periodic_named {
|
||||
let s in 1 .. T::MaxScheduledPerBlock::get();
|
||||
let when = BLOCK_NUMBER.into();
|
||||
fill_schedule::<T>(when, s, true, true, Some(false))?;
|
||||
}: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }
|
||||
verify {
|
||||
assert_eq!(System::<T>::event_count(), s);
|
||||
for i in 0..s {
|
||||
assert_eq!(Agenda::<T>::get(when + (i + 100).into()).len(), 1 as usize);
|
||||
}
|
||||
}
|
||||
|
||||
on_initialize_periodic {
|
||||
let s in 1 .. T::MaxScheduledPerBlock::get();
|
||||
let when = BLOCK_NUMBER.into();
|
||||
fill_schedule::<T>(when, s, true, false, Some(false))?;
|
||||
}: { Scheduler::<T>::on_initialize(when); }
|
||||
verify {
|
||||
assert_eq!(System::<T>::event_count(), s);
|
||||
for i in 0..s {
|
||||
assert_eq!(Agenda::<T>::get(when + (i + 100).into()).len(), 1 as usize);
|
||||
}
|
||||
}
|
||||
|
||||
on_initialize_named {
|
||||
let s in 1 .. T::MaxScheduledPerBlock::get();
|
||||
let when = BLOCK_NUMBER.into();
|
||||
fill_schedule::<T>(when, s, false, true, Some(false))?;
|
||||
}: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }
|
||||
verify {
|
||||
assert_eq!(System::<T>::event_count(), s);
|
||||
assert!(Agenda::<T>::iter().count() == 0);
|
||||
}
|
||||
|
||||
on_initialize {
|
||||
let s in 1 .. T::MaxScheduledPerBlock::get();
|
||||
let when = BLOCK_NUMBER.into();
|
||||
fill_schedule::<T>(when, s, false, false, Some(false))?;
|
||||
}: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }
|
||||
verify {
|
||||
assert_eq!(System::<T>::event_count(), s);
|
||||
assert!(Agenda::<T>::iter().count() == 0);
|
||||
}
|
||||
|
||||
schedule {
|
||||
let s in 0 .. T::MaxScheduledPerBlock::get();
|
||||
let when = BLOCK_NUMBER.into();
|
||||
let periodic = Some((T::BlockNumber::one(), 100));
|
||||
let priority = 0;
|
||||
// Essentially a no-op call.
|
||||
let call = Box::new(frame_system::Call::set_storage { items: vec![] }.into());
|
||||
let inner_call = frame_system::Call::set_storage { items: vec![] }.into();
|
||||
let call = Box::new(CallOrHashOf::<T>::Value(inner_call));
|
||||
|
||||
fill_schedule::<T>(when, s)?;
|
||||
fill_schedule::<T>(when, s, true, true, Some(false))?;
|
||||
}: _(RawOrigin::Root, when, periodic, priority, call)
|
||||
verify {
|
||||
ensure!(
|
||||
@@ -73,7 +222,7 @@ benchmarks! {
|
||||
let s in 1 .. T::MaxScheduledPerBlock::get();
|
||||
let when = BLOCK_NUMBER.into();
|
||||
|
||||
fill_schedule::<T>(when, s)?;
|
||||
fill_schedule::<T>(when, s, true, true, Some(false))?;
|
||||
assert_eq!(Agenda::<T>::get(when).len(), s as usize);
|
||||
}: _(RawOrigin::Root, when, 0)
|
||||
verify {
|
||||
@@ -95,9 +244,10 @@ benchmarks! {
|
||||
let periodic = Some((T::BlockNumber::one(), 100));
|
||||
let priority = 0;
|
||||
// Essentially a no-op call.
|
||||
let call = Box::new(frame_system::Call::set_storage { items: vec![] }.into());
|
||||
let inner_call = frame_system::Call::set_storage { items: vec![] }.into();
|
||||
let call = Box::new(CallOrHashOf::<T>::Value(inner_call));
|
||||
|
||||
fill_schedule::<T>(when, s)?;
|
||||
fill_schedule::<T>(when, s, true, true, Some(false))?;
|
||||
}: _(RawOrigin::Root, id, when, periodic, priority, call)
|
||||
verify {
|
||||
ensure!(
|
||||
@@ -110,7 +260,7 @@ benchmarks! {
|
||||
let s in 1 .. T::MaxScheduledPerBlock::get();
|
||||
let when = BLOCK_NUMBER.into();
|
||||
|
||||
fill_schedule::<T>(when, s)?;
|
||||
fill_schedule::<T>(when, s, true, true, Some(false))?;
|
||||
}: _(RawOrigin::Root, 0.encode())
|
||||
verify {
|
||||
ensure!(
|
||||
@@ -124,21 +274,5 @@ benchmarks! {
|
||||
);
|
||||
}
|
||||
|
||||
// TODO [#7141]: Make this more complex and flexible so it can be used in automation.
|
||||
#[extra]
|
||||
on_initialize {
|
||||
let s in 0 .. T::MaxScheduledPerBlock::get();
|
||||
let when = BLOCK_NUMBER.into();
|
||||
fill_schedule::<T>(when, s)?;
|
||||
}: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }
|
||||
verify {
|
||||
assert_eq!(System::<T>::event_count(), s);
|
||||
// Next block should have all the schedules again
|
||||
ensure!(
|
||||
Agenda::<T>::get(when + T::BlockNumber::one()).len() == s as usize,
|
||||
"didn't append schedule"
|
||||
);
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(Scheduler, crate::tests::new_test_ext(), crate::tests::Test);
|
||||
impl_benchmark_test_suite!(Scheduler, crate::mock::new_test_ext(), crate::mock::Test);
|
||||
}
|
||||
|
||||
+261
-1116
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,203 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! # Scheduler test environment.
|
||||
|
||||
use super::*;
|
||||
|
||||
use crate as scheduler;
|
||||
use frame_support::{
|
||||
ord_parameter_types, parameter_types,
|
||||
traits::{Contains, EnsureOneOf, EqualPrivilegeOnly, OnFinalize, OnInitialize},
|
||||
weights::constants::RocksDbWeight,
|
||||
};
|
||||
use frame_system::{EnsureRoot, EnsureSignedBy};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
Perbill,
|
||||
};
|
||||
|
||||
// Logger module to track execution.
|
||||
#[frame_support::pallet]
|
||||
pub mod logger {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
use std::cell::RefCell;
|
||||
|
||||
thread_local! {
|
||||
static LOG: RefCell<Vec<(OriginCaller, u32)>> = RefCell::new(Vec::new());
|
||||
}
|
||||
pub fn log() -> Vec<(OriginCaller, u32)> {
|
||||
LOG.with(|log| log.borrow().clone())
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
Logged(u32, Weight),
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T>
|
||||
where
|
||||
<T as system::Config>::Origin: OriginTrait<PalletsOrigin = OriginCaller>,
|
||||
{
|
||||
#[pallet::weight(*weight)]
|
||||
pub fn log(origin: OriginFor<T>, i: u32, weight: Weight) -> DispatchResult {
|
||||
Self::deposit_event(Event::Logged(i, weight));
|
||||
LOG.with(|log| {
|
||||
log.borrow_mut().push((origin.caller().clone(), i));
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[pallet::weight(*weight)]
|
||||
pub fn log_without_filter(origin: OriginFor<T>, i: u32, weight: Weight) -> DispatchResult {
|
||||
Self::deposit_event(Event::Logged(i, weight));
|
||||
LOG.with(|log| {
|
||||
log.borrow_mut().push((origin.caller().clone(), i));
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
|
||||
frame_support::construct_runtime!(
|
||||
pub enum Test where
|
||||
Block = Block,
|
||||
NodeBlock = Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Logger: logger::{Pallet, Call, Event<T>},
|
||||
Scheduler: scheduler::{Pallet, Call, Storage, Event<T>},
|
||||
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>},
|
||||
}
|
||||
);
|
||||
|
||||
// Scheduler must dispatch with root and no filter, this tests base filter is indeed not used.
|
||||
pub struct BaseFilter;
|
||||
impl Contains<Call> for BaseFilter {
|
||||
fn contains(call: &Call) -> bool {
|
||||
!matches!(call, Call::Logger(LoggerCall::log { .. }))
|
||||
}
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::simple_max(2_000_000_000_000);
|
||||
}
|
||||
impl system::Config for Test {
|
||||
type BaseCallFilter = BaseFilter;
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = RocksDbWeight;
|
||||
type Origin = Origin;
|
||||
type Call = Call;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Header = Header;
|
||||
type Event = Event;
|
||||
type BlockHashCount = BlockHashCount;
|
||||
type Version = ();
|
||||
type PalletInfo = PalletInfo;
|
||||
type AccountData = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
type SystemWeightInfo = ();
|
||||
type SS58Prefix = ();
|
||||
type OnSetCode = ();
|
||||
type MaxConsumers = frame_support::traits::ConstU32<16>;
|
||||
}
|
||||
impl logger::Config for Test {
|
||||
type Event = Event;
|
||||
}
|
||||
parameter_types! {
|
||||
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;
|
||||
pub const MaxScheduledPerBlock: u32 = 10;
|
||||
pub const MaxSize: u32 = 1024;
|
||||
pub const NoPreimagePostponement: Option<u64> = Some(2);
|
||||
}
|
||||
ord_parameter_types! {
|
||||
pub const One: u64 = 1;
|
||||
}
|
||||
|
||||
impl pallet_preimage::Config for Test {
|
||||
type Event = Event;
|
||||
type WeightInfo = ();
|
||||
type Currency = ();
|
||||
type ManagerOrigin = EnsureRoot<u64>;
|
||||
type MaxSize = MaxSize;
|
||||
type BaseDeposit = ();
|
||||
type ByteDeposit = ();
|
||||
}
|
||||
|
||||
impl Config for Test {
|
||||
type Event = Event;
|
||||
type Origin = Origin;
|
||||
type PalletsOrigin = OriginCaller;
|
||||
type Call = Call;
|
||||
type MaximumWeight = MaximumSchedulerWeight;
|
||||
type ScheduleOrigin = EnsureOneOf<EnsureRoot<u64>, EnsureSignedBy<One, u64>>;
|
||||
type MaxScheduledPerBlock = MaxScheduledPerBlock;
|
||||
type WeightInfo = ();
|
||||
type OriginPrivilegeCmp = EqualPrivilegeOnly;
|
||||
type PreimageProvider = Preimage;
|
||||
type NoPreimagePostponement = NoPreimagePostponement;
|
||||
}
|
||||
|
||||
pub type LoggerCall = logger::Call<Test>;
|
||||
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
t.into()
|
||||
}
|
||||
|
||||
pub fn run_to_block(n: u64) {
|
||||
while System::block_number() < n {
|
||||
Scheduler::on_finalize(System::block_number());
|
||||
System::set_block_number(System::block_number() + 1);
|
||||
Scheduler::on_initialize(System::block_number());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn root() -> OriginCaller {
|
||||
system::RawOrigin::Root.into()
|
||||
}
|
||||
@@ -0,0 +1,901 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! # Scheduler tests.
|
||||
|
||||
use super::*;
|
||||
use crate::mock::{logger, new_test_ext, root, run_to_block, Call, LoggerCall, Scheduler, Test, *};
|
||||
use frame_support::{
|
||||
assert_err, assert_noop, assert_ok,
|
||||
traits::{Contains, OnInitialize, PreimageProvider},
|
||||
Hashable,
|
||||
};
|
||||
use sp_runtime::traits::Hash;
|
||||
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 });
|
||||
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);
|
||||
assert!(logger::log().is_empty());
|
||||
run_to_block(4);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
run_to_block(100);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scheduling_with_preimages_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let call = Call::Logger(LoggerCall::log { i: 42, weight: 1000 });
|
||||
let hash = <Test as frame_system::Config>::Hashing::hash_of(&call);
|
||||
let hashed = MaybeHashed::Hash(hash.clone());
|
||||
assert_ok!(Preimage::note_preimage(Origin::signed(0), call.encode()));
|
||||
assert_ok!(Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), hashed));
|
||||
assert!(Preimage::preimage_requested(&hash));
|
||||
run_to_block(3);
|
||||
assert!(logger::log().is_empty());
|
||||
run_to_block(4);
|
||||
assert!(!Preimage::have_preimage(&hash));
|
||||
assert!(!Preimage::preimage_requested(&hash));
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
run_to_block(100);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scheduling_with_preimage_postpones_correctly() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let call = Call::Logger(LoggerCall::log { i: 42, weight: 1000 });
|
||||
let hash = <Test as frame_system::Config>::Hashing::hash_of(&call);
|
||||
let hashed = MaybeHashed::Hash(hash.clone());
|
||||
|
||||
assert_ok!(Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), hashed));
|
||||
assert!(Preimage::preimage_requested(&hash));
|
||||
|
||||
run_to_block(4);
|
||||
// #4 empty due to no preimage
|
||||
assert!(logger::log().is_empty());
|
||||
|
||||
// Register preimage.
|
||||
assert_ok!(Preimage::note_preimage(Origin::signed(0), call.encode()));
|
||||
|
||||
run_to_block(5);
|
||||
// #5 empty since postponement is 2 blocks.
|
||||
assert!(logger::log().is_empty());
|
||||
|
||||
run_to_block(6);
|
||||
// #6 is good.
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
assert!(!Preimage::have_preimage(&hash));
|
||||
assert!(!Preimage::preimage_requested(&hash));
|
||||
|
||||
run_to_block(100);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schedule_after_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(2);
|
||||
let call = Call::Logger(LoggerCall::log { i: 42, weight: 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()));
|
||||
run_to_block(5);
|
||||
assert!(logger::log().is_empty());
|
||||
run_to_block(6);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
run_to_block(100);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schedule_after_zero_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(2);
|
||||
let call = Call::Logger(LoggerCall::log { i: 42, weight: 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.
|
||||
run_to_block(3);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
run_to_block(100);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn periodic_scheduling_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// at #4, every 3 blocks, 3 times.
|
||||
assert_ok!(Scheduler::do_schedule(
|
||||
DispatchTime::At(4),
|
||||
Some((3, 3)),
|
||||
127,
|
||||
root(),
|
||||
Call::Logger(logger::Call::log { i: 42, weight: 1000 }).into()
|
||||
));
|
||||
run_to_block(3);
|
||||
assert!(logger::log().is_empty());
|
||||
run_to_block(4);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
run_to_block(6);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
run_to_block(7);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32)]);
|
||||
run_to_block(9);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32)]);
|
||||
run_to_block(10);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]);
|
||||
run_to_block(100);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reschedule_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let call = Call::Logger(LoggerCall::log { i: 42, weight: 1000 });
|
||||
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
|
||||
assert_eq!(
|
||||
Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.into()).unwrap(),
|
||||
(4, 0)
|
||||
);
|
||||
|
||||
run_to_block(3);
|
||||
assert!(logger::log().is_empty());
|
||||
|
||||
assert_eq!(Scheduler::do_reschedule((4, 0), DispatchTime::At(6)).unwrap(), (6, 0));
|
||||
|
||||
assert_noop!(
|
||||
Scheduler::do_reschedule((6, 0), DispatchTime::At(6)),
|
||||
Error::<Test>::RescheduleNoChange
|
||||
);
|
||||
|
||||
run_to_block(4);
|
||||
assert!(logger::log().is_empty());
|
||||
|
||||
run_to_block(6);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
|
||||
run_to_block(100);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reschedule_named_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let call = Call::Logger(LoggerCall::log { i: 42, weight: 1000 });
|
||||
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
|
||||
assert_eq!(
|
||||
Scheduler::do_schedule_named(
|
||||
1u32.encode(),
|
||||
DispatchTime::At(4),
|
||||
None,
|
||||
127,
|
||||
root(),
|
||||
call.into(),
|
||||
)
|
||||
.unwrap(),
|
||||
(4, 0)
|
||||
);
|
||||
|
||||
run_to_block(3);
|
||||
assert!(logger::log().is_empty());
|
||||
|
||||
assert_eq!(
|
||||
Scheduler::do_reschedule_named(1u32.encode(), DispatchTime::At(6)).unwrap(),
|
||||
(6, 0)
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Scheduler::do_reschedule_named(1u32.encode(), DispatchTime::At(6)),
|
||||
Error::<Test>::RescheduleNoChange
|
||||
);
|
||||
|
||||
run_to_block(4);
|
||||
assert!(logger::log().is_empty());
|
||||
|
||||
run_to_block(6);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
|
||||
run_to_block(100);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reschedule_named_perodic_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let call = Call::Logger(LoggerCall::log { i: 42, weight: 1000 });
|
||||
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
|
||||
assert_eq!(
|
||||
Scheduler::do_schedule_named(
|
||||
1u32.encode(),
|
||||
DispatchTime::At(4),
|
||||
Some((3, 3)),
|
||||
127,
|
||||
root(),
|
||||
call.into(),
|
||||
)
|
||||
.unwrap(),
|
||||
(4, 0)
|
||||
);
|
||||
|
||||
run_to_block(3);
|
||||
assert!(logger::log().is_empty());
|
||||
|
||||
assert_eq!(
|
||||
Scheduler::do_reschedule_named(1u32.encode(), DispatchTime::At(5)).unwrap(),
|
||||
(5, 0)
|
||||
);
|
||||
assert_eq!(
|
||||
Scheduler::do_reschedule_named(1u32.encode(), DispatchTime::At(6)).unwrap(),
|
||||
(6, 0)
|
||||
);
|
||||
|
||||
run_to_block(5);
|
||||
assert!(logger::log().is_empty());
|
||||
|
||||
run_to_block(6);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
|
||||
assert_eq!(
|
||||
Scheduler::do_reschedule_named(1u32.encode(), DispatchTime::At(10)).unwrap(),
|
||||
(10, 0)
|
||||
);
|
||||
|
||||
run_to_block(9);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
|
||||
run_to_block(10);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32)]);
|
||||
|
||||
run_to_block(13);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]);
|
||||
|
||||
run_to_block(100);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cancel_named_scheduling_works_with_normal_cancel() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// at #4.
|
||||
Scheduler::do_schedule_named(
|
||||
1u32.encode(),
|
||||
DispatchTime::At(4),
|
||||
None,
|
||||
127,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
|
||||
)
|
||||
.unwrap();
|
||||
let i = Scheduler::do_schedule(
|
||||
DispatchTime::At(4),
|
||||
None,
|
||||
127,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 42, weight: 1000 }).into(),
|
||||
)
|
||||
.unwrap();
|
||||
run_to_block(3);
|
||||
assert!(logger::log().is_empty());
|
||||
assert_ok!(Scheduler::do_cancel_named(None, 1u32.encode()));
|
||||
assert_ok!(Scheduler::do_cancel(None, i));
|
||||
run_to_block(100);
|
||||
assert!(logger::log().is_empty());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cancel_named_periodic_scheduling_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// at #4, every 3 blocks, 3 times.
|
||||
Scheduler::do_schedule_named(
|
||||
1u32.encode(),
|
||||
DispatchTime::At(4),
|
||||
Some((3, 3)),
|
||||
127,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 42, weight: 1000 }).into(),
|
||||
)
|
||||
.unwrap();
|
||||
// same id results in error.
|
||||
assert!(Scheduler::do_schedule_named(
|
||||
1u32.encode(),
|
||||
DispatchTime::At(4),
|
||||
None,
|
||||
127,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
|
||||
)
|
||||
.is_err());
|
||||
// different id is ok.
|
||||
Scheduler::do_schedule_named(
|
||||
2u32.encode(),
|
||||
DispatchTime::At(8),
|
||||
None,
|
||||
127,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
|
||||
)
|
||||
.unwrap();
|
||||
run_to_block(3);
|
||||
assert!(logger::log().is_empty());
|
||||
run_to_block(4);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
run_to_block(6);
|
||||
assert_ok!(Scheduler::do_cancel_named(None, 1u32.encode()));
|
||||
run_to_block(100);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 69u32)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scheduler_respects_weight_limits() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Scheduler::do_schedule(
|
||||
DispatchTime::At(4),
|
||||
None,
|
||||
127,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 42, weight: MaximumSchedulerWeight::get() / 2 })
|
||||
.into(),
|
||||
));
|
||||
assert_ok!(Scheduler::do_schedule(
|
||||
DispatchTime::At(4),
|
||||
None,
|
||||
127,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 69, weight: MaximumSchedulerWeight::get() / 2 })
|
||||
.into(),
|
||||
));
|
||||
// 69 and 42 do not fit together
|
||||
run_to_block(4);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32)]);
|
||||
run_to_block(5);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 69u32)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scheduler_respects_hard_deadlines_more() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Scheduler::do_schedule(
|
||||
DispatchTime::At(4),
|
||||
None,
|
||||
0,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 42, weight: MaximumSchedulerWeight::get() / 2 })
|
||||
.into(),
|
||||
));
|
||||
assert_ok!(Scheduler::do_schedule(
|
||||
DispatchTime::At(4),
|
||||
None,
|
||||
0,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 69, weight: MaximumSchedulerWeight::get() / 2 })
|
||||
.into(),
|
||||
));
|
||||
// With base weights, 69 and 42 should not fit together, but do because of hard
|
||||
// deadlines
|
||||
run_to_block(4);
|
||||
assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 69u32)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scheduler_respects_priority_ordering() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Scheduler::do_schedule(
|
||||
DispatchTime::At(4),
|
||||
None,
|
||||
1,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 42, weight: MaximumSchedulerWeight::get() / 2 })
|
||||
.into(),
|
||||
));
|
||||
assert_ok!(Scheduler::do_schedule(
|
||||
DispatchTime::At(4),
|
||||
None,
|
||||
0,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 69, weight: MaximumSchedulerWeight::get() / 2 })
|
||||
.into(),
|
||||
));
|
||||
run_to_block(4);
|
||||
assert_eq!(logger::log(), vec![(root(), 69u32), (root(), 42u32)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scheduler_respects_priority_ordering_with_soft_deadlines() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let max_weight = MaximumSchedulerWeight::get() - <() as WeightInfo>::on_initialize(0);
|
||||
let item_weight =
|
||||
<() as WeightInfo>::on_initialize(1) - <() as WeightInfo>::on_initialize(0);
|
||||
assert_ok!(Scheduler::do_schedule(
|
||||
DispatchTime::At(4),
|
||||
None,
|
||||
255,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 42, weight: max_weight / 2 - item_weight }).into(),
|
||||
));
|
||||
assert_ok!(Scheduler::do_schedule(
|
||||
DispatchTime::At(4),
|
||||
None,
|
||||
127,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 69, weight: max_weight / 2 - item_weight }).into(),
|
||||
));
|
||||
assert_ok!(Scheduler::do_schedule(
|
||||
DispatchTime::At(4),
|
||||
None,
|
||||
126,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 2600, weight: max_weight / 2 - item_weight + 1 })
|
||||
.into(),
|
||||
));
|
||||
|
||||
// 2600 does not fit with 69 or 42, but has higher priority, so will go through
|
||||
run_to_block(4);
|
||||
assert_eq!(logger::log(), vec![(root(), 2600u32)]);
|
||||
// 69 and 42 fit together
|
||||
run_to_block(5);
|
||||
assert_eq!(logger::log(), vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn on_initialize_weight_is_correct() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let base_weight = <() as WeightInfo>::on_initialize(0);
|
||||
let call_weight = MaximumSchedulerWeight::get() / 4;
|
||||
|
||||
// Named
|
||||
assert_ok!(Scheduler::do_schedule_named(
|
||||
1u32.encode(),
|
||||
DispatchTime::At(3),
|
||||
None,
|
||||
255,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 3, weight: call_weight + 1 }).into(),
|
||||
));
|
||||
// Anon Periodic
|
||||
assert_ok!(Scheduler::do_schedule(
|
||||
DispatchTime::At(2),
|
||||
Some((1000, 3)),
|
||||
128,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 42, weight: call_weight + 2 }).into(),
|
||||
));
|
||||
// Anon
|
||||
assert_ok!(Scheduler::do_schedule(
|
||||
DispatchTime::At(2),
|
||||
None,
|
||||
127,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 69, weight: call_weight + 3 }).into(),
|
||||
));
|
||||
// Named Periodic
|
||||
assert_ok!(Scheduler::do_schedule_named(
|
||||
2u32.encode(),
|
||||
DispatchTime::At(1),
|
||||
Some((1000, 3)),
|
||||
126,
|
||||
root(),
|
||||
Call::Logger(LoggerCall::log { i: 2600, weight: call_weight + 4 }).into(),
|
||||
));
|
||||
|
||||
// Will include the named periodic only
|
||||
let actual_weight = Scheduler::on_initialize(1);
|
||||
assert_eq!(
|
||||
actual_weight,
|
||||
base_weight +
|
||||
call_weight + 4 + <() as MarginalWeightInfo>::item(true, true, Some(false))
|
||||
);
|
||||
assert_eq!(logger::log(), vec![(root(), 2600u32)]);
|
||||
|
||||
// Will include anon and anon periodic
|
||||
let actual_weight = Scheduler::on_initialize(2);
|
||||
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))
|
||||
);
|
||||
assert_eq!(logger::log(), vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]);
|
||||
|
||||
// Will include named only
|
||||
let actual_weight = Scheduler::on_initialize(3);
|
||||
assert_eq!(
|
||||
actual_weight,
|
||||
base_weight +
|
||||
call_weight + 1 + <() as MarginalWeightInfo>::item(false, true, Some(false))
|
||||
);
|
||||
assert_eq!(
|
||||
logger::log(),
|
||||
vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32), (root(), 3u32)]
|
||||
);
|
||||
|
||||
// Will contain none
|
||||
let actual_weight = Scheduler::on_initialize(4);
|
||||
assert_eq!(actual_weight, base_weight);
|
||||
});
|
||||
}
|
||||
|
||||
#[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());
|
||||
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);
|
||||
// Scheduled calls are in the agenda.
|
||||
assert_eq!(Agenda::<Test>::get(4).len(), 2);
|
||||
assert!(logger::log().is_empty());
|
||||
assert_ok!(Scheduler::cancel_named(Origin::root(), 1u32.encode()));
|
||||
assert_ok!(Scheduler::cancel(Origin::root(), 4, 1));
|
||||
// Scheduled calls are made NONE, so should not effect state
|
||||
run_to_block(100);
|
||||
assert!(logger::log().is_empty());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
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());
|
||||
|
||||
assert_err!(
|
||||
Scheduler::schedule_named(Origin::root(), 1u32.encode(), 2, None, 127, call1),
|
||||
Error::<Test>::TargetBlockNumberInPast,
|
||||
);
|
||||
|
||||
assert_err!(
|
||||
Scheduler::schedule(Origin::root(), 2, None, 127, call2),
|
||||
Error::<Test>::TargetBlockNumberInPast,
|
||||
);
|
||||
|
||||
assert_err!(
|
||||
Scheduler::schedule(Origin::root(), 3, None, 127, call3),
|
||||
Error::<Test>::TargetBlockNumberInPast,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[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());
|
||||
assert_ok!(Scheduler::schedule_named(
|
||||
system::RawOrigin::Signed(1).into(),
|
||||
1u32.encode(),
|
||||
4,
|
||||
None,
|
||||
127,
|
||||
call,
|
||||
));
|
||||
assert_ok!(Scheduler::schedule(system::RawOrigin::Signed(1).into(), 4, None, 127, call2,));
|
||||
run_to_block(3);
|
||||
// Scheduled calls are in the agenda.
|
||||
assert_eq!(Agenda::<Test>::get(4).len(), 2);
|
||||
assert!(logger::log().is_empty());
|
||||
assert_ok!(Scheduler::cancel_named(system::RawOrigin::Signed(1).into(), 1u32.encode()));
|
||||
assert_ok!(Scheduler::cancel(system::RawOrigin::Signed(1).into(), 4, 1));
|
||||
// Scheduled calls are made NONE, so should not effect state
|
||||
run_to_block(100);
|
||||
assert!(logger::log().is_empty());
|
||||
});
|
||||
}
|
||||
|
||||
#[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());
|
||||
assert_noop!(
|
||||
Scheduler::schedule_named(
|
||||
system::RawOrigin::Signed(2).into(),
|
||||
1u32.encode(),
|
||||
4,
|
||||
None,
|
||||
127,
|
||||
call
|
||||
),
|
||||
BadOrigin
|
||||
);
|
||||
assert_noop!(
|
||||
Scheduler::schedule(system::RawOrigin::Signed(2).into(), 4, None, 127, call2),
|
||||
BadOrigin
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[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());
|
||||
assert_ok!(Scheduler::schedule_named(
|
||||
system::RawOrigin::Signed(1).into(),
|
||||
1u32.encode(),
|
||||
4,
|
||||
None,
|
||||
127,
|
||||
call,
|
||||
));
|
||||
assert_ok!(Scheduler::schedule(system::RawOrigin::Signed(1).into(), 4, None, 127, call2,));
|
||||
run_to_block(3);
|
||||
// Scheduled calls are in the agenda.
|
||||
assert_eq!(Agenda::<Test>::get(4).len(), 2);
|
||||
assert!(logger::log().is_empty());
|
||||
assert_noop!(
|
||||
Scheduler::cancel_named(system::RawOrigin::Signed(2).into(), 1u32.encode()),
|
||||
BadOrigin
|
||||
);
|
||||
assert_noop!(Scheduler::cancel(system::RawOrigin::Signed(2).into(), 4, 1), BadOrigin);
|
||||
assert_noop!(
|
||||
Scheduler::cancel_named(system::RawOrigin::Root.into(), 1u32.encode()),
|
||||
BadOrigin
|
||||
);
|
||||
assert_noop!(Scheduler::cancel(system::RawOrigin::Root.into(), 4, 1), BadOrigin);
|
||||
run_to_block(5);
|
||||
assert_eq!(
|
||||
logger::log(),
|
||||
vec![
|
||||
(system::RawOrigin::Signed(1).into(), 69u32),
|
||||
(system::RawOrigin::Signed(1).into(), 42u32)
|
||||
]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn migration_to_v3_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
for i in 0..3u64 {
|
||||
let k = i.twox_64_concat();
|
||||
let old = vec![
|
||||
Some(ScheduledV1 {
|
||||
maybe_id: None,
|
||||
priority: i as u8 + 10,
|
||||
call: Call::Logger(LoggerCall::log { i: 96, weight: 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 }),
|
||||
maybe_periodic: Some((456u64, 10)),
|
||||
}),
|
||||
];
|
||||
frame_support::migration::put_storage_value(b"Scheduler", b"Agenda", &k, old);
|
||||
}
|
||||
|
||||
assert_eq!(StorageVersion::<Test>::get(), Releases::V1);
|
||||
|
||||
assert!(Scheduler::migrate_v1_to_v3());
|
||||
|
||||
assert_eq_uvec!(
|
||||
Agenda::<Test>::iter().collect::<Vec<_>>(),
|
||||
vec![
|
||||
(
|
||||
0,
|
||||
vec![
|
||||
Some(ScheduledV3Of::<Test> {
|
||||
maybe_id: None,
|
||||
priority: 10,
|
||||
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }).into(),
|
||||
maybe_periodic: None,
|
||||
origin: root(),
|
||||
_phantom: PhantomData::<u64>::default(),
|
||||
}),
|
||||
None,
|
||||
Some(ScheduledV3Of::<Test> {
|
||||
maybe_id: Some(b"test".to_vec()),
|
||||
priority: 123,
|
||||
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
|
||||
maybe_periodic: Some((456u64, 10)),
|
||||
origin: root(),
|
||||
_phantom: PhantomData::<u64>::default(),
|
||||
}),
|
||||
]
|
||||
),
|
||||
(
|
||||
1,
|
||||
vec![
|
||||
Some(ScheduledV3Of::<Test> {
|
||||
maybe_id: None,
|
||||
priority: 11,
|
||||
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }).into(),
|
||||
maybe_periodic: None,
|
||||
origin: root(),
|
||||
_phantom: PhantomData::<u64>::default(),
|
||||
}),
|
||||
None,
|
||||
Some(ScheduledV3Of::<Test> {
|
||||
maybe_id: Some(b"test".to_vec()),
|
||||
priority: 123,
|
||||
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
|
||||
maybe_periodic: Some((456u64, 10)),
|
||||
origin: root(),
|
||||
_phantom: PhantomData::<u64>::default(),
|
||||
}),
|
||||
]
|
||||
),
|
||||
(
|
||||
2,
|
||||
vec![
|
||||
Some(ScheduledV3Of::<Test> {
|
||||
maybe_id: None,
|
||||
priority: 12,
|
||||
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }).into(),
|
||||
maybe_periodic: None,
|
||||
origin: root(),
|
||||
_phantom: PhantomData::<u64>::default(),
|
||||
}),
|
||||
None,
|
||||
Some(ScheduledV3Of::<Test> {
|
||||
maybe_id: Some(b"test".to_vec()),
|
||||
priority: 123,
|
||||
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
|
||||
maybe_periodic: Some((456u64, 10)),
|
||||
origin: root(),
|
||||
_phantom: PhantomData::<u64>::default(),
|
||||
}),
|
||||
]
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
assert_eq!(StorageVersion::<Test>::get(), Releases::V3);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_migrate_origin() {
|
||||
new_test_ext().execute_with(|| {
|
||||
for i in 0..3u64 {
|
||||
let k = i.twox_64_concat();
|
||||
let old: Vec<Option<Scheduled<CallOrHashOf<Test>, u64, u32, u64>>> = vec![
|
||||
Some(Scheduled {
|
||||
maybe_id: None,
|
||||
priority: i as u8 + 10,
|
||||
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }).into(),
|
||||
origin: 3u32,
|
||||
maybe_periodic: None,
|
||||
_phantom: Default::default(),
|
||||
}),
|
||||
None,
|
||||
Some(Scheduled {
|
||||
maybe_id: Some(b"test".to_vec()),
|
||||
priority: 123,
|
||||
origin: 2u32,
|
||||
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
|
||||
maybe_periodic: Some((456u64, 10)),
|
||||
_phantom: Default::default(),
|
||||
}),
|
||||
];
|
||||
frame_support::migration::put_storage_value(b"Scheduler", b"Agenda", &k, old);
|
||||
}
|
||||
|
||||
impl Into<OriginCaller> for u32 {
|
||||
fn into(self) -> OriginCaller {
|
||||
match self {
|
||||
3u32 => system::RawOrigin::Root.into(),
|
||||
2u32 => system::RawOrigin::None.into(),
|
||||
_ => unreachable!("test make no use of it"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Scheduler::migrate_origin::<u32>();
|
||||
|
||||
assert_eq_uvec!(
|
||||
Agenda::<Test>::iter().collect::<Vec<_>>(),
|
||||
vec![
|
||||
(
|
||||
0,
|
||||
vec![
|
||||
Some(ScheduledV2::<CallOrHashOf<Test>, u64, OriginCaller, u64> {
|
||||
maybe_id: None,
|
||||
priority: 10,
|
||||
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }).into(),
|
||||
maybe_periodic: None,
|
||||
origin: system::RawOrigin::Root.into(),
|
||||
_phantom: PhantomData::<u64>::default(),
|
||||
}),
|
||||
None,
|
||||
Some(ScheduledV2 {
|
||||
maybe_id: Some(b"test".to_vec()),
|
||||
priority: 123,
|
||||
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
|
||||
maybe_periodic: Some((456u64, 10)),
|
||||
origin: system::RawOrigin::None.into(),
|
||||
_phantom: PhantomData::<u64>::default(),
|
||||
}),
|
||||
]
|
||||
),
|
||||
(
|
||||
1,
|
||||
vec![
|
||||
Some(ScheduledV2 {
|
||||
maybe_id: None,
|
||||
priority: 11,
|
||||
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }).into(),
|
||||
maybe_periodic: None,
|
||||
origin: system::RawOrigin::Root.into(),
|
||||
_phantom: PhantomData::<u64>::default(),
|
||||
}),
|
||||
None,
|
||||
Some(ScheduledV2 {
|
||||
maybe_id: Some(b"test".to_vec()),
|
||||
priority: 123,
|
||||
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
|
||||
maybe_periodic: Some((456u64, 10)),
|
||||
origin: system::RawOrigin::None.into(),
|
||||
_phantom: PhantomData::<u64>::default(),
|
||||
}),
|
||||
]
|
||||
),
|
||||
(
|
||||
2,
|
||||
vec![
|
||||
Some(ScheduledV2 {
|
||||
maybe_id: None,
|
||||
priority: 12,
|
||||
call: Call::Logger(LoggerCall::log { i: 96, weight: 100 }).into(),
|
||||
maybe_periodic: None,
|
||||
origin: system::RawOrigin::Root.into(),
|
||||
_phantom: PhantomData::<u64>::default(),
|
||||
}),
|
||||
None,
|
||||
Some(ScheduledV2 {
|
||||
maybe_id: Some(b"test".to_vec()),
|
||||
priority: 123,
|
||||
call: Call::Logger(LoggerCall::log { i: 69, weight: 1000 }).into(),
|
||||
maybe_periodic: Some((456u64, 10)),
|
||||
origin: system::RawOrigin::None.into(),
|
||||
_phantom: PhantomData::<u64>::default(),
|
||||
}),
|
||||
]
|
||||
)
|
||||
]
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
//! Autogenerated weights for pallet_scheduler
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
|
||||
//! DATE: 2021-08-07, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! DATE: 2021-12-10, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128
|
||||
|
||||
// Executed Command:
|
||||
@@ -35,7 +35,6 @@
|
||||
// --output=./frame/scheduler/src/weights.rs
|
||||
// --template=./.maintain/frame-weight-template.hbs
|
||||
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
@@ -45,6 +44,16 @@ use sp_std::marker::PhantomData;
|
||||
|
||||
/// Weight functions needed for pallet_scheduler.
|
||||
pub trait WeightInfo {
|
||||
fn on_initialize_periodic_named_resolved(s: u32, ) -> Weight;
|
||||
fn on_initialize_named_resolved(s: u32, ) -> Weight;
|
||||
fn on_initialize_periodic_resolved(s: u32, ) -> Weight;
|
||||
fn on_initialize_resolved(s: u32, ) -> Weight;
|
||||
fn on_initialize_named_aborted(s: u32, ) -> Weight;
|
||||
fn on_initialize_aborted(s: u32, ) -> Weight;
|
||||
fn on_initialize_periodic_named(s: u32, ) -> Weight;
|
||||
fn on_initialize_periodic(s: u32, ) -> Weight;
|
||||
fn on_initialize_named(s: u32, ) -> Weight;
|
||||
fn on_initialize(s: u32, ) -> Weight;
|
||||
fn schedule(s: u32, ) -> Weight;
|
||||
fn cancel(s: u32, ) -> Weight;
|
||||
fn schedule_named(s: u32, ) -> Weight;
|
||||
@@ -54,38 +63,149 @@ pub trait WeightInfo {
|
||||
/// Weights for pallet_scheduler using the Substrate node and recommended hardware.
|
||||
pub struct SubstrateWeight<T>(PhantomData<T>);
|
||||
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: Scheduler Agenda (r:2 w:2)
|
||||
// Storage: Preimage PreimageFor (r:1 w:1)
|
||||
// Storage: Preimage StatusFor (r:1 w:1)
|
||||
// Storage: Scheduler Lookup (r:0 w:1)
|
||||
fn on_initialize_periodic_named_resolved(s: u32, ) -> Weight {
|
||||
(8_183_000 as Weight)
|
||||
// Standard Error: 36_000
|
||||
.saturating_add((34_670_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
// Storage: Preimage PreimageFor (r:1 w:1)
|
||||
// Storage: Preimage StatusFor (r:1 w:1)
|
||||
// Storage: Scheduler Lookup (r:0 w:1)
|
||||
fn on_initialize_named_resolved(s: u32, ) -> Weight {
|
||||
(11_520_000 as Weight)
|
||||
// Standard Error: 30_000
|
||||
.saturating_add((26_386_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:2 w:2)
|
||||
// Storage: Preimage PreimageFor (r:1 w:1)
|
||||
// Storage: Preimage StatusFor (r:1 w:1)
|
||||
fn on_initialize_periodic_resolved(s: u32, ) -> Weight {
|
||||
(8_222_000 as Weight)
|
||||
// Standard Error: 33_000
|
||||
.saturating_add((28_925_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
// Storage: Preimage PreimageFor (r:1 w:1)
|
||||
// Storage: Preimage StatusFor (r:1 w:1)
|
||||
fn on_initialize_resolved(s: u32, ) -> Weight {
|
||||
(11_610_000 as Weight)
|
||||
// Standard Error: 26_000
|
||||
.saturating_add((23_857_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:2 w:2)
|
||||
// Storage: Preimage PreimageFor (r:1 w:0)
|
||||
// Storage: Scheduler Lookup (r:0 w:1)
|
||||
fn on_initialize_named_aborted(s: u32, ) -> Weight {
|
||||
(11_067_000 as Weight)
|
||||
// Standard Error: 15_000
|
||||
.saturating_add((11_728_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:2 w:2)
|
||||
// Storage: Preimage PreimageFor (r:1 w:0)
|
||||
fn on_initialize_aborted(s: u32, ) -> Weight {
|
||||
(13_045_000 as Weight)
|
||||
// Standard Error: 5_000
|
||||
.saturating_add((6_378_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:2 w:2)
|
||||
// Storage: Scheduler Lookup (r:0 w:1)
|
||||
fn on_initialize_periodic_named(s: u32, ) -> Weight {
|
||||
(13_496_000 as Weight)
|
||||
// Standard Error: 27_000
|
||||
.saturating_add((17_932_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:2 w:2)
|
||||
fn on_initialize_periodic(s: u32, ) -> Weight {
|
||||
(17_074_000 as Weight)
|
||||
// Standard Error: 16_000
|
||||
.saturating_add((11_982_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
// Storage: Scheduler Lookup (r:0 w:1)
|
||||
fn on_initialize_named(s: u32, ) -> Weight {
|
||||
(18_730_000 as Weight)
|
||||
// Standard Error: 10_000
|
||||
.saturating_add((9_909_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
fn on_initialize(s: u32, ) -> Weight {
|
||||
(17_844_000 as Weight)
|
||||
// Standard Error: 9_000
|
||||
.saturating_add((7_719_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
fn schedule(s: u32, ) -> Weight {
|
||||
(24_730_000 as Weight)
|
||||
(23_361_000 as Weight)
|
||||
// Standard Error: 1_000
|
||||
.saturating_add((77_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add((82_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
// Storage: Scheduler Lookup (r:0 w:1)
|
||||
fn cancel(s: u32, ) -> Weight {
|
||||
(23_272_000 as Weight)
|
||||
// Standard Error: 4_000
|
||||
.saturating_add((1_261_000 as Weight).saturating_mul(s as Weight))
|
||||
(22_359_000 as Weight)
|
||||
// Standard Error: 2_000
|
||||
.saturating_add((1_219_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
// Storage: Scheduler Lookup (r:1 w:1)
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
fn schedule_named(s: u32, ) -> Weight {
|
||||
(30_971_000 as Weight)
|
||||
(28_499_000 as Weight)
|
||||
// Standard Error: 1_000
|
||||
.saturating_add((96_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add((98_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
// Storage: Scheduler Lookup (r:1 w:1)
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
fn cancel_named(s: u32, ) -> Weight {
|
||||
(25_778_000 as Weight)
|
||||
// Standard Error: 4_000
|
||||
.saturating_add((1_270_000 as Weight).saturating_mul(s as Weight))
|
||||
(24_995_000 as Weight)
|
||||
// Standard Error: 2_000
|
||||
.saturating_add((1_223_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
@@ -93,38 +213,149 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
|
||||
// For backwards compatibility and tests
|
||||
impl WeightInfo for () {
|
||||
// Storage: Scheduler Agenda (r:2 w:2)
|
||||
// Storage: Preimage PreimageFor (r:1 w:1)
|
||||
// Storage: Preimage StatusFor (r:1 w:1)
|
||||
// Storage: Scheduler Lookup (r:0 w:1)
|
||||
fn on_initialize_periodic_named_resolved(s: u32, ) -> Weight {
|
||||
(8_183_000 as Weight)
|
||||
// Standard Error: 36_000
|
||||
.saturating_add((34_670_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes((4 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
// Storage: Preimage PreimageFor (r:1 w:1)
|
||||
// Storage: Preimage StatusFor (r:1 w:1)
|
||||
// Storage: Scheduler Lookup (r:0 w:1)
|
||||
fn on_initialize_named_resolved(s: u32, ) -> Weight {
|
||||
(11_520_000 as Weight)
|
||||
// Standard Error: 30_000
|
||||
.saturating_add((26_386_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:2 w:2)
|
||||
// Storage: Preimage PreimageFor (r:1 w:1)
|
||||
// Storage: Preimage StatusFor (r:1 w:1)
|
||||
fn on_initialize_periodic_resolved(s: u32, ) -> Weight {
|
||||
(8_222_000 as Weight)
|
||||
// Standard Error: 33_000
|
||||
.saturating_add((28_925_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
// Storage: Preimage PreimageFor (r:1 w:1)
|
||||
// Storage: Preimage StatusFor (r:1 w:1)
|
||||
fn on_initialize_resolved(s: u32, ) -> Weight {
|
||||
(11_610_000 as Weight)
|
||||
// Standard Error: 26_000
|
||||
.saturating_add((23_857_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:2 w:2)
|
||||
// Storage: Preimage PreimageFor (r:1 w:0)
|
||||
// Storage: Scheduler Lookup (r:0 w:1)
|
||||
fn on_initialize_named_aborted(s: u32, ) -> Weight {
|
||||
(11_067_000 as Weight)
|
||||
// Standard Error: 15_000
|
||||
.saturating_add((11_728_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:2 w:2)
|
||||
// Storage: Preimage PreimageFor (r:1 w:0)
|
||||
fn on_initialize_aborted(s: u32, ) -> Weight {
|
||||
(13_045_000 as Weight)
|
||||
// Standard Error: 5_000
|
||||
.saturating_add((6_378_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:2 w:2)
|
||||
// Storage: Scheduler Lookup (r:0 w:1)
|
||||
fn on_initialize_periodic_named(s: u32, ) -> Weight {
|
||||
(13_496_000 as Weight)
|
||||
// Standard Error: 27_000
|
||||
.saturating_add((17_932_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:2 w:2)
|
||||
fn on_initialize_periodic(s: u32, ) -> Weight {
|
||||
(17_074_000 as Weight)
|
||||
// Standard Error: 16_000
|
||||
.saturating_add((11_982_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
// Storage: Scheduler Lookup (r:0 w:1)
|
||||
fn on_initialize_named(s: u32, ) -> Weight {
|
||||
(18_730_000 as Weight)
|
||||
// Standard Error: 10_000
|
||||
.saturating_add((9_909_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(s as Weight)))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
fn on_initialize(s: u32, ) -> Weight {
|
||||
(17_844_000 as Weight)
|
||||
// Standard Error: 9_000
|
||||
.saturating_add((7_719_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
fn schedule(s: u32, ) -> Weight {
|
||||
(24_730_000 as Weight)
|
||||
(23_361_000 as Weight)
|
||||
// Standard Error: 1_000
|
||||
.saturating_add((77_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add((82_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
// Storage: Scheduler Lookup (r:0 w:1)
|
||||
fn cancel(s: u32, ) -> Weight {
|
||||
(23_272_000 as Weight)
|
||||
// Standard Error: 4_000
|
||||
.saturating_add((1_261_000 as Weight).saturating_mul(s as Weight))
|
||||
(22_359_000 as Weight)
|
||||
// Standard Error: 2_000
|
||||
.saturating_add((1_219_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
// Storage: Scheduler Lookup (r:1 w:1)
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
fn schedule_named(s: u32, ) -> Weight {
|
||||
(30_971_000 as Weight)
|
||||
(28_499_000 as Weight)
|
||||
// Standard Error: 1_000
|
||||
.saturating_add((96_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add((98_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
// Storage: Scheduler Lookup (r:1 w:1)
|
||||
// Storage: Scheduler Agenda (r:1 w:1)
|
||||
fn cancel_named(s: u32, ) -> Weight {
|
||||
(25_778_000 as Weight)
|
||||
// Standard Error: 4_000
|
||||
.saturating_add((1_270_000 as Weight).saturating_mul(s as Weight))
|
||||
(24_995_000 as Weight)
|
||||
// Standard Error: 2_000
|
||||
.saturating_add((1_223_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user