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: Loans demo migration #1765

Merged
merged 7 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion pallets/loans/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn migrate_from_v2_to_v3<T: Config>() -> Weight {
T::DbWeight::get().reads_writes(count + 1, count + 1)
} else {
// wrong storage version
log::info!("Loans: Migration did not execute. This probably should be removed");
log::warn!("Loans: Migration did not execute. This probably should be removed");
T::DbWeight::get().reads_writes(1, 0)
}
}
51 changes: 51 additions & 0 deletions runtime/common/src/migrations/increase_storage_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,54 @@ where
Ok(())
}
}

/// Simply bumps the storage version of a pallet
///
/// NOTE: Use with extreme caution! Must ensure beforehand that a migration is
/// not necessary
pub struct ForceMigration<P, const FROM_VERSION: u16, const TO_VERSION: u16>(
sp_std::marker::PhantomData<P>,
);
impl<P, const FROM_VERSION: u16, const TO_VERSION: u16> OnRuntimeUpgrade
for ForceMigration<P, FROM_VERSION, TO_VERSION>
where
P: GetStorageVersion<CurrentStorageVersion = StorageVersion> + PalletInfoAccess,
{
fn on_runtime_upgrade() -> Weight {
if P::on_chain_storage_version() == FROM_VERSION {
log::warn!("Double-check you really want this migration!!!!",);
log::info!(
"{LOG_PREFIX} Increasing storage version of {:?} from {:?} to {TO_VERSION:?}",
P::name(),
P::on_chain_storage_version(),
);
StorageVersion::new(TO_VERSION).put::<P>();

RocksDbWeight::get().writes(1)
} else {
log::error!(
"{LOG_PREFIX} Mismatching versions. Wanted to upgrade from \
{FROM_VERSION} but on-chain version is {:?}",
P::on_chain_storage_version(),
);
Zero::zero()
}
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::DispatchError> {
assert_eq!(
P::on_chain_storage_version(),
FROM_VERSION,
"Unexpected onchain version: Expected {FROM_VERSION:?}, received {:?}",
P::on_chain_storage_version(),
);
Ok(sp_std::vec![])
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_: sp_std::vec::Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
assert_eq!(P::on_chain_storage_version(), TO_VERSION);
Ok(())
}
}
35 changes: 2 additions & 33 deletions runtime/development/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,5 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

use cfg_types::tokens::{
usdc::{CURRENCY_ID_DOT_NATIVE, CURRENCY_ID_LOCAL, CURRENCY_ID_LP_ETH, LOCAL_ASSET_ID},
CurrencyId, LocalAssetId,
};

frame_support::parameter_types! {
pub const UsdcVariants: [CurrencyId; 1] = [CURRENCY_ID_LP_ETH];
pub const LocalAssetIdUsdc: LocalAssetId = LOCAL_ASSET_ID;
pub const LocalCurrencyIdUsdc: CurrencyId = CURRENCY_ID_LOCAL;
pub const PoolCurrencyAnemoy: CurrencyId = CURRENCY_ID_DOT_NATIVE;
pub const AnnualTreasuryInflationPercent: u32 = 3;
}

pub type UpgradeDevelopment1042 = (
// Reset pallets
runtime_common::migrations::nuke::ResetPallet<crate::OrderBook, crate::RocksDbWeight, 0>,
runtime_common::migrations::nuke::ResetPallet<
crate::TransferAllowList,
crate::RocksDbWeight,
0,
>,
// Apply relative treasury inflation
pallet_block_rewards::migrations::v2::RelativeTreasuryInflationMigration<
crate::Runtime,
AnnualTreasuryInflationPercent,
>,
// Apply version bump to 1 (storage already reset)
runtime_common::migrations::increase_storage_version::Migration<
crate::ForeignInvestments,
0,
1,
>,
);
pub type UpgradeDevelopment1042 =
(runtime_common::migrations::increase_storage_version::ForceMigration<crate::Loans, 0, 2>,);
Loading