Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6d11c9d
allow specify schedule dispatch origin
xlc Jun 18, 2020
8aa6ed9
fix tests
xlc Jun 19, 2020
a572232
use caller origin for scheduled
xlc Jun 19, 2020
8eba0a4
fix tests
xlc Jun 19, 2020
d51269a
line width
xlc Jun 19, 2020
5f1ee49
check origin for cancel
xlc Jun 19, 2020
fb5b48d
line width
xlc Jun 19, 2020
b7c9cba
fix some issues for benchmarking
xlc Jun 19, 2020
b2e1067
fix doc test
xlc Jun 19, 2020
f61230b
another way to constraint origin
xlc Jun 20, 2020
061d78f
Merge remote-tracking branch 'origin/master' into update-scheduler
xlc Jun 20, 2020
f43f468
fix build issues
xlc Jun 21, 2020
14b7522
fix cancel
xlc Jun 21, 2020
2c4a7d2
line width
xlc Jun 21, 2020
bc166a7
fix benchmarks
xlc Jun 21, 2020
9fc1fc0
bump version
xlc Jun 21, 2020
97cbaf3
enable runtime upgrade
xlc Jun 22, 2020
9dc582a
add migration code and test
xlc Jun 23, 2020
dd97a5a
Merge remote-tracking branch 'origin/master' into update-scheduler
xlc Jun 23, 2020
ae0231a
Update frame/scheduler/src/lib.rs
xlc Jun 23, 2020
c3f9e55
expose migration method
xlc Jun 23, 2020
5f00a81
Merge remote-tracking branch 'origin/master' into update-scheduler
xlc Jun 23, 2020
39040bc
add notes
xlc Jun 23, 2020
79cde79
Merge remote-tracking branch 'origin/master' into update-scheduler
xlc Jun 24, 2020
4099003
Merge remote-tracking branch 'origin/master' into update-scheduler
xlc Jun 25, 2020
b9000e8
Merge remote-tracking branch 'origin/master' into update-scheduler
xlc Jun 27, 2020
5b65287
bump version
xlc Jun 27, 2020
f19c49f
remove on_runtime_upgrade
xlc Jun 27, 2020
40e99bc
fix test
xlc Jun 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
enable runtime upgrade
  • Loading branch information
xlc committed Jun 22, 2020
commit 97cbaf37e40b33b3d084793cd7b008f20602f913
74 changes: 53 additions & 21 deletions frame/scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use sp_std::{prelude::*, marker::PhantomData, borrow::Borrow};
use codec::{Encode, Decode, Codec};
use sp_runtime::{RuntimeDebug, traits::{Zero, One, BadOrigin}};
use frame_support::{
decl_module, decl_storage, decl_event, decl_error,
decl_module, decl_storage, decl_event, decl_error, IterableStorageMap,
dispatch::{Dispatchable, DispatchError, DispatchResult, Parameter},
traits::{Get, schedule, OriginTrait, EnsureOrigin, IsType},
weights::{GetDispatchInfo, Weight},
Expand Down Expand Up @@ -88,9 +88,17 @@ pub type PeriodicIndex = u32;
/// The location of a scheduled task that can be used to remove it.
pub type TaskAddress<BlockNumber> = (BlockNumber, u32);

#[derive(Clone, RuntimeDebug, Encode, Decode)]
struct ScheduledLegacy<Call, BlockNumber> {
maybe_id: Option<Vec<u8>>,
priority: schedule::Priority,
call: Call,
maybe_periodic: Option<schedule::Period<BlockNumber>>,
}

/// Information regarding an item to be executed in the future.
#[derive(Clone, RuntimeDebug, Encode)]
pub struct Scheduled<Call, BlockNumber, PalletsOrigin, AccountId> {
#[derive(Clone, RuntimeDebug, Encode, Decode)]
pub struct ScheduledV1<Call, BlockNumber, PalletsOrigin, AccountId> {
/// The unique identity for this task, if there is one.
maybe_id: Option<Vec<u8>>,
/// This task's priority.
Expand All @@ -104,24 +112,15 @@ pub struct Scheduled<Call, BlockNumber, PalletsOrigin, AccountId> {
_phantom: PhantomData<AccountId>,
}

impl<Call, BlockNumber, PalletsOrigin, AccountId> Decode for Scheduled<Call, BlockNumber, PalletsOrigin, AccountId>
where
Call: Decode,
BlockNumber: Decode,
PalletsOrigin: Decode + From<system::RawOrigin<AccountId>>
{
fn decode<I: codec::Input>(input: &mut I) -> sp_std::result::Result<Self, codec::Error> {
// Implement decode manually to keep backwards compatibility.
// Old version does not have origin field and default to ROOT.
Ok(Scheduled {
maybe_id: Decode::decode(input)?,
priority: Decode::decode(input)?,
call: Decode::decode(input)?,
maybe_periodic: Decode::decode(input)?,
origin: Decode::decode(input).unwrap_or_else(|_| system::RawOrigin::Root.into()),
_phantom: Default::default(),
})
}
/// The current version of Scheduled struct.
pub type Scheduled<Call, BlockNumber, PalletsOrigin, AccountId> = ScheduledV1<Call, BlockNumber, PalletsOrigin, AccountId>;

// A value placed in storage that represents the current version of the Scheduler storage.
// This value is used by the `on_runtime_upgrade` logic to determine whether we run
// storage migration logic.
#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug)]
enum Releases {
V1,
}

decl_storage! {
Expand All @@ -132,6 +131,11 @@ decl_storage! {

/// Lookup from identity to the block number and index of the task.
Lookup: map hasher(twox_64_concat) Vec<u8> => Option<TaskAddress<T::BlockNumber>>;

/// Storage version of the pallet.
///
/// New networks start with last version.
StorageVersion build(|_| Some(Releases::V1)): Option<Releases>;
}
}

Expand All @@ -158,6 +162,34 @@ decl_module! {
type Error = Error<T>;
fn deposit_event() = default;

fn on_runtime_upgrade() -> Weight {
if let None = StorageVersion::get() {
StorageVersion::put(Releases::V1);

Agenda::<T>::translate::<
Vec<Option<ScheduledLegacy<<T as Trait>::Call, T::BlockNumber>>>, _
>(|_, agenda| {
Some(
agenda
.into_iter()
.map(|schedule| schedule.map(|schedule| ScheduledV1 {
maybe_id: schedule.maybe_id,
priority: schedule.priority,
call: schedule.call,
maybe_periodic: schedule.maybe_periodic,
origin: system::RawOrigin::Root.into(),
_phantom: Default::default(),
}))
.collect::<Vec<_>>()
)
});

T::MaximumBlockWeight::get()
} else {
T::DbWeight::get().reads(1)
}
}

/// Anonymously schedule a task.
///
/// # <weight>
Expand Down