Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate schedule_notify_task #373

Merged
merged 13 commits into from
Jul 5, 2023
27 changes: 0 additions & 27 deletions pallets/automation-time/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,33 +162,6 @@ fn increment_provided_id(mut provided_id: Vec<u8>) -> Vec<u8> {
}

benchmarks! {
schedule_notify_task_empty {
let caller: T::AccountId = account("caller", 0, SEED);
let time: u64 = 7200;
let time_moment: u32 = time.try_into().unwrap();
Timestamp::<T>::set_timestamp(time_moment.into());
let transfer_amount = T::Currency::minimum_balance().saturating_mul(ED_MULTIPLIER.into());
T::Currency::deposit_creating(&caller, transfer_amount.clone().saturating_mul(DEPOSIT_MULTIPLIER.into()));
}: schedule_notify_task(RawOrigin::Signed(caller), vec![10], vec![time], vec![4, 5])

schedule_notify_task_full {
let v in 1 .. T::MaxExecutionTimes::get();

let caller: T::AccountId = account("caller", 0, SEED);
let time: u64 = 7200;

let mut times: Vec<u64> = vec![];
for i in 0..v {
let hour: u64 = (3600 * (i + 1)).try_into().unwrap();
times.push(hour);
}

let mut provided_id = schedule_notify_tasks::<T>(caller.clone(), times.clone(), T::MaxTasksPerSlot::get() - 1);
provided_id = increment_provided_id(provided_id);
let transfer_amount = T::Currency::minimum_balance().saturating_mul(ED_MULTIPLIER.into());
T::Currency::deposit_creating(&caller, transfer_amount.clone().saturating_mul(DEPOSIT_MULTIPLIER.into()));
}: schedule_notify_task(RawOrigin::Signed(caller), provided_id, times, vec![4, 5])

schedule_xcmp_task_full {
let v in 1..T::MaxExecutionTimes::get();

Expand Down
1 change: 1 addition & 0 deletions pallets/automation-time/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ where

// Manually check for ExistenceRequirement since MultiCurrency doesn't currently support it
let free_balance = T::MultiCurrency::free_balance(self.currency_id, &self.owner);

free_balance
.checked_sub(&fee)
.ok_or(DispatchError::Token(BelowMinimum))?
Expand Down
47 changes: 3 additions & 44 deletions pallets/automation-time/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,63 +349,21 @@ pub mod pallet {

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: T::BlockNumber) -> Weight {
fn on_initialize(block: T::BlockNumber) -> Weight {
chrisli30 marked this conversation as resolved.
Show resolved Hide resolved
if Self::is_shutdown() == true {
return T::DbWeight::get().reads(1u64)
}

let max_weight: Weight = Weight::from_ref_time(
T::MaxWeightPercentage::get().mul_floor(T::MaxBlockWeight::get()),
);

Self::trigger_tasks(max_weight)
}
}

#[pallet::call]
impl<T: Config> Pallet<T> {
/// Schedule a task to fire an event with a custom message.
///
/// Before the task can be scheduled the task must past validation checks.
/// * The transaction is signed
/// * The provided_id's length > 0
/// * The message's length > 0
/// * The times are valid
///
/// # Parameters
/// * `provided_id`: An id provided by the user. This id must be unique for the user.
/// * `execution_times`: The list of unix standard times in seconds for when the task should run.
/// * `message`: The message you want the event to have.
///
/// # Errors
/// * `InvalidTime`: Time must end in a whole hour.
/// * `PastTime`: Time must be in the future.
/// * `EmptyMessage`: The message cannot be empty.
/// * `DuplicateTask`: There can be no duplicate tasks.
/// * `TimeTooFarOut`: Execution time or frequency are past the max time horizon.
/// * `TimeSlotFull`: Time slot is full. No more tasks can be scheduled for this time.
#[pallet::call_index(0)]
#[pallet::weight(<T as Config>::WeightInfo::schedule_notify_task_full(execution_times.len().try_into().unwrap()))]
pub fn schedule_notify_task(
origin: OriginFor<T>,
provided_id: Vec<u8>,
execution_times: Vec<UnixTime>,
message: Vec<u8>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
if message.len() == 0 {
Err(Error::<T>::EmptyMessage)?
}

let schedule = Schedule::new_fixed_schedule::<T>(execution_times)?;
Self::validate_and_schedule_task(
Action::Notify { message },
who,
provided_id,
schedule,
)?;
Ok(().into())
}

/// Schedule a task to transfer native token balance from sender to recipient.
///
/// Before the task can be scheduled the task must past validation checks.
Expand Down Expand Up @@ -1052,6 +1010,7 @@ pub mod pallet {
/// Fire the notify event with the custom message.
pub fn run_notify_task(message: Vec<u8>) -> (Weight, Option<DispatchError>) {
Self::deposit_event(Event::Notify { message });

(<T as Config>::WeightInfo::run_notify_task(), None)
}

Expand Down
19 changes: 13 additions & 6 deletions pallets/automation-time/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,19 +389,26 @@ pub fn new_test_ext(state_block_time: u64) -> sp_io::TestExternalities {
ext
}

// A function to support test scheduleing.
// We don't focus on making sure the execution run properly. We just focus on
// making sure a task is scheduled into the queue
chrisli30 marked this conversation as resolved.
Show resolved Hide resolved
pub fn schedule_task(
owner: [u8; 32],
provided_id: Vec<u8>,
scheduled_times: Vec<u64>,
message: Vec<u8>,
) -> sp_core::H256 {
get_funds(AccountId32::new(owner));
let task_hash_input = TaskHashInput::new(AccountId32::new(owner), provided_id.clone());
assert_ok!(AutomationTime::schedule_notify_task(
RuntimeOrigin::signed(AccountId32::new(owner)),
let account_id = AccountId32::new(owner);
let task_hash_input = TaskHashInput::new(account_id.clone(), provided_id.clone());
let call: RuntimeCall = frame_system::Call::remark_with_event { remark: message }.into();

assert_ok!(fund_account_dynamic_dispatch(&account_id, scheduled_times.len(), call.encode()));

assert_ok!(AutomationTime::schedule_dynamic_dispatch_task(
RuntimeOrigin::signed(account_id.clone()),
provided_id,
scheduled_times,
message,
ScheduleParam::Fixed { execution_times: scheduled_times },
Box::new(call),
));
BlakeTwo256::hash_of(&task_hash_input)
}
Expand Down
Loading