Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix try-runtime #1451

Merged
merged 1 commit into from
Oct 8, 2024
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
17 changes: 14 additions & 3 deletions pallets/asset-registry/src/migrations/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
// Check the storage version
let onchain_version = Pallet::<T>::on_chain_storage_version();
let in_code_version = Pallet::<T>::in_code_storage_version();
let on_chain_version = Pallet::<T>::on_chain_storage_version();
// Transform storage values
// We transform the storage values from the old into the new format.
if onchain_version < 1 {
if on_chain_version == 0 && in_code_version == 1 {
let mut count = 0;

log::info!(target: LOG_TARGET, "Start to migrate RegisterWhiteList storage...");
Expand Down Expand Up @@ -59,7 +60,7 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
}

// Update the storage version
StorageVersion::new(1).put::<Pallet<T>>();
in_code_version.put::<Pallet<T>>();

// Return the consumed weight
Weight::from(T::DbWeight::get().reads_writes(count as u64 + 1, count as u64 + 1))
Expand All @@ -71,6 +72,8 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
ensure!(Pallet::<T>::on_chain_storage_version() == 0, "must upgrade linearly");
ensure!(Pallet::<T>::in_code_storage_version() == 1, "must upgrade linearly");
let currency_id_to_locations_count = CurrencyIdToLocations::<T>::iter().count();
log::info!(target: LOG_TARGET, "CurrencyIdToLocations pre-migrate storage count: {:?}", currency_id_to_locations_count);

Expand All @@ -85,6 +88,14 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {

#[cfg(feature = "try-runtime")]
fn post_upgrade(cnt: Vec<u8>) -> Result<(), TryRuntimeError> {
let in_code_version = Pallet::<T>::in_code_storage_version();
let on_chain_version = Pallet::<T>::on_chain_storage_version();
ensure!(in_code_version == 1, "must_upgrade");
ensure!(
in_code_version == on_chain_version,
"after migration, the in_code_version and on_chain_version should be the same"
);

let (old_currency_id_to_locations_count, old_location_to_currency_ids_count): (u64, u64) =
Decode::decode(&mut cnt.as_slice()).expect(
"the state parameter should be something that was generated by pre_upgrade",
Expand Down
4 changes: 4 additions & 0 deletions pallets/flexible-fee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ pub mod pallet {
},
}

/// The current storage version, we set to 2 our new version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);

/// Universal fee currency order list for all users
#[pallet::storage]
pub type UniversalFeeCurrencyOrderList<T: Config> =
Expand All @@ -180,6 +183,7 @@ pub mod pallet {
>;

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);

#[pallet::error]
Expand Down
1 change: 1 addition & 0 deletions runtime/bifrost-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,7 @@ pub mod migrations {
// permanent migration, do not remove
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
bifrost_cross_in_out::migrations::v3::MigrateToV2<Runtime>,
bifrost_asset_registry::migrations::v1::MigrateToV1<Runtime>,
SystemMakerClearPalletId<Runtime>,
frame_support::migrations::RemovePallet<SystemMakerName, RocksDbWeight>,
);
Expand Down
1 change: 1 addition & 0 deletions runtime/bifrost-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,7 @@ pub mod migrations {
// permanent migration, do not remove
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
bifrost_cross_in_out::migrations::v3::MigrateToV2<Runtime>,
bifrost_asset_registry::migrations::v1::MigrateToV1<Runtime>,
frame_support::migrations::RemovePallet<SystemMakerName, RocksDbWeight>,
);
}
Expand Down