mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 18:07:58 +00:00
Fix Society v2 migration (#14421)
* fix society v2 migration * Update frame/society/src/migrations.rs * Update frame/society/src/migrations.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update frame/society/src/migrations.rs Co-authored-by: Bastian Köcher <git@kchr.de> * update for versioned upgrade * fix society v2 migration * remove references to members being sorted from commnets * fix type * fix can_migrate check * add sanity log * fix sanity check * kick ci * kick ci * run tests with --experimental flag * versioned migration cleanup * revert pipeline change * use defensive! * semicolons * defensive and doc comment * address pr comment * feature gate the versioned migration * defensive_unwrap_or * fix test * fix doc comment * change defensive to a log warning * remove can_migrate anti-pattern * Update frame/society/Cargo.toml Co-authored-by: Bastian Köcher <git@kchr.de> * add experimental feature warning to doc comment * update doc comment * bump ci * kick ci * kick ci * kick ci --------- Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -24,12 +24,8 @@ use sp_core::Get;
|
||||
use sp_io::{hashing::twox_128, storage::clear_prefix, KillStorageResult};
|
||||
use sp_std::marker::PhantomData;
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
#[cfg(feature = "experimental")]
|
||||
use crate::traits::OnRuntimeUpgrade;
|
||||
|
||||
/// EXPERIMENTAL: The API of this feature may change.
|
||||
///
|
||||
/// Make it easier to write versioned runtime upgrades.
|
||||
///
|
||||
/// [`VersionedRuntimeUpgrade`] allows developers to write migrations without worrying about
|
||||
@@ -57,13 +53,19 @@ use crate::traits::OnRuntimeUpgrade;
|
||||
/// // OnRuntimeUpgrade implementation...
|
||||
/// }
|
||||
///
|
||||
/// pub type VersionCheckedMigrateV5ToV6<Runtime, Pallet, DbWeight> =
|
||||
/// VersionedRuntimeUpgrade<5, 6, VersionUncheckedMigrateV5ToV6<Runtime>, Pallet, DbWeight>;
|
||||
/// pub type VersionCheckedMigrateV5ToV6<T, I> =
|
||||
/// VersionedRuntimeUpgrade<
|
||||
/// 5,
|
||||
/// 6,
|
||||
/// VersionUncheckedMigrateV5ToV6<T, I>,
|
||||
/// crate::pallet::Pallet<T, I>,
|
||||
/// <T as frame_system::Config>::DbWeight
|
||||
/// >;
|
||||
///
|
||||
/// // Migrations tuple to pass to the Executive pallet:
|
||||
/// pub type Migrations = (
|
||||
/// // other migrations...
|
||||
/// VersionCheckedMigrateV5ToV6<Runtime, Balances, RuntimeDbWeight>,
|
||||
/// VersionCheckedMigrateV5ToV6<T, ()>,
|
||||
/// // other migrations...
|
||||
/// );
|
||||
/// ```
|
||||
@@ -78,7 +80,7 @@ pub struct VersionedRuntimeUpgrade<const FROM: u16, const TO: u16, Inner, Pallet
|
||||
#[derive(codec::Encode, codec::Decode)]
|
||||
pub enum VersionedPostUpgradeData {
|
||||
/// The migration ran, inner vec contains pre_upgrade data.
|
||||
MigrationExecuted(Vec<u8>),
|
||||
MigrationExecuted(sp_std::vec::Vec<u8>),
|
||||
/// This migration is a noop, do not run post_upgrade checks.
|
||||
Noop,
|
||||
}
|
||||
@@ -93,16 +95,16 @@ pub enum VersionedPostUpgradeData {
|
||||
impl<
|
||||
const FROM: u16,
|
||||
const TO: u16,
|
||||
Inner: OnRuntimeUpgrade,
|
||||
Inner: crate::traits::OnRuntimeUpgrade,
|
||||
Pallet: GetStorageVersion<CurrentStorageVersion = StorageVersion> + PalletInfoAccess,
|
||||
DbWeight: Get<RuntimeDbWeight>,
|
||||
> OnRuntimeUpgrade for VersionedRuntimeUpgrade<FROM, TO, Inner, Pallet, DbWeight>
|
||||
> crate::traits::OnRuntimeUpgrade for VersionedRuntimeUpgrade<FROM, TO, Inner, Pallet, DbWeight>
|
||||
{
|
||||
/// Executes pre_upgrade if the migration will run, and wraps the pre_upgrade bytes in
|
||||
/// [`VersionedPostUpgradeData`] before passing them to post_upgrade, so it knows whether the
|
||||
/// migration ran or not.
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
|
||||
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::TryRuntimeError> {
|
||||
use codec::Encode;
|
||||
let on_chain_version = Pallet::on_chain_storage_version();
|
||||
if on_chain_version == FROM {
|
||||
@@ -152,7 +154,7 @@ impl<
|
||||
/// the migration ran, and [`VersionedPostUpgradeData::Noop`] otherwise.
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn post_upgrade(
|
||||
versioned_post_upgrade_data_bytes: Vec<u8>,
|
||||
versioned_post_upgrade_data_bytes: sp_std::vec::Vec<u8>,
|
||||
) -> Result<(), sp_runtime::TryRuntimeError> {
|
||||
use codec::DecodeAll;
|
||||
match <VersionedPostUpgradeData>::decode_all(&mut &versioned_post_upgrade_data_bytes[..])
|
||||
@@ -321,7 +323,7 @@ impl<P: Get<&'static str>, DbWeight: Get<RuntimeDbWeight>> frame_support::traits
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
|
||||
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::TryRuntimeError> {
|
||||
use crate::storage::unhashed::contains_prefixed_key;
|
||||
|
||||
let hashed_prefix = twox_128(P::get().as_bytes());
|
||||
@@ -332,11 +334,11 @@ impl<P: Get<&'static str>, DbWeight: Get<RuntimeDbWeight>> frame_support::traits
|
||||
P::get()
|
||||
),
|
||||
};
|
||||
Ok(Vec::new())
|
||||
Ok(sp_std::vec::Vec::new())
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
|
||||
fn post_upgrade(_state: sp_std::vec::Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
|
||||
use crate::storage::unhashed::contains_prefixed_key;
|
||||
|
||||
let hashed_prefix = twox_128(P::get().as_bytes());
|
||||
|
||||
Reference in New Issue
Block a user