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

Remove old migrations for development 1047 #1840

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had this not updated, although I guess it's not a problem

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this often falls short but it doesn't have any effect anyways.

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
114 changes: 1 addition & 113 deletions runtime/development/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,118 +10,6 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// 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 = ();
Loading