diff --git a/Cargo.lock b/Cargo.lock index 7d2aec7998..3b18c1ef1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8811,6 +8811,8 @@ dependencies = [ "attestation", "ctype", "cumulus-primitives-core", + "delegation", + "did", "frame-support", "frame-system", "kilt-asset-dids", @@ -8818,8 +8820,11 @@ dependencies = [ "log", "pallet-authorship", "pallet-balances", + "pallet-did-lookup", + "pallet-inflation", "pallet-membership", "pallet-transaction-payment", + "pallet-web3-names", "parachain-staking", "parity-scale-codec", "polkadot-parachain", diff --git a/pallets/ctype/src/lib.rs b/pallets/ctype/src/lib.rs index 61758d8a2d..5f33bc7a4b 100644 --- a/pallets/ctype/src/lib.rs +++ b/pallets/ctype/src/lib.rs @@ -73,7 +73,7 @@ pub mod pallet { use crate::ctype_entry::CtypeEntry; /// The current storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); /// Type of a CType hash. pub type CtypeHashOf = ::Hash; diff --git a/runtimes/common/Cargo.toml b/runtimes/common/Cargo.toml index 91e85925b8..97b5fc6f33 100644 --- a/runtimes/common/Cargo.toml +++ b/runtimes/common/Cargo.toml @@ -24,9 +24,14 @@ smallvec.workspace = true # Internal dependencies attestation.workspace = true ctype.workspace = true +delegation = {workspace = true, optional = true} +did = {workspace = true, optional = true} +pallet-did-lookup = {workspace = true, optional = true} +pallet-inflation = {workspace = true, optional = true} kilt-support.workspace = true parachain-staking.workspace = true public-credentials.workspace = true +pallet-web3-names.workspace = true # Substrate dependencies frame-support.workspace = true @@ -97,11 +102,15 @@ std = [ ] try-runtime = [ "attestation/try-runtime", + "delegation", + "did", "frame-support/try-runtime", "frame-system/try-runtime", "kilt-support/try-runtime", "pallet-authorship/try-runtime", "pallet-balances/try-runtime", + "pallet-did-lookup", + "pallet-inflation", "pallet-membership/try-runtime", "pallet-transaction-payment/try-runtime", "parachain-staking/try-runtime", diff --git a/runtimes/common/src/migrations.rs b/runtimes/common/src/migrations.rs index 76f2a8e6b6..413e3e8227 100644 --- a/runtimes/common/src/migrations.rs +++ b/runtimes/common/src/migrations.rs @@ -30,7 +30,9 @@ pub struct AddCTypeBlockNumber(PhantomData); impl OnRuntimeUpgrade for AddCTypeBlockNumber { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { - assert_eq!(ctype::Pallet::::on_chain_storage_version(), 0,); + // Missed the migration when v1 was introduced, so now Spiritnet and Peregrine + // are on v0 although they should be on v1. + assert!(ctype::Pallet::::on_chain_storage_version() <= 1,); // Use iter_keys() on new storage so it won't try to decode values. let ctypes_to_migrate = ctype::Ctypes::::iter_keys().count() as u64; @@ -44,7 +46,7 @@ impl OnRuntimeUpgrade for AddCTypeBlockNumber { let onchain = ctype::Pallet::::on_chain_storage_version(); log::info!( - "💰 Running migration with current storage version {:?} / onchain {:?}", + "💰 Running CType migration with current storage version {:?} / onchain {:?}", current, onchain ); @@ -67,7 +69,7 @@ impl OnRuntimeUpgrade for AddCTypeBlockNumber { #[cfg(feature = "try-runtime")] fn post_upgrade(state: Vec) -> Result<(), &'static str> { - assert_eq!(ctype::Pallet::::on_chain_storage_version(), 1); + assert_eq!(ctype::Pallet::::on_chain_storage_version(), 2); let initial_ctype_count = u64::from_be_bytes(state.try_into().expect("input state should be 8 bytes")); assert_eq!(initial_ctype_count, ctype::Ctypes::::iter().count() as u64); @@ -81,3 +83,209 @@ impl OnRuntimeUpgrade for AddCTypeBlockNumber { Ok(()) } } + +pub struct MigrateToNewStorageVersion(PhantomData); + +impl MigrateToNewStorageVersion +where + R: attestation::Config + pallet_web3_names::Config + public_credentials::Config, +{ + fn migrate() -> frame_support::weights::Weight { + type AttestationPallet = attestation::Pallet; + type Web3NamesPallet = pallet_web3_names::Pallet; + type PublicCredentialsPallet = public_credentials::Pallet; + + AttestationPallet::::current_storage_version().put::>(); + // Not an issue with Peregrine, but it is with Spiritnet. + Web3NamesPallet::::current_storage_version().put::>(); + PublicCredentialsPallet::::current_storage_version().put::>(); + + ::DbWeight::get().writes(3) + } +} + +#[cfg(feature = "try-runtime")] +impl OnRuntimeUpgrade for MigrateToNewStorageVersion +where + R: attestation::Config + + ctype::Config + + delegation::Config + + did::Config + + pallet_did_lookup::Config + + pallet_inflation::Config + + pallet_web3_names::Config + + parachain_staking::Config + + public_credentials::Config, +{ + fn pre_upgrade() -> Result, &'static str> { + type AttestationPallet = attestation::Pallet; + type DelegationPallet = delegation::Pallet; + type DidPallet = did::Pallet; + type LookupPallet = pallet_did_lookup::Pallet; + type InflationPallet = pallet_inflation::Pallet; + type Web3NamesPallet = pallet_web3_names::Pallet; + type ParachainStakingPallet = parachain_staking::Pallet; + type PublicCredentialsPallet = public_credentials::Pallet; + + log::info!("💿 Storage version pre checks"); + + if AttestationPallet::::on_chain_storage_version() != AttestationPallet::::current_storage_version() { + log::warn!( + "🚨 Attestation pallet on chain version {:?} != declared storage version {:?}.", + AttestationPallet::::on_chain_storage_version(), + AttestationPallet::::current_storage_version() + ) + } + if DelegationPallet::::on_chain_storage_version() != DelegationPallet::::current_storage_version() { + log::warn!( + "🚨 Delegation pallet on chain version {:?} != declared storage version {:?}.", + DelegationPallet::::on_chain_storage_version(), + DelegationPallet::::current_storage_version() + ) + } + if DidPallet::::on_chain_storage_version() != DidPallet::::current_storage_version() { + log::warn!( + "🚨 Did pallet on chain version {:?} != declared storage version {:?}.", + DidPallet::::on_chain_storage_version(), + DidPallet::::current_storage_version() + ) + } + if LookupPallet::::on_chain_storage_version() != LookupPallet::::current_storage_version() { + log::warn!( + "🚨 Lookup pallet on chain version {:?} != declared storage version {:?}.", + LookupPallet::::on_chain_storage_version(), + LookupPallet::::current_storage_version() + ) + } + if InflationPallet::::on_chain_storage_version() != InflationPallet::::current_storage_version() { + log::warn!( + "🚨 Inflation pallet on chain version {:?} != declared storage version {:?}.", + InflationPallet::::on_chain_storage_version(), + InflationPallet::::current_storage_version() + ) + } + if Web3NamesPallet::::on_chain_storage_version() != Web3NamesPallet::::current_storage_version() { + log::warn!( + "🚨 Web3names pallet on chain version {:?} != declared storage version {:?}.", + Web3NamesPallet::::on_chain_storage_version(), + Web3NamesPallet::::current_storage_version() + ) + } + if ParachainStakingPallet::::on_chain_storage_version() + != ParachainStakingPallet::::current_storage_version() + { + log::warn!( + "🚨 Parachain staking pallet on chain version {:?} != declared storage version {:?}.", + ParachainStakingPallet::::on_chain_storage_version(), + ParachainStakingPallet::::current_storage_version() + ) + } + if PublicCredentialsPallet::::on_chain_storage_version() + != PublicCredentialsPallet::::current_storage_version() + { + log::warn!( + "🚨 Public credentials pallet on chain version {:?} != declared storage version {:?}.", + PublicCredentialsPallet::::on_chain_storage_version(), + PublicCredentialsPallet::::current_storage_version() + ) + } + + Ok(Vec::default()) + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + Self::migrate() + } + + fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + type AttestationPallet = attestation::Pallet; + type CTypePallet = ctype::Pallet; + type DelegationPallet = delegation::Pallet; + type DidPallet = did::Pallet; + type LookupPallet = pallet_did_lookup::Pallet; + type InflationPallet = pallet_inflation::Pallet; + type Web3NamesPallet = pallet_web3_names::Pallet; + type ParachainStakingPallet = parachain_staking::Pallet; + type PublicCredentialsPallet = public_credentials::Pallet; + + assert_eq!( + AttestationPallet::::on_chain_storage_version(), + AttestationPallet::::current_storage_version(), + "Attestation pallet on chain version {:?} != declared storage version {:?}.", + AttestationPallet::::on_chain_storage_version(), + AttestationPallet::::current_storage_version() + ); + // Although it's part of a different migration, we check that the CType pallet + // storage version is also consistent. + assert_eq!( + CTypePallet::::on_chain_storage_version(), + CTypePallet::::current_storage_version(), + "CType pallet on chain version {:?} != declared storage version {:?}.", + CTypePallet::::on_chain_storage_version(), + CTypePallet::::current_storage_version() + ); + assert_eq!( + DelegationPallet::::on_chain_storage_version(), + DelegationPallet::::current_storage_version(), + "Delegation pallet on chain version {:?} != declared storage version {:?}.", + DelegationPallet::::on_chain_storage_version(), + DelegationPallet::::current_storage_version() + ); + assert_eq!( + DidPallet::::on_chain_storage_version(), + DidPallet::::current_storage_version(), + "Did pallet on chain version {:?} != declared storage version {:?}.", + DidPallet::::on_chain_storage_version(), + DidPallet::::current_storage_version() + ); + assert_eq!( + LookupPallet::::on_chain_storage_version(), + LookupPallet::::current_storage_version(), + "Lookup pallet on chain version {:?} != declared storage version {:?}.", + LookupPallet::::on_chain_storage_version(), + LookupPallet::::current_storage_version() + ); + assert_eq!( + InflationPallet::::on_chain_storage_version(), + InflationPallet::::current_storage_version(), + "Inflation pallet on chain version {:?} != declared storage version {:?}.", + InflationPallet::::on_chain_storage_version(), + InflationPallet::::current_storage_version() + ); + assert_eq!( + Web3NamesPallet::::on_chain_storage_version(), + Web3NamesPallet::::current_storage_version(), + "Web3names pallet on chain version {:?} != declared storage version {:?}.", + Web3NamesPallet::::on_chain_storage_version(), + Web3NamesPallet::::current_storage_version() + ); + assert_eq!( + ParachainStakingPallet::::on_chain_storage_version(), + ParachainStakingPallet::::current_storage_version(), + "Parachain staking pallet on chain version {:?} != declared storage version {:?}.", + ParachainStakingPallet::::on_chain_storage_version(), + ParachainStakingPallet::::current_storage_version() + ); + assert_eq!( + PublicCredentialsPallet::::on_chain_storage_version(), + PublicCredentialsPallet::::current_storage_version(), + "Public credentials pallet on chain version {:?} != declared storage version {:?}.", + PublicCredentialsPallet::::on_chain_storage_version(), + PublicCredentialsPallet::::current_storage_version() + ); + + log::info!("💿 Storage version post checks ok ✅"); + + Ok(()) + } +} + +#[cfg(not(feature = "try-runtime"))] +impl OnRuntimeUpgrade for MigrateToNewStorageVersion +where + R: attestation::Config + pallet_web3_names::Config + public_credentials::Config, +{ + fn on_runtime_upgrade() -> frame_support::weights::Weight { + Self::migrate() + } +} diff --git a/runtimes/peregrine/src/lib.rs b/runtimes/peregrine/src/lib.rs index 9c4309e8f6..df4fd561aa 100644 --- a/runtimes/peregrine/src/lib.rs +++ b/runtimes/peregrine/src/lib.rs @@ -51,7 +51,7 @@ use xcm_executor::XcmExecutor; use delegation::DelegationAc; use kilt_support::traits::ItemFilter; -use pallet_did_lookup::{linkable_account::LinkableAccountId, migrations::EthereumMigration}; +use pallet_did_lookup::linkable_account::LinkableAccountId; pub use parachain_staking::InflationInfo; pub use public_credentials; @@ -1067,8 +1067,11 @@ pub type Executive = frame_executive::Executive< pallet_preimage::migration::v1::Migration, pallet_scheduler::migration::v3::MigrateToV4, pallet_democracy::migrations::v1::Migration, + pallet_did_lookup::migrations::EthereumMigration, runtime_common::migrations::AddCTypeBlockNumber, - EthereumMigration, + // The migration above must be run as last since it checks that all pallets are using the new StorageVersion + // properly. + runtime_common::migrations::MigrateToNewStorageVersion, ), >; diff --git a/runtimes/spiritnet/src/lib.rs b/runtimes/spiritnet/src/lib.rs index 8710383180..13d3750ee0 100644 --- a/runtimes/spiritnet/src/lib.rs +++ b/runtimes/spiritnet/src/lib.rs @@ -51,7 +51,7 @@ use xcm_executor::XcmExecutor; use delegation::DelegationAc; use kilt_support::traits::ItemFilter; -use pallet_did_lookup::{linkable_account::LinkableAccountId, migrations::EthereumMigration}; +use pallet_did_lookup::linkable_account::LinkableAccountId; pub use parachain_staking::InflationInfo; pub use public_credentials; @@ -1063,8 +1063,11 @@ pub type Executive = frame_executive::Executive< pallet_preimage::migration::v1::Migration, pallet_scheduler::migration::v3::MigrateToV4, pallet_democracy::migrations::v1::Migration, + pallet_did_lookup::migrations::EthereumMigration, runtime_common::migrations::AddCTypeBlockNumber, - EthereumMigration, + // The migration above must be run as last since it checks that all pallets are using the new StorageVersion + // properly. + runtime_common::migrations::MigrateToNewStorageVersion, ), >;