Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Rc/0.32.0 fixes - pallets storage versions allignment #668

Merged
merged 6 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions pallets/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,17 +270,6 @@ pub mod pallet {
T::DbWeight::get().reads(2)
}
}

fn on_runtime_upgrade() -> Weight {
let onchain = Pallet::<T>::on_chain_storage_version();
if onchain == 0 {
STORAGE_VERSION.put::<Pallet<T>>();
T::DbWeight::get().reads_writes(1, 1)
} else {
log!(warn, "skipping version upgrade, remove migration");
T::DbWeight::get().reads(1)
}
}
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
109 changes: 94 additions & 15 deletions runtime/common/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,109 @@ use log::info;
use mangata_types::assets::CustomMetadata;
use sp_std::marker::PhantomData;

pub struct AssetRegistryMigration<Runtime>(PhantomData<Runtime>);
pub struct PalletsVersionsAlignment<Runtime>(PhantomData<Runtime>);

impl<T> OnRuntimeUpgrade for AssetRegistryMigration<T>
impl<T> OnRuntimeUpgrade for PalletsVersionsAlignment<T>
where
T: orml_asset_registry::Config<
CustomMetadata = CustomMetadata,
AssetId = TokenId,
Balance = Balance,
StringLimit = StringLimit,
> + orml_tokens::Config<CurrencyId = TokenId>,
T: orml_asset_registry::Config,
T: orml_tokens::Config,
T: pallet_maintenance::Config,
T: orml_unknown_tokens::Config,
T: pallet_xcm::Config,
T: pallet_bootstrap::Config,
T: pallet_crowdloan_rewards::Config,
T: pallet_fee_lock::Config,
T: cumulus_pallet_dmp_queue::Config,
T: cumulus_pallet_xcmp_queue::Config,
{
fn on_runtime_upgrade() -> Weight {
info!(
target: "asset_registry",
target: "migration::versions-alignment",
"on_runtime_upgrade: Attempted to apply AssetRegistry migration"
);

let version = orml_asset_registry::Pallet::<T>::on_chain_storage_version();
if version == 2 {
info!(target: "asset-registry", "No migration applied, remove");
T::DbWeight::get().reads(1)
let mut reads = 0;
let mut writes = 0;

// Maintanance -> 0
// currently set to null that defaults to 0
StorageVersion::new(0).put::<pallet_maintenance::Pallet<T>>();
writes += 1;

// AssetRegistry -> 2
if orml_asset_registry::Pallet::<T>::on_chain_storage_version() == 2 {
info!(target: "migration::asset-registry", "No migration applied, remove");
reads += 1;
} else {
info!(target: "migration::asset-registry", "Migration applied");
StorageVersion::new(2).put::<orml_asset_registry::Pallet<T>>();
T::DbWeight::get().reads_writes(1, 1)
}
reads += 1;
writes += 1;
};

//UnknwonTokens -> 2
if orml_unknown_tokens::Pallet::<T>::on_chain_storage_version() == 2 {
info!(target: "migration::unknown-tokens", "No migration applied, remove");
reads += 1;
} else {
info!(target: "migration::unknown-tokens", "Migration applied");
StorageVersion::new(2).put::<orml_unknown_tokens::Pallet<T>>();
reads += 1;
writes += 1;
};

// PolkadotXcm -> 1
if pallet_xcm::Pallet::<T>::on_chain_storage_version() == 1 {
info!(target: "migration::pallet_xcm", "No migration applied, remove");
reads += 1;
} else {
info!(target: "migration::pallet_xcm", "Migration applied");
StorageVersion::new(1).put::<pallet_xcm::Pallet<T>>();
reads += 1;
writes += 1;
};

// Bootstrap -> 2
if pallet_bootstrap::Pallet::<T>::on_chain_storage_version() == 2 {
info!(target: "migration::pallet_bootstrap", "No migration applied, remove");
reads += 1;
} else {
info!(target: "migration::pallet_bootstrap", "Migration applied");
StorageVersion::new(2).put::<pallet_bootstrap::Pallet<T>>();
reads += 1;
writes += 1;
};

// Crowdloan -> 1
if pallet_crowdloan_rewards::Pallet::<T>::on_chain_storage_version() == 1 {
info!(target: "migration::pallet_crowdloan_rewards", "No migration applied, remove");
reads += 1;
} else {
info!(target: "migration::pallet_crowdloan_rewards", "Migration applied");
StorageVersion::new(1).put::<pallet_crowdloan_rewards::Pallet<T>>();
reads += 1;
writes += 1;
};

// FeeLock -> 0
// currently set to null that defaults to 0
StorageVersion::new(0).put::<pallet_fee_lock::Pallet<T>>();
writes += 1;

T::DbWeight::get().reads_writes(reads, writes)
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: sp_std::vec::Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
assert_eq!(orml_asset_registry::Pallet::<T>::on_chain_storage_version(), 2);
assert_eq!(pallet_maintenance::Pallet::<T>::on_chain_storage_version(), 0);
assert_eq!(orml_unknown_tokens::Pallet::<T>::on_chain_storage_version(), 2);
assert_eq!(pallet_bootstrap::Pallet::<T>::on_chain_storage_version(), 2);
assert_eq!(pallet_crowdloan_rewards::Pallet::<T>::on_chain_storage_version(), 1);
assert_eq!(pallet_fee_lock::Pallet::<T>::on_chain_storage_version(), 0);
assert_eq!(cumulus_pallet_dmp_queue::Pallet::<T>::on_chain_storage_version(), 2);
assert_eq!(cumulus_pallet_xcmp_queue::Pallet::<T>::on_chain_storage_version(), 3);
assert_eq!(pallet_xcm::Pallet::<T>::on_chain_storage_version(), 1);
Ok(())
}
}
6 changes: 1 addition & 5 deletions runtime/mangata-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ pub type Executive = frame_executive::Executive<
Migrations,
>;

type Migrations = (
common_runtime::migration::AssetRegistryMigration<Runtime>,
pallet_xcm::migration::v1::VersionUncheckedMigrateToV1<Runtime>,
orml_unknown_tokens::Migration<Runtime>,
);
type Migrations = (common_runtime::migration::PalletsVersionsAlignment<Runtime>,);

/// 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
Expand Down
5 changes: 1 addition & 4 deletions runtime/mangata-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ pub type Executive = frame_executive::Executive<
Migrations,
>;

type Migrations = (
pallet_xcm::migration::v1::VersionUncheckedMigrateToV1<Runtime>,
orml_unknown_tokens::Migration<Runtime>,
);
type Migrations = (common_runtime::migration::PalletsVersionsAlignment<Runtime>,);

/// 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
Expand Down