Skip to content

Commit

Permalink
remove old development migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed May 20, 2024
1 parent ba41880 commit ef5af4d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 115 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion runtime/development/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "development-runtime"
version = "0.10.46"
version = "0.10.48"
build = "build.rs"
authors.workspace = true
edition.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions runtime/development/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("centrifuge-devel"),
impl_name: create_runtime_str!("centrifuge-devel"),
authoring_version: 1,
spec_version: 1047,
spec_version: 1048,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down Expand Up @@ -1994,7 +1994,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
crate::migrations::UpgradeDevelopment1047,
crate::migrations::UpgradeDevelopment1048,
>;

// Frame Order in this block dictates the index of each one in the metadata
Expand Down
112 changes: 1 addition & 111 deletions runtime/development/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,117 +11,7 @@
// GNU General Public License for more details.

use sp_core::parameter_types;
parameter_types! {
pub const CollatorReward: cfg_primitives::Balance = cfg_primitives::constants::CFG;
pub const AnnualTreasuryInflationPercent: u32 = 3;
}

/// The migration set for Development & Demo.
/// It includes all the migrations that have to be applied on that chain.
pub type UpgradeDevelopment1047 = (
pallet_collator_selection::migration::v1::MigrateToV1<crate::Runtime>,
cleanup_foreign_investments::Migration<crate::Runtime>,
// v0 -> v1
pallet_multisig::migrations::v1::MigrateToV1<crate::Runtime>,
// v0 -> v1
pallet_balances::migration::MigrateToTrackInactive<super::Runtime, super::CheckingAccount, ()>,
// v0 -> v1
runtime_common::migrations::nuke::ResetPallet<crate::Preimage, crate::RocksDbWeight, 0>,
// v0 -> v1
runtime_common::migrations::nuke::ResetPallet<crate::Democracy, crate::RocksDbWeight, 0>,
// v0 -> v1
pallet_xcm::migration::v1::VersionUncheckedMigrateToV1<crate::Runtime>,
runtime_common::migrations::increase_storage_version::Migration<crate::PoolSystem, 0, 2>,
runtime_common::migrations::increase_storage_version::Migration<crate::InterestAccrual, 0, 3>,
runtime_common::migrations::increase_storage_version::Migration<crate::Investments, 0, 1>,
runtime_common::migrations::increase_storage_version::Migration<crate::BlockRewards, 0, 2>,
runtime_common::migrations::increase_storage_version::Migration<crate::OraclePriceFeed, 0, 1>,
runtime_common::migrations::increase_storage_version::Migration<
crate::OraclePriceCollection,
0,
1,
>,
runtime_common::migrations::increase_storage_version::Migration<crate::OrmlAssetRegistry, 0, 2>,
// Reset Block rewards
runtime_common::migrations::nuke::ResetPallet<crate::BlockRewards, crate::RocksDbWeight, 0>,
pallet_block_rewards::migrations::init::InitBlockRewards<
crate::Runtime,
CollatorReward,
AnnualTreasuryInflationPercent,
>,
);

mod cleanup_foreign_investments {
use cfg_types::tokens::CurrencyId;
use frame_support::{
storage::StoragePrefixedMap,
traits::{Get, OnRuntimeUpgrade},
weights::Weight,
};
#[cfg(feature = "try-runtime")]
use runtime_common::migrations::utils::count_storage_keys;
use runtime_common::migrations::utils::remove_undecodable_storage_keys;
#[cfg(feature = "try-runtime")]
use sp_runtime::DispatchError;
#[cfg(feature = "try-runtime")]
use sp_runtime::SaturatedConversion;

pub struct Migration<T>(sp_std::marker::PhantomData<T>);

const LOG_PREFIX: &str = "CleanupForeignInvestments";
impl<T> OnRuntimeUpgrade for Migration<T>
where
T: pallet_foreign_investments::Config + frame_system::Config,
{
fn on_runtime_upgrade() -> Weight {
log::info!("{LOG_PREFIX} Initiating removal of undecodable keys");
let (reads, writes) = remove_undecodable_storage_keys::<CurrencyId>(
pallet_foreign_investments::ForeignInvestmentInfo::<T>::final_prefix(),
);

log::info!("{LOG_PREFIX} Removed {writes} undecodable keys");

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

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, DispatchError> {
let n: u32 = count_storage_keys(
pallet_foreign_investments::ForeignInvestmentInfo::<T>::final_prefix(),
);
let n_count: u32 = pallet_foreign_investments::ForeignInvestmentInfo::<T>::iter_keys()
.count()
.saturated_into();

if n == n_count {
log::info!(
"{LOG_PREFIX} Storage cleanup can be skipped because all keys can be decoded"
);
} else {
log::info!(
"{LOG_PREFIX} Failed to decode {} keys, cleanup necessary",
n.saturating_sub(n_count)
);
}

log::info!("{LOG_PREFIX} pre_upgrade done!",);

Ok(sp_std::vec![])
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_pre_state: sp_std::vec::Vec<u8>) -> Result<(), DispatchError> {
let n: u32 = count_storage_keys(
pallet_foreign_investments::ForeignInvestmentInfo::<T>::final_prefix(),
);
let n_count: u32 = pallet_foreign_investments::ForeignInvestmentInfo::<T>::iter_keys()
.count()
.saturated_into();
assert_eq!(n, n_count);

log::info!("{LOG_PREFIX} post_upgrade done with {n} remaining storage keys!",);

Ok(())
}
}
}
pub type UpgradeDevelopment1048 = ();

0 comments on commit ef5af4d

Please sign in to comment.