Skip to content

Commit

Permalink
remove migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ark930 committed Sep 6, 2022
1 parent aa87583 commit 8f8d792
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 143 deletions.
84 changes: 1 addition & 83 deletions runtime/bifrost-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ pub use frame_support::{
PalletId, RuntimeDebug, StorageValue,
};
use frame_system::limits::{BlockLength, BlockWeights};
#[cfg(feature = "try-runtime")]
use node_primitives::TokenInfo;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_timestamp::Call as TimestampCall;
use pallet_xcm::QueryStatus;
Expand Down Expand Up @@ -2142,89 +2140,9 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
SlpMigration,
(),
>;

#[cfg(feature = "try-runtime")]
use bifrost_slp::{
migration::DeprecatedMinimumsMaximums, BalanceOf, MinimumsAndMaximums, MinimumsMaximums,
};
#[cfg(feature = "try-runtime")]
use frame_support::{ensure, traits::OnRuntimeUpgradeHelpersExt};
pub struct SlpMigration;
impl OnRuntimeUpgrade for SlpMigration {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
bifrost_slp::migration::update_minimums_maximums::<Runtime>()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
let mut count = 0;
let mut match_count = 0;
MinimumsAndMaximums::<Runtime>::translate::<
DeprecatedMinimumsMaximums<BalanceOf<Runtime>>,
_,
>(|_currency_id, mins_maxs| {
let new_entry = MinimumsMaximums::<BalanceOf<Runtime>> {
delegator_bonded_minimum: mins_maxs.delegator_bonded_minimum,
bond_extra_minimum: mins_maxs.bond_extra_minimum,
unbond_minimum: mins_maxs.unbond_minimum,
rebond_minimum: mins_maxs.rebond_minimum,
unbond_record_maximum: mins_maxs.unbond_record_maximum,
validators_back_maximum: mins_maxs.validators_back_maximum,
delegator_active_staking_maximum: mins_maxs.delegator_active_staking_maximum,
validators_reward_maximum: mins_maxs.validators_reward_maximum,
delegation_amount_minimum: mins_maxs.delegation_amount_minimum,
delegators_maximum: 100u16,
validators_maximum: 300u16,
};

let post_migration = MinimumsMaximums::<BalanceOf<Runtime>> {
delegator_bonded_minimum: mins_maxs.delegator_bonded_minimum,
bond_extra_minimum: mins_maxs.bond_extra_minimum,
unbond_minimum: mins_maxs.unbond_minimum,
rebond_minimum: mins_maxs.rebond_minimum,
unbond_record_maximum: mins_maxs.unbond_record_maximum,
validators_back_maximum: mins_maxs.validators_back_maximum,
delegator_active_staking_maximum: mins_maxs.delegator_active_staking_maximum,
validators_reward_maximum: mins_maxs.validators_reward_maximum,
delegation_amount_minimum: mins_maxs.delegation_amount_minimum,
delegators_maximum: 100u16,
validators_maximum: 300u16,
};

count = count + 1;

if post_migration == new_entry {
match_count = match_count + 1;
}

Some(new_entry)
});

ensure!(count == match_count, "error ...");
log::info!("count: {}", count);

Self::set_temp_storage(count, "count");

Ok(())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
let mut count = 0;
for (_currency_id, _post_migration) in bifrost_slp::MinimumsAndMaximums::<Runtime>::iter() {
count = count + 1;
}

let post_count = Self::get_temp_storage("count");

ensure!(Some(count) == post_count, "error ...");

Ok(())
}
}

#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;
Expand Down
61 changes: 1 addition & 60 deletions runtime/bifrost-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1769,68 +1769,9 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
AssetRegistryMigration,
(),
>;

pub struct AssetRegistryMigration;
impl frame_support::traits::OnRuntimeUpgrade for AssetRegistryMigration {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
let items = vec![
("Polkadot DOT", "DOT", 10_u8, 1_000_000_u128), // 0.0001 DOT
("Moonbeam Native Token", "GLMR", 18_u8, 1_000_000_000_000_u128), // 0.000001 GLMR
];
for (currency_id, metadata) in
items.iter().map(|(name, symbol, decimals, minimal_balance)| {
let token_id = AssetRegistry::get_next_token_id().expect("Next token id");
(
CurrencyId::Token2(token_id),
bifrost_asset_registry::AssetMetadata {
name: name.as_bytes().to_vec(),
symbol: symbol.as_bytes().to_vec(),
decimals: *decimals,
minimal_balance: *minimal_balance,
},
)
}) {
AssetRegistry::do_register_metadata(currency_id, &metadata).expect("Asset register");
}

let len = items.len() as Weight;
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(len, len)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
log::info!("try-runtime::pre_upgrade next_token_id: {:?}", AssetRegistry::next_token_id());
Ok(())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
log::info!("try-runtime::pre_upgrade next_token_id: {:?}", AssetRegistry::next_token_id());
assert_eq!(AssetRegistry::next_token_id(), 2);
assert_eq!(
AssetRegistry::currency_metadatas(CurrencyId::Token2(DOT_TOKEN_ID)).unwrap(),
bifrost_asset_registry::AssetMetadata {
name: "Polkadot DOT".as_bytes().to_vec(),
symbol: "DOT".as_bytes().to_vec(),
decimals: 10_u8,
minimal_balance: 1_000_000_u128,
}
);
assert_eq!(
AssetRegistry::currency_metadatas(CurrencyId::Token2(GLMR_TOKEN_ID)).unwrap(),
bifrost_asset_registry::AssetMetadata {
name: "Moonbeam Native Token".as_bytes().to_vec(),
symbol: "GLMR".as_bytes().to_vec(),
decimals: 18_u8,
minimal_balance: 1_000_000_000_000_u128,
}
);
Ok(())
}
}

#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;
Expand Down

0 comments on commit 8f8d792

Please sign in to comment.