diff --git a/Cargo.lock b/Cargo.lock index c7a9f93826..72c931060c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8885,6 +8885,9 @@ dependencies = [ "attestation", "frame-support", "frame-system", + "frame-try-runtime", + "hex-literal", + "log", "pallet-authorship", "pallet-balances", "pallet-membership", diff --git a/runtimes/common/Cargo.toml b/runtimes/common/Cargo.toml index 15e2b9a106..7141786609 100644 --- a/runtimes/common/Cargo.toml +++ b/runtimes/common/Cargo.toml @@ -9,6 +9,8 @@ sp-io = {git = "https://github.com/paritytech/substrate", default-features = fal [dependencies] codec = {package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"]} +hex-literal = "0.3.4" +log = "0.4.16" scale-info = {version = "2.0.1", default-features = false, features = ["derive"]} serde = {version = "1.0.132", optional = true, features = ["derive"]} smallvec = "1.8.0" @@ -24,9 +26,13 @@ pallet-membership = {git = "https://github.com/paritytech/substrate", default-fe pallet-transaction-payment = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} sp-consensus-aura = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} sp-core = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} +sp-io = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} sp-std = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} +# Runtime tests +frame-try-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19", optional = true} + [features] default = ["std"] fast-gov = [] @@ -50,6 +56,11 @@ std = [ "serde", "sp-consensus-aura/std", "sp-core/std", + "sp-io/std", "sp-runtime/std", "sp-std/std", ] +try-runtime = [ + "frame-support/try-runtime", + "frame-try-runtime", +] diff --git a/runtimes/common/src/lib.rs b/runtimes/common/src/lib.rs index c05f191df8..70f5cb27e8 100644 --- a/runtimes/common/src/lib.rs +++ b/runtimes/common/src/lib.rs @@ -45,6 +45,7 @@ use sp_std::marker::PhantomData; pub mod authorization; pub mod constants; pub mod fees; +pub mod migrations; pub mod pallet_id; #[cfg(feature = "runtime-benchmarks")] diff --git a/runtimes/common/src/migrations.rs b/runtimes/common/src/migrations.rs new file mode 100644 index 0000000000..1e938c65ee --- /dev/null +++ b/runtimes/common/src/migrations.rs @@ -0,0 +1,75 @@ +// KILT Blockchain – https://botlabs.org +// Copyright (C) 2019-2022 BOTLabs GmbH + +// The KILT Blockchain 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. + +// The KILT Blockchain 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 this program. If not, see . + +// If you feel like getting in touch with us, you can do so at info@botlabs.org + +use core::marker::PhantomData; +use frame_support::traits::Get; +use hex_literal::hex; + +pub struct RemoveKiltLaunch(PhantomData); +impl frame_support::traits::OnRuntimeUpgrade for RemoveKiltLaunch { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let items = match frame_support::storage::unhashed::kill_prefix(&hex!("37be294ab4b5aa76f1df3f80e7c180ef"), None) + { + sp_io::KillStorageResult::AllRemoved(n) => { + log::info!("🚀 Successfully removed all {} storage items of the launch pallet", n); + n + } + sp_io::KillStorageResult::SomeRemaining(n) => { + log::warn!( + "🚀 Failed to remove all storage items of the launch pallet, {} are remaining", + n + ); + n + } + }; + ::DbWeight::get().writes(items.into()) + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result<(), &'static str> { + // FIXME: Why does this fail? + log::info!( + "🚀 Pre check: Launch pallet storage exists {}?", + frame_support::storage::migration::have_storage_value( + &hex!("37be294ab4b5aa76f1df3f80e7c180ef"), + // b"KiltLaunch" + b"TransferAccount", + &[] + ) + ); + + assert!(frame_support::storage::migration::have_storage_value( + &hex!("37be294ab4b5aa76f1df3f80e7c180ef"), + // b"KiltLaunch", + b"TransferAccount", + &[] + )); + Ok(()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade() -> Result<(), &'static str> { + match frame_support::storage::unhashed::kill_prefix(&hex!("37be294ab4b5aa76f1df3f80e7c180ef"), Some(1)) { + sp_io::KillStorageResult::AllRemoved(0) => { + log::info!("🚀 Post check: Launch pallet storage successfully removed"); + Ok(()) + } + _ => Err("🚀 Post check: Launch pallet storage still exists!"), + } + } +} diff --git a/runtimes/peregrine/src/lib.rs b/runtimes/peregrine/src/lib.rs index 313dd83139..b3be6975ac 100644 --- a/runtimes/peregrine/src/lib.rs +++ b/runtimes/peregrine/src/lib.rs @@ -981,7 +981,7 @@ pub type Executive = frame_executive::Executive< // Executes pallet hooks in reverse order of definition in construct_runtime // If we want to switch to AllPalletsWithSystem, we need to reorder the staking pallets AllPalletsReversedWithSystemFirst, - pallet_did_lookup::migrations::LookupReverseIndexMigration, + runtime_common::migrations::RemoveKiltLaunch, >; impl_runtime_apis! { diff --git a/runtimes/spiritnet/Cargo.toml b/runtimes/spiritnet/Cargo.toml index 1e426854b7..9d8ffce70c 100644 --- a/runtimes/spiritnet/Cargo.toml +++ b/runtimes/spiritnet/Cargo.toml @@ -230,4 +230,5 @@ try-runtime = [ "pallet-utility/try-runtime", "pallet-vesting/try-runtime", "parachain-staking/try-runtime", + "runtime-common/try-runtime", ] diff --git a/runtimes/spiritnet/src/lib.rs b/runtimes/spiritnet/src/lib.rs index 4b7e9e889c..72b248b571 100644 --- a/runtimes/spiritnet/src/lib.rs +++ b/runtimes/spiritnet/src/lib.rs @@ -984,7 +984,7 @@ pub type Executive = frame_executive::Executive< // Executes pallet hooks in reverse order of definition in construct_runtime // If we want to switch to AllPalletsWithSystem, we need to reorder the staking pallets AllPalletsReversedWithSystemFirst, - pallet_did_lookup::migrations::LookupReverseIndexMigration, + runtime_common::migrations::RemoveKiltLaunch, >; impl_runtime_apis! {