mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Moves Block to frame_system instead of construct_runtime and removes Header and BlockNumber (#14437)
* Initial setup * Adds node block * Uses UncheckedExtrinsic and removes Where section * Updates frame_system to use Block * Adds deprecation warning * Fixes pallet-timestamp * Removes Header and BlockNumber * Addresses review comments * Addresses review comments * Adds comment about compiler bug * Removes where clause * Refactors code * Fixes errors in cargo check * Fixes errors in cargo check * Fixes warnings in cargo check * Formatting * Fixes construct_runtime tests * Uses import instead of full path for BlockNumber * Uses import instead of full path for Header * Formatting * Fixes construct_runtime tests * Fixes imports in benchmarks * Formatting * Fixes construct_runtime tests * Formatting * Minor updates * Fixes construct_runtime ui tests * Fixes construct_runtime ui tests with 1.70 * Fixes docs * Fixes docs * Adds u128 mock block type * Fixes split example * fixes for cumulus * ".git/.scripts/commands/fmt/fmt.sh" * Updates new tests * Fixes fully-qualified path in few places * Formatting * Update frame/examples/default-config/src/lib.rs Co-authored-by: Juan <juangirini@gmail.com> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Juan <juangirini@gmail.com> * ".git/.scripts/commands/fmt/fmt.sh" * Addresses some review comments * Fixes build * ".git/.scripts/commands/fmt/fmt.sh" * Update frame/democracy/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/democracy/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Addresses review comments * Updates trait bounds * Minor fix * ".git/.scripts/commands/fmt/fmt.sh" * Removes unnecessary bound * ".git/.scripts/commands/fmt/fmt.sh" * Updates test * Fixes build * Adds a bound for header * ".git/.scripts/commands/fmt/fmt.sh" * Removes where block * Minor fix * Minor fix * Fixes tests * ".git/.scripts/commands/update-ui/update-ui.sh" 1.70 * Updates test * Update primitives/runtime/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/runtime/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Updates doc * Updates doc --------- Co-authored-by: command-bot <> Co-authored-by: Juan <juangirini@gmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -23,7 +23,7 @@ use frame_support::{
|
||||
ensure,
|
||||
traits::{schedule::Priority, BoundedInline},
|
||||
};
|
||||
use frame_system::RawOrigin;
|
||||
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
|
||||
use sp_std::{prelude::*, vec};
|
||||
|
||||
use crate::Pallet as Scheduler;
|
||||
@@ -42,7 +42,10 @@ type SystemOrigin<T> = <T as frame_system::Config>::RuntimeOrigin;
|
||||
/// - `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) -> Result<(), &'static str> {
|
||||
fn fill_schedule<T: Config>(
|
||||
when: frame_system::pallet_prelude::BlockNumberFor<T>,
|
||||
n: u32,
|
||||
) -> Result<(), &'static str> {
|
||||
let t = DispatchTime::At(when);
|
||||
let origin: <T as Config>::PalletsOrigin = frame_system::RawOrigin::Root.into();
|
||||
for i in 0..n {
|
||||
@@ -125,7 +128,7 @@ fn make_origin<T: Config>(signed: bool) -> <T as Config>::PalletsOrigin {
|
||||
benchmarks! {
|
||||
// `service_agendas` when no work is done.
|
||||
service_agendas_base {
|
||||
let now = T::BlockNumber::from(BLOCK_NUMBER);
|
||||
let now = BlockNumberFor::<T>::from(BLOCK_NUMBER);
|
||||
IncompleteSince::<T>::put(now - One::one());
|
||||
}: {
|
||||
Scheduler::<T>::service_agendas(&mut WeightMeter::max_limit(), now, 0);
|
||||
@@ -224,7 +227,7 @@ benchmarks! {
|
||||
schedule {
|
||||
let s in 0 .. (T::MaxScheduledPerBlock::get() - 1);
|
||||
let when = BLOCK_NUMBER.into();
|
||||
let periodic = Some((T::BlockNumber::one(), 100));
|
||||
let periodic = Some((BlockNumberFor::<T>::one(), 100));
|
||||
let priority = 0;
|
||||
// Essentially a no-op call.
|
||||
let call = Box::new(SystemCall::set_storage { items: vec![] }.into());
|
||||
@@ -267,7 +270,7 @@ benchmarks! {
|
||||
let s in 0 .. (T::MaxScheduledPerBlock::get() - 1);
|
||||
let id = u32_to_name(s);
|
||||
let when = BLOCK_NUMBER.into();
|
||||
let periodic = Some((T::BlockNumber::one(), 100));
|
||||
let periodic = Some((BlockNumberFor::<T>::one(), 100));
|
||||
let priority = 0;
|
||||
// Essentially a no-op call.
|
||||
let call = Box::new(SystemCall::set_storage { items: vec![] }.into());
|
||||
|
||||
@@ -72,7 +72,10 @@ use frame_support::{
|
||||
},
|
||||
weights::{Weight, WeightMeter},
|
||||
};
|
||||
use frame_system::{self as system};
|
||||
use frame_system::{
|
||||
pallet_prelude::BlockNumberFor,
|
||||
{self as system},
|
||||
};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_io::hashing::blake2_256;
|
||||
use sp_runtime::{
|
||||
@@ -123,7 +126,7 @@ use crate::{Scheduled as ScheduledV3, Scheduled as ScheduledV2};
|
||||
pub type ScheduledV2Of<T> = ScheduledV2<
|
||||
Vec<u8>,
|
||||
<T as Config>::RuntimeCall,
|
||||
<T as frame_system::Config>::BlockNumber,
|
||||
BlockNumberFor<T>,
|
||||
<T as Config>::PalletsOrigin,
|
||||
<T as frame_system::Config>::AccountId,
|
||||
>;
|
||||
@@ -131,7 +134,7 @@ pub type ScheduledV2Of<T> = ScheduledV2<
|
||||
pub type ScheduledV3Of<T> = ScheduledV3<
|
||||
Vec<u8>,
|
||||
CallOrHashOf<T>,
|
||||
<T as frame_system::Config>::BlockNumber,
|
||||
BlockNumberFor<T>,
|
||||
<T as Config>::PalletsOrigin,
|
||||
<T as frame_system::Config>::AccountId,
|
||||
>;
|
||||
@@ -139,7 +142,7 @@ pub type ScheduledV3Of<T> = ScheduledV3<
|
||||
pub type ScheduledOf<T> = Scheduled<
|
||||
TaskName,
|
||||
Bounded<<T as Config>::RuntimeCall>,
|
||||
<T as frame_system::Config>::BlockNumber,
|
||||
BlockNumberFor<T>,
|
||||
<T as Config>::PalletsOrigin,
|
||||
<T as frame_system::Config>::AccountId,
|
||||
>;
|
||||
@@ -231,14 +234,14 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
#[pallet::storage]
|
||||
pub type IncompleteSince<T: Config> = StorageValue<_, T::BlockNumber>;
|
||||
pub type IncompleteSince<T: Config> = StorageValue<_, BlockNumberFor<T>>;
|
||||
|
||||
/// Items to be executed, indexed by the block number that they should be executed on.
|
||||
#[pallet::storage]
|
||||
pub type Agenda<T: Config> = StorageMap<
|
||||
_,
|
||||
Twox64Concat,
|
||||
T::BlockNumber,
|
||||
BlockNumberFor<T>,
|
||||
BoundedVec<Option<ScheduledOf<T>>, T::MaxScheduledPerBlock>,
|
||||
ValueQuery,
|
||||
>;
|
||||
@@ -249,28 +252,28 @@ pub mod pallet {
|
||||
/// identities.
|
||||
#[pallet::storage]
|
||||
pub(crate) type Lookup<T: Config> =
|
||||
StorageMap<_, Twox64Concat, TaskName, TaskAddress<T::BlockNumber>>;
|
||||
StorageMap<_, Twox64Concat, TaskName, TaskAddress<BlockNumberFor<T>>>;
|
||||
|
||||
/// Events type.
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
/// Scheduled some task.
|
||||
Scheduled { when: T::BlockNumber, index: u32 },
|
||||
Scheduled { when: BlockNumberFor<T>, index: u32 },
|
||||
/// Canceled some task.
|
||||
Canceled { when: T::BlockNumber, index: u32 },
|
||||
Canceled { when: BlockNumberFor<T>, index: u32 },
|
||||
/// Dispatched some task.
|
||||
Dispatched {
|
||||
task: TaskAddress<T::BlockNumber>,
|
||||
task: TaskAddress<BlockNumberFor<T>>,
|
||||
id: Option<TaskName>,
|
||||
result: DispatchResult,
|
||||
},
|
||||
/// The call for the provided hash was not found so the task has been aborted.
|
||||
CallUnavailable { task: TaskAddress<T::BlockNumber>, id: Option<TaskName> },
|
||||
CallUnavailable { task: TaskAddress<BlockNumberFor<T>>, id: Option<TaskName> },
|
||||
/// The given task was unable to be renewed since the agenda is full at that block.
|
||||
PeriodicFailed { task: TaskAddress<T::BlockNumber>, id: Option<TaskName> },
|
||||
PeriodicFailed { task: TaskAddress<BlockNumberFor<T>>, id: Option<TaskName> },
|
||||
/// The given task can never be executed since it is overweight.
|
||||
PermanentlyOverweight { task: TaskAddress<T::BlockNumber>, id: Option<TaskName> },
|
||||
PermanentlyOverweight { task: TaskAddress<BlockNumberFor<T>>, id: Option<TaskName> },
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
@@ -290,7 +293,7 @@ pub mod pallet {
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
/// Execute the scheduled calls
|
||||
fn on_initialize(now: T::BlockNumber) -> Weight {
|
||||
fn on_initialize(now: BlockNumberFor<T>) -> Weight {
|
||||
let mut weight_counter = WeightMeter::from_limit(T::MaximumWeight::get());
|
||||
Self::service_agendas(&mut weight_counter, now, u32::max_value());
|
||||
weight_counter.consumed
|
||||
@@ -304,8 +307,8 @@ pub mod pallet {
|
||||
#[pallet::weight(<T as Config>::WeightInfo::schedule(T::MaxScheduledPerBlock::get()))]
|
||||
pub fn schedule(
|
||||
origin: OriginFor<T>,
|
||||
when: T::BlockNumber,
|
||||
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
|
||||
when: BlockNumberFor<T>,
|
||||
maybe_periodic: Option<schedule::Period<BlockNumberFor<T>>>,
|
||||
priority: schedule::Priority,
|
||||
call: Box<<T as Config>::RuntimeCall>,
|
||||
) -> DispatchResult {
|
||||
@@ -324,7 +327,7 @@ pub mod pallet {
|
||||
/// Cancel an anonymously scheduled task.
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight(<T as Config>::WeightInfo::cancel(T::MaxScheduledPerBlock::get()))]
|
||||
pub fn cancel(origin: OriginFor<T>, when: T::BlockNumber, index: u32) -> DispatchResult {
|
||||
pub fn cancel(origin: OriginFor<T>, when: BlockNumberFor<T>, index: u32) -> DispatchResult {
|
||||
T::ScheduleOrigin::ensure_origin(origin.clone())?;
|
||||
let origin = <T as Config>::RuntimeOrigin::from(origin);
|
||||
Self::do_cancel(Some(origin.caller().clone()), (when, index))?;
|
||||
@@ -337,8 +340,8 @@ pub mod pallet {
|
||||
pub fn schedule_named(
|
||||
origin: OriginFor<T>,
|
||||
id: TaskName,
|
||||
when: T::BlockNumber,
|
||||
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
|
||||
when: BlockNumberFor<T>,
|
||||
maybe_periodic: Option<schedule::Period<BlockNumberFor<T>>>,
|
||||
priority: schedule::Priority,
|
||||
call: Box<<T as Config>::RuntimeCall>,
|
||||
) -> DispatchResult {
|
||||
@@ -370,8 +373,8 @@ pub mod pallet {
|
||||
#[pallet::weight(<T as Config>::WeightInfo::schedule(T::MaxScheduledPerBlock::get()))]
|
||||
pub fn schedule_after(
|
||||
origin: OriginFor<T>,
|
||||
after: T::BlockNumber,
|
||||
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
|
||||
after: BlockNumberFor<T>,
|
||||
maybe_periodic: Option<schedule::Period<BlockNumberFor<T>>>,
|
||||
priority: schedule::Priority,
|
||||
call: Box<<T as Config>::RuntimeCall>,
|
||||
) -> DispatchResult {
|
||||
@@ -393,8 +396,8 @@ pub mod pallet {
|
||||
pub fn schedule_named_after(
|
||||
origin: OriginFor<T>,
|
||||
id: TaskName,
|
||||
after: T::BlockNumber,
|
||||
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
|
||||
after: BlockNumberFor<T>,
|
||||
maybe_periodic: Option<schedule::Period<BlockNumberFor<T>>>,
|
||||
priority: schedule::Priority,
|
||||
call: Box<<T as Config>::RuntimeCall>,
|
||||
) -> DispatchResult {
|
||||
@@ -434,7 +437,7 @@ impl<T: Config<Hash = PreimageHash>> Pallet<T> {
|
||||
}
|
||||
|
||||
Agenda::<T>::translate::<
|
||||
Vec<Option<ScheduledV1<<T as Config>::RuntimeCall, T::BlockNumber>>>,
|
||||
Vec<Option<ScheduledV1<<T as Config>::RuntimeCall, BlockNumberFor<T>>>>,
|
||||
_,
|
||||
>(|_, agenda| {
|
||||
Some(BoundedVec::truncate_from(
|
||||
@@ -669,7 +672,7 @@ impl<T: Config> Pallet<T> {
|
||||
Scheduled<
|
||||
TaskName,
|
||||
Bounded<<T as Config>::RuntimeCall>,
|
||||
T::BlockNumber,
|
||||
BlockNumberFor<T>,
|
||||
OldOrigin,
|
||||
T::AccountId,
|
||||
>,
|
||||
@@ -695,7 +698,9 @@ impl<T: Config> Pallet<T> {
|
||||
});
|
||||
}
|
||||
|
||||
fn resolve_time(when: DispatchTime<T::BlockNumber>) -> Result<T::BlockNumber, DispatchError> {
|
||||
fn resolve_time(
|
||||
when: DispatchTime<BlockNumberFor<T>>,
|
||||
) -> Result<BlockNumberFor<T>, DispatchError> {
|
||||
let now = frame_system::Pallet::<T>::block_number();
|
||||
|
||||
let when = match when {
|
||||
@@ -713,9 +718,9 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
fn place_task(
|
||||
when: T::BlockNumber,
|
||||
when: BlockNumberFor<T>,
|
||||
what: ScheduledOf<T>,
|
||||
) -> Result<TaskAddress<T::BlockNumber>, (DispatchError, ScheduledOf<T>)> {
|
||||
) -> Result<TaskAddress<BlockNumberFor<T>>, (DispatchError, ScheduledOf<T>)> {
|
||||
let maybe_name = what.maybe_id;
|
||||
let index = Self::push_to_agenda(when, what)?;
|
||||
let address = (when, index);
|
||||
@@ -727,7 +732,7 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
fn push_to_agenda(
|
||||
when: T::BlockNumber,
|
||||
when: BlockNumberFor<T>,
|
||||
what: ScheduledOf<T>,
|
||||
) -> Result<u32, (DispatchError, ScheduledOf<T>)> {
|
||||
let mut agenda = Agenda::<T>::get(when);
|
||||
@@ -749,7 +754,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Remove trailing `None` items of an agenda at `when`. If all items are `None` remove the
|
||||
/// agenda record entirely.
|
||||
fn cleanup_agenda(when: T::BlockNumber) {
|
||||
fn cleanup_agenda(when: BlockNumberFor<T>) {
|
||||
let mut agenda = Agenda::<T>::get(when);
|
||||
match agenda.iter().rposition(|i| i.is_some()) {
|
||||
Some(i) if agenda.len() > i + 1 => {
|
||||
@@ -764,12 +769,12 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
fn do_schedule(
|
||||
when: DispatchTime<T::BlockNumber>,
|
||||
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
|
||||
when: DispatchTime<BlockNumberFor<T>>,
|
||||
maybe_periodic: Option<schedule::Period<BlockNumberFor<T>>>,
|
||||
priority: schedule::Priority,
|
||||
origin: T::PalletsOrigin,
|
||||
call: Bounded<<T as Config>::RuntimeCall>,
|
||||
) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {
|
||||
) -> Result<TaskAddress<BlockNumberFor<T>>, DispatchError> {
|
||||
let when = Self::resolve_time(when)?;
|
||||
|
||||
let lookup_hash = call.lookup_hash();
|
||||
@@ -799,7 +804,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
fn do_cancel(
|
||||
origin: Option<T::PalletsOrigin>,
|
||||
(when, index): TaskAddress<T::BlockNumber>,
|
||||
(when, index): TaskAddress<BlockNumberFor<T>>,
|
||||
) -> Result<(), DispatchError> {
|
||||
let scheduled = Agenda::<T>::try_mutate(when, |agenda| {
|
||||
agenda.get_mut(index as usize).map_or(
|
||||
@@ -831,9 +836,9 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
fn do_reschedule(
|
||||
(when, index): TaskAddress<T::BlockNumber>,
|
||||
new_time: DispatchTime<T::BlockNumber>,
|
||||
) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {
|
||||
(when, index): TaskAddress<BlockNumberFor<T>>,
|
||||
new_time: DispatchTime<BlockNumberFor<T>>,
|
||||
) -> Result<TaskAddress<BlockNumberFor<T>>, DispatchError> {
|
||||
let new_time = Self::resolve_time(new_time)?;
|
||||
|
||||
if new_time == when {
|
||||
@@ -853,12 +858,12 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
fn do_schedule_named(
|
||||
id: TaskName,
|
||||
when: DispatchTime<T::BlockNumber>,
|
||||
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
|
||||
when: DispatchTime<BlockNumberFor<T>>,
|
||||
maybe_periodic: Option<schedule::Period<BlockNumberFor<T>>>,
|
||||
priority: schedule::Priority,
|
||||
origin: T::PalletsOrigin,
|
||||
call: Bounded<<T as Config>::RuntimeCall>,
|
||||
) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {
|
||||
) -> Result<TaskAddress<BlockNumberFor<T>>, DispatchError> {
|
||||
// ensure id it is unique
|
||||
if Lookup::<T>::contains_key(&id) {
|
||||
return Err(Error::<T>::FailedToSchedule.into())
|
||||
@@ -922,8 +927,8 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
fn do_reschedule_named(
|
||||
id: TaskName,
|
||||
new_time: DispatchTime<T::BlockNumber>,
|
||||
) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {
|
||||
new_time: DispatchTime<BlockNumberFor<T>>,
|
||||
) -> Result<TaskAddress<BlockNumberFor<T>>, DispatchError> {
|
||||
let new_time = Self::resolve_time(new_time)?;
|
||||
|
||||
let lookup = Lookup::<T>::get(id);
|
||||
@@ -953,7 +958,7 @@ use ServiceTaskError::*;
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Service up to `max` agendas queue starting from earliest incompletely executed agenda.
|
||||
fn service_agendas(weight: &mut WeightMeter, now: T::BlockNumber, max: u32) {
|
||||
fn service_agendas(weight: &mut WeightMeter, now: BlockNumberFor<T>, max: u32) {
|
||||
if !weight.check_accrue(T::WeightInfo::service_agendas_base()) {
|
||||
return
|
||||
}
|
||||
@@ -983,8 +988,8 @@ impl<T: Config> Pallet<T> {
|
||||
fn service_agenda(
|
||||
weight: &mut WeightMeter,
|
||||
executed: &mut u32,
|
||||
now: T::BlockNumber,
|
||||
when: T::BlockNumber,
|
||||
now: BlockNumberFor<T>,
|
||||
when: BlockNumberFor<T>,
|
||||
max: u32,
|
||||
) -> bool {
|
||||
let mut agenda = Agenda::<T>::get(when);
|
||||
@@ -1052,8 +1057,8 @@ impl<T: Config> Pallet<T> {
|
||||
/// - Rescheduling the task for execution in a later agenda if periodic.
|
||||
fn service_task(
|
||||
weight: &mut WeightMeter,
|
||||
now: T::BlockNumber,
|
||||
when: T::BlockNumber,
|
||||
now: BlockNumberFor<T>,
|
||||
when: BlockNumberFor<T>,
|
||||
agenda_index: u32,
|
||||
is_first: bool,
|
||||
mut task: ScheduledOf<T>,
|
||||
@@ -1161,14 +1166,14 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
impl<T: Config<Hash = PreimageHash>>
|
||||
schedule::v2::Anon<T::BlockNumber, <T as Config>::RuntimeCall, T::PalletsOrigin> for Pallet<T>
|
||||
schedule::v2::Anon<BlockNumberFor<T>, <T as Config>::RuntimeCall, T::PalletsOrigin> for Pallet<T>
|
||||
{
|
||||
type Address = TaskAddress<T::BlockNumber>;
|
||||
type Address = TaskAddress<BlockNumberFor<T>>;
|
||||
type Hash = T::Hash;
|
||||
|
||||
fn schedule(
|
||||
when: DispatchTime<T::BlockNumber>,
|
||||
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
|
||||
when: DispatchTime<BlockNumberFor<T>>,
|
||||
maybe_periodic: Option<schedule::Period<BlockNumberFor<T>>>,
|
||||
priority: schedule::Priority,
|
||||
origin: T::PalletsOrigin,
|
||||
call: CallOrHashOf<T>,
|
||||
@@ -1184,26 +1189,26 @@ impl<T: Config<Hash = PreimageHash>>
|
||||
|
||||
fn reschedule(
|
||||
address: Self::Address,
|
||||
when: DispatchTime<T::BlockNumber>,
|
||||
when: DispatchTime<BlockNumberFor<T>>,
|
||||
) -> Result<Self::Address, DispatchError> {
|
||||
Self::do_reschedule(address, when)
|
||||
}
|
||||
|
||||
fn next_dispatch_time((when, index): Self::Address) -> Result<T::BlockNumber, ()> {
|
||||
fn next_dispatch_time((when, index): Self::Address) -> Result<BlockNumberFor<T>, ()> {
|
||||
Agenda::<T>::get(when).get(index as usize).ok_or(()).map(|_| when)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<Hash = PreimageHash>>
|
||||
schedule::v2::Named<T::BlockNumber, <T as Config>::RuntimeCall, T::PalletsOrigin> for Pallet<T>
|
||||
schedule::v2::Named<BlockNumberFor<T>, <T as Config>::RuntimeCall, T::PalletsOrigin> for Pallet<T>
|
||||
{
|
||||
type Address = TaskAddress<T::BlockNumber>;
|
||||
type Address = TaskAddress<BlockNumberFor<T>>;
|
||||
type Hash = T::Hash;
|
||||
|
||||
fn schedule_named(
|
||||
id: Vec<u8>,
|
||||
when: DispatchTime<T::BlockNumber>,
|
||||
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
|
||||
when: DispatchTime<BlockNumberFor<T>>,
|
||||
maybe_periodic: Option<schedule::Period<BlockNumberFor<T>>>,
|
||||
priority: schedule::Priority,
|
||||
origin: T::PalletsOrigin,
|
||||
call: CallOrHashOf<T>,
|
||||
@@ -1221,13 +1226,13 @@ impl<T: Config<Hash = PreimageHash>>
|
||||
|
||||
fn reschedule_named(
|
||||
id: Vec<u8>,
|
||||
when: DispatchTime<T::BlockNumber>,
|
||||
when: DispatchTime<BlockNumberFor<T>>,
|
||||
) -> Result<Self::Address, DispatchError> {
|
||||
let name = blake2_256(&id[..]);
|
||||
Self::do_reschedule_named(name, when)
|
||||
}
|
||||
|
||||
fn next_dispatch_time(id: Vec<u8>) -> Result<T::BlockNumber, ()> {
|
||||
fn next_dispatch_time(id: Vec<u8>) -> Result<BlockNumberFor<T>, ()> {
|
||||
let name = blake2_256(&id[..]);
|
||||
Lookup::<T>::get(name)
|
||||
.and_then(|(when, index)| Agenda::<T>::get(when).get(index as usize).map(|_| when))
|
||||
@@ -1235,14 +1240,14 @@ impl<T: Config<Hash = PreimageHash>>
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> schedule::v3::Anon<T::BlockNumber, <T as Config>::RuntimeCall, T::PalletsOrigin>
|
||||
impl<T: Config> schedule::v3::Anon<BlockNumberFor<T>, <T as Config>::RuntimeCall, T::PalletsOrigin>
|
||||
for Pallet<T>
|
||||
{
|
||||
type Address = TaskAddress<T::BlockNumber>;
|
||||
type Address = TaskAddress<BlockNumberFor<T>>;
|
||||
|
||||
fn schedule(
|
||||
when: DispatchTime<T::BlockNumber>,
|
||||
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
|
||||
when: DispatchTime<BlockNumberFor<T>>,
|
||||
maybe_periodic: Option<schedule::Period<BlockNumberFor<T>>>,
|
||||
priority: schedule::Priority,
|
||||
origin: T::PalletsOrigin,
|
||||
call: Bounded<<T as Config>::RuntimeCall>,
|
||||
@@ -1256,12 +1261,14 @@ impl<T: Config> schedule::v3::Anon<T::BlockNumber, <T as Config>::RuntimeCall, T
|
||||
|
||||
fn reschedule(
|
||||
address: Self::Address,
|
||||
when: DispatchTime<T::BlockNumber>,
|
||||
when: DispatchTime<BlockNumberFor<T>>,
|
||||
) -> Result<Self::Address, DispatchError> {
|
||||
Self::do_reschedule(address, when).map_err(map_err_to_v3_err::<T>)
|
||||
}
|
||||
|
||||
fn next_dispatch_time((when, index): Self::Address) -> Result<T::BlockNumber, DispatchError> {
|
||||
fn next_dispatch_time(
|
||||
(when, index): Self::Address,
|
||||
) -> Result<BlockNumberFor<T>, DispatchError> {
|
||||
Agenda::<T>::get(when)
|
||||
.get(index as usize)
|
||||
.ok_or(DispatchError::Unavailable)
|
||||
@@ -1271,15 +1278,15 @@ impl<T: Config> schedule::v3::Anon<T::BlockNumber, <T as Config>::RuntimeCall, T
|
||||
|
||||
use schedule::v3::TaskName;
|
||||
|
||||
impl<T: Config> schedule::v3::Named<T::BlockNumber, <T as Config>::RuntimeCall, T::PalletsOrigin>
|
||||
impl<T: Config> schedule::v3::Named<BlockNumberFor<T>, <T as Config>::RuntimeCall, T::PalletsOrigin>
|
||||
for Pallet<T>
|
||||
{
|
||||
type Address = TaskAddress<T::BlockNumber>;
|
||||
type Address = TaskAddress<BlockNumberFor<T>>;
|
||||
|
||||
fn schedule_named(
|
||||
id: TaskName,
|
||||
when: DispatchTime<T::BlockNumber>,
|
||||
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
|
||||
when: DispatchTime<BlockNumberFor<T>>,
|
||||
maybe_periodic: Option<schedule::Period<BlockNumberFor<T>>>,
|
||||
priority: schedule::Priority,
|
||||
origin: T::PalletsOrigin,
|
||||
call: Bounded<<T as Config>::RuntimeCall>,
|
||||
@@ -1293,12 +1300,12 @@ impl<T: Config> schedule::v3::Named<T::BlockNumber, <T as Config>::RuntimeCall,
|
||||
|
||||
fn reschedule_named(
|
||||
id: TaskName,
|
||||
when: DispatchTime<T::BlockNumber>,
|
||||
when: DispatchTime<BlockNumberFor<T>>,
|
||||
) -> Result<Self::Address, DispatchError> {
|
||||
Self::do_reschedule_named(id, when).map_err(map_err_to_v3_err::<T>)
|
||||
}
|
||||
|
||||
fn next_dispatch_time(id: TaskName) -> Result<T::BlockNumber, DispatchError> {
|
||||
fn next_dispatch_time(id: TaskName) -> Result<BlockNumberFor<T>, DispatchError> {
|
||||
Lookup::<T>::get(id)
|
||||
.and_then(|(when, index)| Agenda::<T>::get(when).get(index as usize).map(|_| when))
|
||||
.ok_or(DispatchError::Unavailable)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
use super::*;
|
||||
use frame_support::traits::OnRuntimeUpgrade;
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
use sp_runtime::TryRuntimeError;
|
||||
@@ -34,22 +35,14 @@ pub mod v1 {
|
||||
pub(crate) type Agenda<T: Config> = StorageMap<
|
||||
Pallet<T>,
|
||||
Twox64Concat,
|
||||
<T as frame_system::Config>::BlockNumber,
|
||||
Vec<
|
||||
Option<
|
||||
ScheduledV1<<T as Config>::RuntimeCall, <T as frame_system::Config>::BlockNumber>,
|
||||
>,
|
||||
>,
|
||||
BlockNumberFor<T>,
|
||||
Vec<Option<ScheduledV1<<T as Config>::RuntimeCall, BlockNumberFor<T>>>>,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
#[frame_support::storage_alias]
|
||||
pub(crate) type Lookup<T: Config> = StorageMap<
|
||||
Pallet<T>,
|
||||
Twox64Concat,
|
||||
Vec<u8>,
|
||||
TaskAddress<<T as frame_system::Config>::BlockNumber>,
|
||||
>;
|
||||
pub(crate) type Lookup<T: Config> =
|
||||
StorageMap<Pallet<T>, Twox64Concat, Vec<u8>, TaskAddress<BlockNumberFor<T>>>;
|
||||
}
|
||||
|
||||
pub mod v2 {
|
||||
@@ -60,18 +53,14 @@ pub mod v2 {
|
||||
pub(crate) type Agenda<T: Config> = StorageMap<
|
||||
Pallet<T>,
|
||||
Twox64Concat,
|
||||
<T as frame_system::Config>::BlockNumber,
|
||||
BlockNumberFor<T>,
|
||||
Vec<Option<ScheduledV2Of<T>>>,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
#[frame_support::storage_alias]
|
||||
pub(crate) type Lookup<T: Config> = StorageMap<
|
||||
Pallet<T>,
|
||||
Twox64Concat,
|
||||
Vec<u8>,
|
||||
TaskAddress<<T as frame_system::Config>::BlockNumber>,
|
||||
>;
|
||||
pub(crate) type Lookup<T: Config> =
|
||||
StorageMap<Pallet<T>, Twox64Concat, Vec<u8>, TaskAddress<BlockNumberFor<T>>>;
|
||||
}
|
||||
|
||||
pub mod v3 {
|
||||
@@ -82,18 +71,14 @@ pub mod v3 {
|
||||
pub(crate) type Agenda<T: Config> = StorageMap<
|
||||
Pallet<T>,
|
||||
Twox64Concat,
|
||||
<T as frame_system::Config>::BlockNumber,
|
||||
BlockNumberFor<T>,
|
||||
Vec<Option<ScheduledV3Of<T>>>,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
#[frame_support::storage_alias]
|
||||
pub(crate) type Lookup<T: Config> = StorageMap<
|
||||
Pallet<T>,
|
||||
Twox64Concat,
|
||||
Vec<u8>,
|
||||
TaskAddress<<T as frame_system::Config>::BlockNumber>,
|
||||
>;
|
||||
pub(crate) type Lookup<T: Config> =
|
||||
StorageMap<Pallet<T>, Twox64Concat, Vec<u8>, TaskAddress<BlockNumberFor<T>>>;
|
||||
|
||||
/// Migrate the scheduler pallet from V3 to V4.
|
||||
pub struct MigrateToV4<T>(sp_std::marker::PhantomData<T>);
|
||||
|
||||
@@ -30,7 +30,6 @@ use frame_support::{
|
||||
use frame_system::{EnsureRoot, EnsureSignedBy};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
BuildStorage, Perbill,
|
||||
};
|
||||
@@ -93,14 +92,10 @@ pub mod logger {
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
pub enum Test
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
|
||||
Logger: logger::{Pallet, Call, Event<T>},
|
||||
@@ -131,12 +126,11 @@ impl system::Config for Test {
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Header = Header;
|
||||
type Block = Block;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type BlockHashCount = ConstU64<250>;
|
||||
type Version = ();
|
||||
|
||||
Reference in New Issue
Block a user