diff --git a/runtime/litmus/src/lib.rs b/runtime/litmus/src/lib.rs index ca448a9340..8716d280cc 100644 --- a/runtime/litmus/src/lib.rs +++ b/runtime/litmus/src/lib.rs @@ -130,7 +130,6 @@ pub type Executive = frame_executive::Executive< // it was reverse order before. // See the comment before collation related pallets too. AllPalletsWithSystem, - migration::RemoveSudoAndStorage, >; impl_opaque_keys! { diff --git a/runtime/litmus/src/migration/P9115.rs b/runtime/litmus/src/migration/P9115.rs new file mode 100644 index 0000000000..f684510cff --- /dev/null +++ b/runtime/litmus/src/migration/P9115.rs @@ -0,0 +1,70 @@ +// Copyright 2020-2021 Litentry Technologies GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . +use frame_support::{ + traits::{Get, OnRuntimeUpgrade}, + StorageHasher, Twox128, +}; +use sp_std::marker::PhantomData; + +pub struct RemoveSudoAndStorage(PhantomData); +impl OnRuntimeUpgrade for RemoveSudoAndStorage +where + T: frame_system::Config, +{ + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result<(), &'static str> { + log::info!("Pre check pallet Sudo exists"); + assert!( + frame_support::storage::migration::have_storage_value(b"Sudo", b"Key", b"",), + "Storage query fails: Sudo Key" + ); + Ok(()) + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + use sp_io::KillStorageResult; + // Remove Sudo Storage + // TODO: Very Weak safety + let entries: u64 = 4 + 100; + let _res: KillStorageResult = frame_support::storage::unhashed::clear_prefix( + &Twox128::hash(b"Sudo"), + Some(entries.try_into().unwrap()), + None, + ) + .into(); + ::DbWeight::get().writes(entries) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade() -> Result<(), &'static str> { + use sp_io::KillStorageResult; + + log::info!("Post check Sudo"); + let res: KillStorageResult = + frame_support::storage::unhashed::clear_prefix(&Twox128::hash(b"Sudo"), Some(0), None) + .into(); + + match res { + KillStorageResult::AllRemoved(0) | KillStorageResult::SomeRemaining(0) => {}, + KillStorageResult::AllRemoved(n) | KillStorageResult::SomeRemaining(n) => { + log::error!("Remaining entries: {:?}", n); + return Err("Sudo not removed") + }, + }; + + Ok(()) + } +} diff --git a/runtime/litmus/src/migration/migration.md b/runtime/litmus/src/migration/migration.md new file mode 100644 index 0000000000..5948610714 --- /dev/null +++ b/runtime/litmus/src/migration/migration.md @@ -0,0 +1,6 @@ +P9115.rs +https://github.com/litentry/litentry-parachain/releases/tag/v0.9.11-1 + # This migration is for the remove of Sudo on Litmus + + + # The main purpose of runtime upgrade is for removing sudo and its storage. \ No newline at end of file diff --git a/runtime/litmus/src/migration/mod.rs b/runtime/litmus/src/migration/mod.rs index f684510cff..8b13789179 100644 --- a/runtime/litmus/src/migration/mod.rs +++ b/runtime/litmus/src/migration/mod.rs @@ -1,70 +1 @@ -// Copyright 2020-2021 Litentry Technologies GmbH. -// This file is part of Litentry. -// -// Litentry is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Litentry is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Litentry. If not, see . -use frame_support::{ - traits::{Get, OnRuntimeUpgrade}, - StorageHasher, Twox128, -}; -use sp_std::marker::PhantomData; -pub struct RemoveSudoAndStorage(PhantomData); -impl OnRuntimeUpgrade for RemoveSudoAndStorage -where - T: frame_system::Config, -{ - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result<(), &'static str> { - log::info!("Pre check pallet Sudo exists"); - assert!( - frame_support::storage::migration::have_storage_value(b"Sudo", b"Key", b"",), - "Storage query fails: Sudo Key" - ); - Ok(()) - } - - fn on_runtime_upgrade() -> frame_support::weights::Weight { - use sp_io::KillStorageResult; - // Remove Sudo Storage - // TODO: Very Weak safety - let entries: u64 = 4 + 100; - let _res: KillStorageResult = frame_support::storage::unhashed::clear_prefix( - &Twox128::hash(b"Sudo"), - Some(entries.try_into().unwrap()), - None, - ) - .into(); - ::DbWeight::get().writes(entries) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade() -> Result<(), &'static str> { - use sp_io::KillStorageResult; - - log::info!("Post check Sudo"); - let res: KillStorageResult = - frame_support::storage::unhashed::clear_prefix(&Twox128::hash(b"Sudo"), Some(0), None) - .into(); - - match res { - KillStorageResult::AllRemoved(0) | KillStorageResult::SomeRemaining(0) => {}, - KillStorageResult::AllRemoved(n) | KillStorageResult::SomeRemaining(n) => { - log::error!("Remaining entries: {:?}", n); - return Err("Sudo not removed") - }, - }; - - Ok(()) - } -}