diff --git a/pallets/automation-time/src/lib.rs b/pallets/automation-time/src/lib.rs index 4af2f40d..bef499b9 100644 --- a/pallets/automation-time/src/lib.rs +++ b/pallets/automation-time/src/lib.rs @@ -37,7 +37,6 @@ mod mock; mod tests; mod benchmarking; -pub mod migrations; pub mod weights; mod fees; diff --git a/pallets/automation-time/src/migrations/mod.rs b/pallets/automation-time/src/migrations/mod.rs deleted file mode 100644 index 2db2f6a4..00000000 --- a/pallets/automation-time/src/migrations/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -// Migrations - -pub mod update_task_idv2; -pub mod update_xcmp_task; -pub mod utils; diff --git a/pallets/automation-time/src/migrations/update_task_idv2.rs b/pallets/automation-time/src/migrations/update_task_idv2.rs deleted file mode 100644 index 809ede13..00000000 --- a/pallets/automation-time/src/migrations/update_task_idv2.rs +++ /dev/null @@ -1,387 +0,0 @@ -use core::marker::PhantomData; - -use crate::{AccountTaskId, Config, MissedTaskV2Of, ScheduledTasksOf, TaskIdV2, UnixTime}; -use codec::{Decode, Encode}; -use frame_support::{ - storage::types::ValueQuery, - traits::{Get, OnRuntimeUpgrade}, - weights::{RuntimeDbWeight, Weight}, - Twox64Concat, -}; - -use sp_std::vec::Vec; - -use crate::migrations::utils::{ - deprecate::old_taskid_to_idv2, OldAccountTaskId, OldMissedTaskV2Of, OldScheduledTasksOf, -}; - -// This is old TaskQueueV2 with old Task -#[frame_support::storage_alias] -pub type TaskQueueV2 = - StorageValue>, ValueQuery>; - -pub struct UpdateTaskIDV2ForTaskQueueV2(PhantomData); -impl OnRuntimeUpgrade for UpdateTaskIDV2ForTaskQueueV2 { - fn on_runtime_upgrade() -> Weight { - log::info!(target: "automation-time", "TaskID migration"); - - let mut storage_ops: u64 = 0; - - let old_task_queue = TaskQueueV2::::get(); - let migrated_tasks = old_task_queue.len(); - - let new_task_queue: Vec> = old_task_queue - .iter() - .map(|(a, b)| ((*a).clone(), old_taskid_to_idv2::(b))) - .collect::>>(); - - storage_ops += old_task_queue.len() as u64; - crate::TaskQueueV2::::put(new_task_queue); - - log::info!( - target: "automation-time", - "migration: Update TaskQueueV2 succesful! Migrated {} tasks.", - migrated_tasks - ); - - let db_weight: RuntimeDbWeight = T::DbWeight::get(); - db_weight.reads_writes(storage_ops + 1, storage_ops + 1) - } - - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { - let prev_count = crate::TaskQueueV2::::get().len() as u32; - Ok(prev_count.encode()) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(prev_count: Vec) -> Result<(), &'static str> { - let prev_count: u32 = Decode::decode(&mut prev_count.as_slice()) - .expect("the state parameter should be something that was generated by pre_upgrade"); - let post_count = crate::TaskQueueV2::::get().len() as u32; - assert!(post_count == prev_count); - - Ok(()) - } -} - -// This is old ScheduledTasksV3 with old Taskid using T::Hash -#[frame_support::storage_alias] -pub type ScheduledTasksV3 = - StorageMap>; -pub struct UpdateTaskIDV2ForScheduledTasksV3(PhantomData); -impl OnRuntimeUpgrade for UpdateTaskIDV2ForScheduledTasksV3 { - fn on_runtime_upgrade() -> Weight { - log::info!(target: "automation-time", "TaskID migration"); - - let mut migrated_tasks = 0; - let mut storage_ops: u64 = 0; - ScheduledTasksV3::::iter().for_each(|(time_slot, old_scheduled_tasks)| { - storage_ops += 1; - let migrated_scheduled_tasks: Vec<(T::AccountId, TaskIdV2)> = old_scheduled_tasks - .tasks - .into_iter() - .map(|(account_id, old_task_id)| { - migrated_tasks += 1; - storage_ops += 1; - (account_id.clone(), old_taskid_to_idv2::(&(old_task_id.clone()))) - }) - .collect::>(); - - storage_ops += 1; - crate::ScheduledTasksV3::::insert( - time_slot, - ScheduledTasksOf:: { - tasks: migrated_scheduled_tasks, - weight: old_scheduled_tasks.weight, - }, - ); - }); - - log::info!( - target: "automation-time", - "migration: Update ScheduledTasksV3 succesful! Migrated {} tasks.", - migrated_tasks - ); - - let db_weight: RuntimeDbWeight = T::DbWeight::get(); - db_weight.reads_writes(storage_ops + 1, storage_ops + 1) - } - - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { - let prev_count = crate::ScheduledTasksV3::::iter().count() as u32; - Ok(prev_count.encode()) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(prev_count: Vec) -> Result<(), &'static str> { - let prev_count: u32 = Decode::decode(&mut prev_count.as_slice()) - .expect("the state parameter should be something that was generated by pre_upgrade"); - let post_count = crate::ScheduledTasksV3::::iter().count() as u32; - assert!(post_count == prev_count); - - Ok(()) - } -} - -// This is old MissedQueueV2 with old Task -#[frame_support::storage_alias] -pub type MissedQueueV2 = - StorageValue>, ValueQuery>; - -pub struct UpdateTaskIDV2ForMissedQueueV2(PhantomData); -impl OnRuntimeUpgrade for UpdateTaskIDV2ForMissedQueueV2 { - fn on_runtime_upgrade() -> Weight { - log::info!(target: "automation-time", "TaskID migration"); - - let old_missed_queue = MissedQueueV2::::get(); - let migrated_tasks: u64 = old_missed_queue.len() as u64; - - let migrated_missed_queuee: Vec> = old_missed_queue - .into_iter() - .map(|old_missed_task| { - let a: MissedTaskV2Of = MissedTaskV2Of:: { - owner_id: old_missed_task.owner_id.clone(), - execution_time: old_missed_task.execution_time, - task_id: old_taskid_to_idv2::(&old_missed_task.task_id.clone()), - }; - - a - }) - .collect::>>(); - - crate::MissedQueueV2::::put(migrated_missed_queuee); - - log::info!( - target: "automation-time", - "migration: Update MissedQueueV2 succesful! Migrated {} tasks.", - migrated_tasks - ); - - let db_weight: RuntimeDbWeight = ::DbWeight::get(); - db_weight.reads_writes(migrated_tasks + 1, migrated_tasks + 1) - } - - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { - let prev_count = crate::MissedQueueV2::::get().len() as u32; - Ok(prev_count.encode()) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(prev_count: Vec) -> Result<(), &'static str> { - let prev_count: u32 = Decode::decode(&mut prev_count.as_slice()) - .expect("the state parameter should be something that was generated by pre_upgrade"); - let post_count = crate::MissedQueueV2::::get().len() as u32; - assert!(post_count == prev_count); - - Ok(()) - } -} - -#[cfg(test)] -mod test { - - use super::{ - UpdateTaskIDV2ForMissedQueueV2, UpdateTaskIDV2ForScheduledTasksV3, - UpdateTaskIDV2ForTaskQueueV2, - }; - use crate::{ - migrations::utils::{ - deprecate::generate_old_task_id, OldMissedTaskV2, OldScheduledTasksOf, TEST_TASKID1, - TEST_TASKID2, - }, - mock::*, - MissedTaskV2, - }; - use frame_support::traits::OnRuntimeUpgrade; - use sp_runtime::AccountId32; - - #[test] - fn on_runtime_upgrade() { - new_test_ext(0).execute_with(|| { - let account_id1 = AccountId32::new(ALICE); - let account_id2 = AccountId32::new(BOB); - - let task_id1: Vec = - hex::decode(TEST_TASKID1).expect("test task id hex code is malformed"); - let task_id2: Vec = - hex::decode(TEST_TASKID2).expect("test task id hex code is malformed"); - - let old_taskqueuev2 = vec![ - (account_id1.clone(), generate_old_task_id::(account_id1.clone(), vec![1])), - (account_id2.clone(), generate_old_task_id::(account_id2.clone(), vec![2])), - ]; - - super::TaskQueueV2::::put(old_taskqueuev2); - UpdateTaskIDV2ForTaskQueueV2::::on_runtime_upgrade(); - - let queue = crate::TaskQueueV2::::get(); - let (task_owner, task_id) = - queue.first().expect("migration task failed to copy task over"); - - assert_eq!( - *task_owner, - account_id1.clone(), - "migration failed to convert OldTaskId -> TaskIDV2 for TaskQueueV2" - ); - assert_eq!(*task_id, task_id1); - - let (task_owner, task_id) = - queue.last().expect("migration task failed to copy task over"); - assert_eq!( - *task_owner, - account_id2.clone(), - "migration failed to convert OldTaskId -> TaskIDV2 for TaskQueueV2" - ); - assert_eq!(*task_id, task_id2); - }) - } - - #[test] - fn on_runtime_upgrade_for_schedule_taskv3() { - new_test_ext(0).execute_with(|| { - let task_owner1 = AccountId32::new(ALICE); - let task_owner2 = AccountId32::new(BOB); - - // These are H256/BlakeTwo256 hex generate from our old task id generation from hashing - let task_id1: Vec = hex::decode(TEST_TASKID1).expect("TEST_TASKID1 is malformed"); - let task_id2: Vec = hex::decode(TEST_TASKID2).expect("TEST_TASKID1 is malformed"); - - super::ScheduledTasksV3::::insert( - 3600, - OldScheduledTasksOf:: { - tasks: vec![ - ( - task_owner1.clone(), - generate_old_task_id::(task_owner1.clone(), vec![1]), - ), - ( - task_owner2.clone(), - generate_old_task_id::(task_owner2.clone(), vec![2]), - ), - ], - // just a random number to compare later on - weight: 1_789_657, - }, - ); - - super::ScheduledTasksV3::::insert( - 7200, - OldScheduledTasksOf:: { - tasks: vec![ - ( - task_owner2.clone(), - generate_old_task_id::(task_owner2.clone(), vec![33]), - ), - ( - task_owner1.clone(), - generate_old_task_id::(task_owner1.clone(), vec![32]), - ), - ], - // just a random number to compare later on - weight: 1_967_672, - }, - ); - UpdateTaskIDV2ForScheduledTasksV3::::on_runtime_upgrade(); - - // ensure all the slots are converted properly - let scheduled_tasks = crate::ScheduledTasksV3::::get(3600) - .expect("ScheduledTasksV3 failed to migrate"); - assert_eq!( - scheduled_tasks.weight, 1_789_657, - "migration failed to convert old ScheduledTasksV3 to new TaskID format" - ); - assert_eq!( - scheduled_tasks.tasks, - vec![ - (task_owner1.clone(), task_id1.clone()), - (task_owner2.clone(), task_id2.clone()), - ], - "migration failed to convert old ScheduledTasksV3 to new TaskID format" - ); - - let scheduled_tasks = crate::ScheduledTasksV3::::get(7200) - .expect("ScheduledTasksV3 failed to migrate"); - assert_eq!( - scheduled_tasks.weight, 1_967_672, - "migration failed to convert old ScheduledTasksV3 to new TaskID format" - ); - assert_eq!( - scheduled_tasks.tasks, - vec![ - // (task owner, vec![33]) hash -> "0x7191f3d83bcbeb221f7b00f501e9a8da3ba3c2d15a672eb694ee7e09dbaddd1e" - ( - task_owner2.clone(), - hex::decode( - "7191f3d83bcbeb221f7b00f501e9a8da3ba3c2d15a672eb694ee7e09dbaddd1e" - ) - .expect("invalid hex code") - ), - // (task owner1, vec![32]) hash -> "0xe94040ca5d09f0e1023aecf5abc3afac0b9e66bc3b1209183b3a009f4c073c2b" - ( - task_owner1.clone(), - hex::decode( - "e94040ca5d09f0e1023aecf5abc3afac0b9e66bc3b1209183b3a009f4c073c2b" - ) - .expect("invalid hex code"), - ), - ], - "migration failed to convert old ScheduledTasksV3 to new TaskID format" - ); - }) - } - - #[test] - fn on_runtime_upgrade_for_missed_queue_v2() { - new_test_ext(0).execute_with(|| { - let account_id1 = AccountId32::new(ALICE); - let account_id2 = AccountId32::new(BOB); - - // These are H256/BlakeTwo256 hex generate from our old task id generation from hashing - let task_id1: Vec = - hex::decode(TEST_TASKID1).expect("test task id hex code is malformed"); - let task_id2: Vec = - hex::decode(TEST_TASKID2).expect("test task id hex code is malformed"); - - let old_missed_queueu_v2 = vec![ - OldMissedTaskV2 { - owner_id: account_id1.clone(), - task_id: generate_old_task_id::(account_id1.clone(), vec![1]), - execution_time: 3600, - }, - OldMissedTaskV2 { - owner_id: account_id2.clone(), - task_id: generate_old_task_id::(account_id2.clone(), vec![2]), - execution_time: 7200, - }, - ]; - - super::MissedQueueV2::::put(old_missed_queueu_v2); - UpdateTaskIDV2ForMissedQueueV2::::on_runtime_upgrade(); - - let queue = crate::MissedQueueV2::::get(); - - assert_eq!( - queue.first().expect("migration task failed to copy missed queuev2 over"), - &MissedTaskV2 { - owner_id: account_id1.clone(), - task_id: task_id1, - execution_time: 3600, - }, - "migration failed to convert old MissedTaskV2 -> new MissedTaskV2 for MissedQueueV2" - ); - - assert_eq!( - queue.last().expect("migration task failed to copy missed queuev2 over"), - &MissedTaskV2 { - owner_id: account_id2.clone(), - task_id: task_id2, - execution_time: 7200, - }, - "migration failed to convert old MissedTaskV2 -> new MissedTaskV2 for MissedQueueV2" - ); - }) - } -} diff --git a/pallets/automation-time/src/migrations/update_xcmp_task.rs b/pallets/automation-time/src/migrations/update_xcmp_task.rs deleted file mode 100644 index 43f0bca4..00000000 --- a/pallets/automation-time/src/migrations/update_xcmp_task.rs +++ /dev/null @@ -1,305 +0,0 @@ -use core::marker::PhantomData; - -use crate::{AccountOf, ActionOf, AssetPayment, Config, InstructionSequence, TaskOf}; -use frame_support::{ - traits::{Get, OnRuntimeUpgrade}, - weights::{RuntimeDbWeight, Weight}, - Twox64Concat, -}; -use sp_runtime::traits::Convert; -use sp_std::{vec, vec::Vec}; -use xcm::latest::prelude::*; - -use crate::migrations::utils::{OldAction, OldTask, OldTaskId}; - -use primitives::TransferCallCreator; - -#[cfg(feature = "try-runtime")] -use codec::Decode; -use codec::Encode; - -const EXECUTION_FEE_AMOUNT: u128 = 4_000_000_000; -const INSTRUCTION_WEIGHT_REF_TIME: u64 = 150_000_000; - -impl From> for ActionOf { - fn from(action: OldAction) -> Self { - match action { - OldAction::AutoCompoundDelegatedStake { delegator, collator, account_minimum } => - Self::AutoCompoundDelegatedStake { delegator, collator, account_minimum }, - OldAction::Notify { message } => { - let call: ::RuntimeCall = - frame_system::Call::::remark_with_event { remark: message }.into(); - Self::DynamicDispatch { encoded_call: call.encode() } - }, - OldAction::NativeTransfer { recipient, amount, .. } => { - let call: ::RuntimeCall = - T::TransferCallCreator::create_transfer_call( - sp_runtime::MultiAddress::Id(recipient), - amount, - ); - Self::DynamicDispatch { encoded_call: call.encode() } - }, - OldAction::XCMP { - para_id, - currency_id, - encoded_call, - encoded_call_weight, - schedule_as, - .. - } => { - let schedule_fee = - T::CurrencyIdConvert::convert(currency_id).expect("IncoveribleCurrencyId"); - Self::XCMP { - destination: MultiLocation::new(1, X1(Parachain(para_id.into()))), - schedule_fee, - execution_fee: AssetPayment { - asset_location: MultiLocation::new(0, Here).into(), - amount: EXECUTION_FEE_AMOUNT, - }, - encoded_call, - encoded_call_weight: encoded_call_weight.clone(), - overall_weight: encoded_call_weight.saturating_add( - Weight::from_ref_time(INSTRUCTION_WEIGHT_REF_TIME).saturating_mul(6), - ), - schedule_as, - instruction_sequence: InstructionSequence::PayThroughSovereignAccount, - } - }, - OldAction::DynamicDispatch { encoded_call } => Self::DynamicDispatch { encoded_call }, - } - } -} - -#[frame_support::storage_alias] -pub type AccountTasks = StorageDoubleMap< - AutomationTime, - Twox64Concat, - AccountOf, - Twox64Concat, - OldTaskId, - OldTask, ->; - -pub struct UpdateXcmpTask(PhantomData); -impl OnRuntimeUpgrade for UpdateXcmpTask { - fn on_runtime_upgrade() -> Weight { - log::info!(target: "automation-time", "UpdateXcmpTask migration"); - - let mut migrated_tasks = 0u64; - - let mut tasks: Vec<(AccountOf, TaskOf)> = vec![]; - AccountTasks::::drain().for_each(|(account_id, _task_id, task)| { - let migrated_task: TaskOf = task.into(); - - tasks.push((account_id, migrated_task)); - migrated_tasks += 1; - }); - - tasks.iter().for_each(|(account_id, task)| { - crate::AccountTasks::::insert(account_id, task.task_id.clone(), task) - }); - - log::info!( - target: "automation-time", - "migration: UpdateXcmpTask succesful! Migrated {} tasks.", - migrated_tasks - ); - - let db_weight: RuntimeDbWeight = T::DbWeight::get(); - db_weight.reads_writes(migrated_tasks + 1, migrated_tasks + 1) - } - - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { - let prev_count = crate::AccountTasks::::iter().count() as u32; - Ok(prev_count.encode()) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(prev_count: Vec) -> Result<(), &'static str> { - let prev_count: u32 = Decode::decode(&mut prev_count.as_slice()) - .expect("the state parameter should be something that was generated by pre_upgrade"); - let post_count = crate::AccountTasks::::iter().count() as u32; - assert!(post_count == prev_count); - - Ok(()) - } -} - -#[cfg(test)] -mod test { - use super::*; - use crate::{ - migrations::utils::{deprecate::generate_old_task_id, TEST_TASKID1}, - mock::*, - ActionOf, AssetPayment, InstructionSequence, Schedule, TaskOf, - }; - - use cumulus_primitives_core::ParaId; - use frame_support::{traits::OnRuntimeUpgrade, weights::Weight}; - use sp_runtime::AccountId32; - - #[test] - fn on_runtime_upgrade() { - new_test_ext(0).execute_with(|| { - let para_id: ParaId = 1000.into(); - let account_id = AccountId32::new(ALICE); - let schedule_as = Some(AccountId32::new(BOB)); - let encoded_call_weight = Weight::from_ref_time(10); - - let task = OldTask:: { - owner_id: account_id.clone(), - provided_id: vec![1], - schedule: Schedule::Fixed { - execution_times: vec![0, 1].try_into().unwrap(), - executions_left: 2, - }, - action: OldAction::::XCMP { - para_id, - currency_id: 0u32.into(), - xcm_asset_location: MultiLocation::new(1, X1(Parachain(para_id.into()))).into(), - encoded_call: vec![0u8], - encoded_call_weight: encoded_call_weight.clone(), - schedule_as: schedule_as.clone(), - }, - }; - - let old_task_id = - generate_old_task_id::(account_id.clone(), task.provided_id.clone()); - super::AccountTasks::::insert(account_id.clone(), old_task_id.clone(), task); - - UpdateXcmpTask::::on_runtime_upgrade(); - - assert_eq!(crate::AccountTasks::::iter().count(), 1); - - let task_id1 = hex::decode(TEST_TASKID1).expect("malform hex code for test task id"); - assert_eq!( - crate::AccountTasks::::get(account_id.clone(), task_id1.clone()).unwrap(), - TaskOf:: { - owner_id: account_id.clone(), - task_id: task_id1, - schedule: Schedule::Fixed { - execution_times: vec![0, 1].try_into().unwrap(), - executions_left: 2 - }, - action: ActionOf::::XCMP { - destination: MultiLocation::new(1, X1(Parachain(para_id.into()))), - schedule_fee: MultiLocation::default(), - execution_fee: AssetPayment { - asset_location: MultiLocation::new(0, Here).into(), - amount: EXECUTION_FEE_AMOUNT, - }, - encoded_call: vec![0u8], - encoded_call_weight: encoded_call_weight.clone(), - overall_weight: encoded_call_weight.saturating_add( - Weight::from_ref_time(INSTRUCTION_WEIGHT_REF_TIME).saturating_mul(6) - ), - schedule_as, - instruction_sequence: InstructionSequence::PayThroughSovereignAccount, - }, - abort_errors: vec![], - } - ); - }) - } - - #[test] - fn on_runtime_upgrade_notify() { - new_test_ext(0).execute_with(|| { - let account_id = AccountId32::new(ALICE); - - let task = OldTask:: { - owner_id: account_id.clone(), - provided_id: vec![1], - schedule: Schedule::Fixed { - execution_times: vec![0, 1].try_into().unwrap(), - executions_left: 2, - }, - action: OldAction::::Notify { message: "hello world".as_bytes().to_vec() }, - }; - - let old_task_id = - generate_old_task_id::(account_id.clone(), task.provided_id.clone()); - super::AccountTasks::::insert(account_id.clone(), old_task_id.clone(), task); - - UpdateXcmpTask::::on_runtime_upgrade(); - - let task_id1 = hex::decode(TEST_TASKID1).expect("malform hex code for test task id"); - assert_eq!( - crate::AccountTasks::::get(account_id.clone(), task_id1.clone()).unwrap(), - TaskOf:: { - owner_id: account_id.clone(), - task_id: task_id1, - schedule: Schedule::Fixed { - execution_times: vec![0, 1].try_into().unwrap(), - executions_left: 2 - }, - action: ActionOf::::DynamicDispatch { - // a = [0, 7, 44, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100] - // irb(main):002:0> a.pack("c*").unpack("H*").first - // => "00072c68656c6c6f20776f726c64" - // Take this hex to polkadotjs and decode we will get - // decoded call: system remarkWithEvent - // remark: hello world - // https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fturing-rpc.dwellir.com#/extrinsics/decode/0x00072c68656c6c6f20776f726c64 - encoded_call: vec![ - 0, 7, 44, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100 - ] - }, - abort_errors: vec![], - } - ); - }) - } - - #[test] - fn on_runtime_upgrade_native_transfer() { - new_test_ext(0).execute_with(|| { - let _para_id: ParaId = 1000.into(); - let account_id = AccountId32::new(ALICE); - let recipient = AccountId32::new(BOB); - - let task = OldTask:: { - owner_id: account_id.clone(), - provided_id: vec![1], - schedule: Schedule::Fixed { - execution_times: vec![0, 1].try_into().unwrap(), - executions_left: 2, - }, - action: OldAction::::NativeTransfer { - sender: account_id.clone(), - recipient, - amount: 100, - }, - }; - - let old_task_id = - generate_old_task_id::(account_id.clone(), task.provided_id.clone()); - super::AccountTasks::::insert(account_id.clone(), old_task_id.clone(), task); - - UpdateXcmpTask::::on_runtime_upgrade(); - - assert_eq!(crate::AccountTasks::::iter().count(), 1); - - let task_id1 = hex::decode(TEST_TASKID1).expect("malform hex code for test task id"); - assert_eq!( - crate::AccountTasks::::get(account_id.clone(), task_id1.clone()).unwrap(), - TaskOf:: { - owner_id: account_id.clone(), - task_id: task_id1, - schedule: Schedule::Fixed { - execution_times: vec![0, 1].try_into().unwrap(), - executions_left: 2 - }, - action: ActionOf::::DynamicDispatch { - encoded_call: vec![ - 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 145, 1 - ], - }, - abort_errors: vec![], - } - ); - }) - } -} diff --git a/pallets/automation-time/src/migrations/utils.rs b/pallets/automation-time/src/migrations/utils.rs deleted file mode 100644 index cd46bfb4..00000000 --- a/pallets/automation-time/src/migrations/utils.rs +++ /dev/null @@ -1,133 +0,0 @@ -// Holding the old data structure so we can share them betwen multiple migrations -use crate::{AccountOf, BalanceOf, Config, Schedule, TaskOf, UnixTime}; - -use codec::{Decode, Encode}; -use cumulus_primitives_core::ParaId; -use frame_support::weights::Weight; - -use scale_info::TypeInfo; -use sp_std::{vec, vec::Vec}; -use xcm::VersionedMultiLocation; - -// These are H256/BlakeTwo256 hex generate from our old task id generation from hashing -// These cons are used for our unit test -// (Account, ProvidedID) -pub const TEST_TASKID1: &str = "d1263842e34adeb00be1146b30bc6527951f0a0f5d5a3f7a758537735b8bcb04"; -pub const TEST_TASKID2: &str = "f76acf0b1d8ef503450a4d5c1a451f1921a906e8711f551c2945e09fb44de5ff"; - -// Old format -pub type OldTaskId = ::Hash; -pub type OldAccountTaskId = (AccountOf, OldTaskId); - -#[derive(Debug, Encode, Decode, TypeInfo)] -#[scale_info(skip_type_params(MaxExecutionTimes))] -pub struct OldTask { - pub owner_id: T::AccountId, - pub provided_id: Vec, - pub schedule: Schedule, - pub action: OldAction, -} - -impl From> for TaskOf { - fn from(task: OldTask) -> Self { - // Previously, our task id is a blake256 hash of account_id + provided_id - // Now, our task id is generate use a different formula without relying on `provided_id` - // for existing task in our storage, the type of the TaskID was T::Hash. - // When emitting on the event, it can be re-present as hex string of the hash. - // so in new task, we simply take that hash and convert it to the hex string, and convert - // to a Vec which is our new taskidv2 format. - let old_task_id = - deprecate::generate_old_task_id::(task.owner_id.clone(), task.provided_id.clone()); - - TaskOf:: { - owner_id: task.owner_id, - task_id: deprecate::old_taskid_to_idv2::(&old_task_id), - schedule: task.schedule, - action: task.action.into(), - abort_errors: vec![], - } - } -} - -/// The enum that stores all action specific data. -#[derive(Clone, Debug, Eq, PartialEq, Encode, Decode, TypeInfo)] -pub enum OldAction { - Notify { - message: Vec, - }, - NativeTransfer { - sender: T::AccountId, - recipient: T::AccountId, - amount: BalanceOf, - }, - XCMP { - para_id: ParaId, - currency_id: T::CurrencyId, - xcm_asset_location: VersionedMultiLocation, - encoded_call: Vec, - encoded_call_weight: Weight, - schedule_as: Option, - }, - AutoCompoundDelegatedStake { - delegator: T::AccountId, - collator: T::AccountId, - account_minimum: BalanceOf, - }, - DynamicDispatch { - encoded_call: Vec, - }, -} - -pub type OldScheduledTasksOf = OldScheduledTasks, OldTaskId>; - -#[derive(Debug, Decode, Eq, Encode, PartialEq, TypeInfo)] -#[scale_info(skip_type_params(T))] -pub struct OldScheduledTasks { - pub tasks: Vec<(AccountId, OldTaskId)>, - pub weight: u128, -} - -impl Default for OldScheduledTasks { - fn default() -> Self { - Self { tasks: vec![], weight: 0 } - } -} - -#[derive(Debug, Eq, PartialEq, Encode, Decode, TypeInfo)] -pub struct OldMissedTaskV2 { - pub owner_id: AccountId, - pub task_id: TaskId, - pub execution_time: UnixTime, -} - -pub type OldMissedTaskV2Of = OldMissedTaskV2, OldTaskId>; - -pub mod deprecate { - use super::*; - - use sp_runtime::traits::Hash; - - #[derive(Debug, Encode, Decode, TypeInfo)] - pub struct TaskHashInput { - owner_id: AccountId, - provided_id: Vec, - } - - impl TaskHashInput { - pub fn new(owner_id: AccountId, provided_id: Vec) -> Self { - Self { owner_id, provided_id } - } - } - - pub fn old_taskid_to_idv2(old_task_id: &OldTaskId) -> Vec { - old_task_id.as_ref().into() - } - - pub fn generate_old_task_id( - owner_id: AccountOf, - provided_id: Vec, - ) -> OldTaskId { - let task_hash_input = TaskHashInput::new(owner_id, provided_id); - T::Hashing::hash_of(&task_hash_input) - } -} diff --git a/runtime/turing/src/lib.rs b/runtime/turing/src/lib.rs index 020a141d..1afab487 100644 --- a/runtime/turing/src/lib.rs +++ b/runtime/turing/src/lib.rs @@ -145,17 +145,7 @@ pub type Executive = frame_executive::Executive< // All migrations executed on runtime upgrade as a nested tuple of types implementing // `OnRuntimeUpgrade`. -type Migrations = ( - // First we upgrade storage from the old task id -> the new task id - pallet_automation_time::migrations::update_task_idv2::UpdateTaskIDV2ForTaskQueueV2, - pallet_automation_time::migrations::update_task_idv2::UpdateTaskIDV2ForMissedQueueV2, - pallet_automation_time::migrations::update_task_idv2::UpdateTaskIDV2ForScheduledTasksV3< - Runtime, - >, - // Then we add the extra info in new XCMP, we also update the new task id for AccountTasks in - // this migration - pallet_automation_time::migrations::update_xcmp_task::UpdateXcmpTask, -); +type Migrations = (); /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know /// the specifics of the runtime. They can then be made to be agnostic over specific formats