Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
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
another way to constraint origin
  • Loading branch information
xlc committed Jun 20, 2020
commit f61230bebe9b4a53d42b7cc9cccf21d7e980a23a
5 changes: 1 addition & 4 deletions frame/scheduler/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ use frame_system::Module as System;
const MAX_SCHEDULED: u32 = 50;

// Add `n` named items to the schedule
fn fill_schedule<T: Trait> (when: T::BlockNumber, n: u32) -> Result<(), &'static str>
where
<T as system::Trait>::Origin: OriginTrait<PalletsOrigin = T::PalletsOrigin>
{
fn fill_schedule<T: Trait> (when: T::BlockNumber, n: u32) -> Result<(), &'static str> {
// Essentially a no-op call.
let call = frame_system::Call::set_storage(vec![]);
for i in 0..n {
Expand Down
33 changes: 10 additions & 23 deletions frame/scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use sp_runtime::{RuntimeDebug, traits::{Zero, One}};
use frame_support::{
decl_module, decl_storage, decl_event, decl_error,
dispatch::{Dispatchable, DispatchError, DispatchResult, Parameter},
traits::{Get, schedule, OriginTrait, EnsureOrigin},
traits::{Get, schedule, OriginTrait, EnsureOrigin, IsType},
weights::{GetDispatchInfo, Weight},
};
use frame_system::{self as system};
Expand All @@ -66,7 +66,7 @@ pub trait Trait: system::Trait {
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;

/// The aggregated origin which the dispatch will take.
type Origin: OriginTrait<PalletsOrigin = Self::PalletsOrigin> + From<Self::PalletsOrigin>;
type Origin: OriginTrait<PalletsOrigin = Self::PalletsOrigin> + From<Self::PalletsOrigin> + IsType<<Self as system::Trait>::Origin>;

/// The caller origin, overarching type of all pallets origins.
type PalletsOrigin: From<system::RawOrigin<Self::AccountId>> + Codec + Clone + Eq;
Expand Down Expand Up @@ -153,11 +153,7 @@ decl_error! {

decl_module! {
/// Scheduler module declaration.
pub struct Module<T: Trait> for enum Call
where
origin: <T as system::Trait>::Origin,
<T as system::Trait>::Origin: OriginTrait<PalletsOrigin = T::PalletsOrigin>
{
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin {
type Error = Error<T>;
fn deposit_event() = default;

Expand All @@ -179,6 +175,7 @@ decl_module! {
call: Box<<T as Trait>::Call>,
) {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Trait>::Origin::from(origin);
let _ = Self::do_schedule(when, maybe_periodic, priority, origin.caller().clone(), *call);
}

Expand All @@ -195,6 +192,7 @@ decl_module! {
#[weight = 100_000_000 + T::DbWeight::get().reads_writes(1, 2)]
fn cancel(origin, when: T::BlockNumber, index: u32) {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Trait>::Origin::from(origin);
Self::do_cancel(Some(origin.caller().clone()), (when, index))?;
}

Expand All @@ -217,6 +215,7 @@ decl_module! {
call: Box<<T as Trait>::Call>,
) {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Trait>::Origin::from(origin);
Self::do_schedule_named(id, when, maybe_periodic, priority, origin.caller().clone(), *call)?;
}

Expand All @@ -233,6 +232,7 @@ decl_module! {
#[weight = 100_000_000 + T::DbWeight::get().reads_writes(2, 2)]
fn cancel_named(origin, id: Vec<u8>) {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Trait>::Origin::from(origin);
Self::do_cancel_named(Some(origin.caller().clone()), id)?;
}

Expand Down Expand Up @@ -322,10 +322,7 @@ decl_module! {
}
}

impl<T: Trait> Module<T>
where
<T as system::Trait>::Origin: OriginTrait<PalletsOrigin = T::PalletsOrigin>
{
impl<T: Trait> Module<T> {
fn do_schedule(
when: T::BlockNumber,
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
Expand Down Expand Up @@ -426,10 +423,7 @@ where
}
}

impl<T: Trait> schedule::Anon<T::BlockNumber, <T as Trait>::Call, T::PalletsOrigin> for Module<T>
where
<T as system::Trait>::Origin: OriginTrait<PalletsOrigin = T::PalletsOrigin>
{
impl<T: Trait> schedule::Anon<T::BlockNumber, <T as Trait>::Call, T::PalletsOrigin> for Module<T> {
type Address = TaskAddress<T::BlockNumber>;

fn schedule(
Expand All @@ -447,10 +441,7 @@ where
}
}

impl<T: Trait> schedule::Named<T::BlockNumber, <T as Trait>::Call, T::PalletsOrigin> for Module<T>
where
<T as system::Trait>::Origin: OriginTrait<PalletsOrigin = T::PalletsOrigin>
{
impl<T: Trait> schedule::Named<T::BlockNumber, <T as Trait>::Call, T::PalletsOrigin> for Module<T> {
type Address = TaskAddress<T::BlockNumber>;

fn schedule_named(
Expand Down Expand Up @@ -503,10 +494,6 @@ mod tests {
pub trait Trait: system::Trait {
type Event: From<Event> + Into<<Self as system::Trait>::Event>;
}
decl_storage! {
trait Store for Module<T: Trait> as Logger {
}
}
decl_event! {
pub enum Event {
Logged(u32, Weight),
Expand Down
7 changes: 4 additions & 3 deletions frame/support/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
/// # extern crate frame_support;
/// # use frame_support::dispatch;
/// # use frame_system::{self as system, ensure_signed};
/// it: system::Trait {}
/// pub trait Trait: system::Trait where Self::AccountId: From<u32> {}
///
/// decl_module! {
/// pub struct Module<T: Trait> for enum Call where origin: T::Origin, T::AccountId: From<u32> {
Expand Down Expand Up @@ -1452,7 +1452,8 @@ macro_rules! decl_module {
pub struct $mod_type<
$trait_instance: $trait_name
$(<I>, $instance: $instantiable $( = $module_default_instance)?)?
>($crate::sp_std::marker::PhantomData<($trait_instance, $( $instance)?)>);
>($crate::sp_std::marker::PhantomData<($trait_instance, $( $instance)?)>) where
$( $other_where_bounds )*;

$crate::decl_module! {
@impl_on_initialize
Expand Down Expand Up @@ -2165,7 +2166,7 @@ mod tests {
IntegrityTest,
};

pub trait Trait: system::Trait + Sized {
pub trait Trait: system::Trait + Sized where Self::AccountId: From<u32> {
type BlockNumber: Into<u32>;
}

Expand Down
2 changes: 1 addition & 1 deletion frame/support/test/tests/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub trait Currency {}
mod module1 {
use super::*;

pub trait Trait<I>: system::Trait {
pub trait Trait<I>: system::Trait where <Self as system::Trait>::BlockNumber: From<u32> {
type Event: From<Event<Self, I>> + Into<<Self as system::Trait>::Event>;
type Origin: From<Origin<Self, I>>;
type SomeParameter: Get<u32>;
Expand Down