From ac47879e1afd24df76380ef35db07bae4718f61d Mon Sep 17 00:00:00 2001 From: yooml Date: Wed, 6 Sep 2023 15:24:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20rm=20migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pallets/lend-market/src/lib.rs | 10 +- pallets/lend-market/src/migrations.rs | 178 -------------------------- 2 files changed, 2 insertions(+), 186 deletions(-) delete mode 100644 pallets/lend-market/src/migrations.rs diff --git a/pallets/lend-market/src/lib.rs b/pallets/lend-market/src/lib.rs index 0af36f764..cb06c61f4 100644 --- a/pallets/lend-market/src/lib.rs +++ b/pallets/lend-market/src/lib.rs @@ -71,7 +71,6 @@ mod lend_token; mod rate_model; mod types; -pub mod migrations; pub mod weights; pub const MAX_INTEREST_CALCULATING_INTERVAL: u64 = 5 * 24 * 3600; // 5 days @@ -89,12 +88,7 @@ type BalanceOf = /// Utility type for managing upgrades/migrations. #[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo)] pub enum Versions { - V1, - V2, - V3, - V4, - V5, - V6, + V0, } #[frame_support::pallet] @@ -454,7 +448,7 @@ pub mod pallet { /// DefaultVersion is using for initialize the StorageVersion #[pallet::type_value] pub(super) fn DefaultVersion() -> Versions { - Versions::V2 + Versions::V0 } /// Storage version of the pallet. diff --git a/pallets/lend-market/src/migrations.rs b/pallets/lend-market/src/migrations.rs deleted file mode 100644 index b149a6768..000000000 --- a/pallets/lend-market/src/migrations.rs +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright 2021-2022 Parallel Finance Developer. -// This file is part of Parallel Finance. - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::*; - -pub mod v3 { - use super::*; - use crate::{pallet::StorageVersion, Config, Weight}; - use frame_support::{log, traits::Get}; - - pub const DEFAULT_LIQUIDATE_INCENTIVE_RESERVED_FACTOR: Ratio = Ratio::from_percent(3); - pub const DEFAULT_LIQUIDATION_OFFSET: Ratio = Ratio::from_percent(10); - - #[cfg_attr(feature = "std", derive(serde::Deserialize, serde::Serialize))] - #[derive(Clone, PartialEq, Eq, codec::Decode, codec::Encode, RuntimeDebug, TypeInfo)] - pub struct V2Market { - /// The collateral utilization ratio - pub collateral_factor: Ratio, - /// Fraction of interest currently set aside for reserves - pub reserve_factor: Ratio, - /// The percent, ranging from 0% to 100%, of a liquidatable account's - /// borrow that can be repaid in a single liquidate transaction. - pub close_factor: Ratio, - /// Liquidation incentive ratio - pub liquidate_incentive: Rate, - /// Current interest rate model being used - pub rate_model: InterestRateModel, - /// Current market state - pub state: MarketState, - /// Upper bound of supplying - pub supply_cap: Balance, - /// Upper bound of borrowing - pub borrow_cap: Balance, - /// Ptoken asset id - pub lend_token_id: CurrencyId, - } - #[frame_support::storage_alias] - type MarketRewardSpeed = - StorageMap, Blake2_128Concat, AssetIdOf, BalanceOf>; - - #[frame_support::storage_alias] - type RewardAccured = StorageMap< - crate::Pallet, - Blake2_128Concat, - ::AccountId, - BalanceOf, - >; - - #[frame_support::storage_alias] - type LastAccruedTimestamp = StorageValue, Timestamp, ValueQuery>; - - #[cfg(feature = "try-runtime")] - pub fn pre_migrate() -> Result<(), &'static str> { - #[frame_support::storage_alias] - type Markets = - StorageMap, Blake2_128Concat, AssetIdOf, V2Market>>; - frame_support::ensure!( - StorageVersion::::get() == crate::Versions::V2, - "must upgrade linearly" - ); - Markets::::iter().for_each(|(asset_id, _)| { - log::info!("market {:#?} need to migrate", asset_id,); - }); - let reward_speed_count = MarketRewardSpeed::::iter().count(); - log::info!("total {:#?} reward speed items need to migrate", reward_speed_count); - - let last_accrued_timestamp = LastAccruedTimestamp::::get(); - log::info!("LastAccruedTimestamp: {:#?} is about to move.", last_accrued_timestamp); - - let old_name_items_count = RewardAccured::::iter().count(); - let new_name_items_count = RewardAccrued::::iter().count(); - log::info!( - "old_name_items_count: {:#?}, new_name_items_count: {:#?}.", - old_name_items_count, - new_name_items_count, - ); - - log::info!("👜 lend-market v3 migration passes PRE migrate checks ✅",); - - Ok(()) - } - - /// Migration to sorted [`SortedListProvider`]. - pub fn migrate() -> Weight { - if StorageVersion::::get() == crate::Versions::V2 { - log::info!("migrating lend-market to Versions::V3",); - - Markets::::translate::>, _>(|_key, market| { - Some(Market { - borrow_cap: market.borrow_cap, - supply_cap: market.supply_cap, - collateral_factor: market.collateral_factor, - liquidation_threshold: (market.collateral_factor + - market.collateral_factor * DEFAULT_LIQUIDATION_OFFSET), - reserve_factor: market.reserve_factor, - close_factor: market.close_factor, - liquidate_incentive_reserved_factor: - DEFAULT_LIQUIDATE_INCENTIVE_RESERVED_FACTOR, - liquidate_incentive: market.liquidate_incentive, - rate_model: market.rate_model, - state: market.state, - lend_token_id: market.lend_token_id, - }) - }); - - MarketRewardSpeed::::iter().for_each(|(asset_id, reward_speed)| { - RewardSupplySpeed::::insert(asset_id, reward_speed); - RewardBorrowSpeed::::insert(asset_id, reward_speed); - }); - - //remove old data. - let _ = MarketRewardSpeed::::clear(u32::max_value(), None); - LastAccruedTimestamp::::kill(); - - StorageVersion::::put(crate::Versions::V3); - log::info!("👜 completed lend-market migration to Versions::V3",); - - T::BlockWeights::get().max_block - } else { - T::DbWeight::get().reads(1) - } - } - - #[cfg(feature = "try-runtime")] - pub fn post_migrate() -> Result<(), &'static str> { - frame_support::ensure!( - StorageVersion::::get() == crate::Versions::V3, - "must upgrade to V3" - ); - Markets::::iter().for_each(|(asset_id, market)| { - log::info!( - "market {:#?}, collateral_factor {:?}, liquidation_threshold {:?}, liquidate_incentive_reserved_factor {:?}", - asset_id, - market.collateral_factor, - market.liquidation_threshold, - market.liquidate_incentive_reserved_factor - ); - }); - RewardSupplySpeed::::iter().for_each(|(asset_id, supply_reward_speed)| { - let borrow_reward_speed = RewardBorrowSpeed::::get(asset_id); - log::info!( - "market {:#?}, supply_reward_speed {:?}, borrow_reward_speed {:?}", - asset_id, - supply_reward_speed, - borrow_reward_speed - ); - }); - - let reward_speed_count = MarketRewardSpeed::::iter().count(); - log::info!("total {:#?} reward speed items remains after migrate", reward_speed_count); - - let last_accrued_timestamp = LastAccruedTimestamp::::get(); - log::info!("LastAccruedTimestamp: {:#?} after migrate.", last_accrued_timestamp); - - let old_name_items_count = RewardAccured::::iter().count(); - let new_name_items_count = RewardAccrued::::iter().count(); - log::info!( - "old_name_items_count: {:#?}, new_name_items_count: {:#?}.", - old_name_items_count, - new_name_items_count, - ); - - log::info!("👜 lend-market v3 migration passes POST migrate checks ✅",); - - Ok(()) - } -}