From 5b86ab8588563b6daa68b6bf942135a39001ed07 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Tue, 3 Sep 2024 11:26:11 +0200 Subject: [PATCH] delete funding storage migrations --- pallets/funding/src/storage_migrations.rs | 331 +--------------------- runtimes/polimec/src/lib.rs | 1 - 2 files changed, 1 insertion(+), 331 deletions(-) diff --git a/pallets/funding/src/storage_migrations.rs b/pallets/funding/src/storage_migrations.rs index 4b6042677..e961157b1 100644 --- a/pallets/funding/src/storage_migrations.rs +++ b/pallets/funding/src/storage_migrations.rs @@ -2,333 +2,4 @@ use frame_support::traits::StorageVersion; /// The current storage version pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(5); -pub const LOG: &str = "runtime::funding::migration"; - -pub mod v5 { - use crate::{ - AccountIdOf, BalanceOf, BlockNumberPair, CheckOutcome, Config, EvaluationRoundInfoOf, EvaluatorsOutcome, - FixedPointNumber, FundingOutcome, HRMPChannelStatus, Pallet, PriceOf, ProjectDetailsOf, ProjectStatus, - RewardInfo, - }; - use core::marker::PhantomData; - use frame_support::traits::{tokens::Balance as BalanceT, UncheckedOnRuntimeUpgrade}; - use frame_system::pallet_prelude::BlockNumberFor; - use polimec_common::credentials::Did; - use polkadot_parachain_primitives::primitives::Id as ParaId; - use scale_info::TypeInfo; - use serde::{Deserialize, Serialize}; - use sp_core::{Decode, Encode, Get, MaxEncodedLen, RuntimeDebug}; - use sp_runtime::traits::One; - - #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] - pub struct OldProjectDetails< - AccountId, - Did, - BlockNumber, - Price: FixedPointNumber, - Balance: BalanceT, - EvaluationRoundInfo, - > { - pub issuer_account: AccountId, - pub issuer_did: Did, - /// Whether the project is frozen, so no `metadata` changes are allowed. - pub is_frozen: bool, - /// The price in USD per token decided after the Auction Round - pub weighted_average_price: Option, - /// The current status of the project - pub status: OldProjectStatus, - /// When the different project phases start and end - pub phase_transition_points: OldPhaseTransitionPoints, - /// Fundraising target amount in USD (6 decimals) - pub fundraising_target_usd: Balance, - /// The amount of Contribution Tokens that have not yet been sold - pub remaining_contribution_tokens: Balance, - /// Funding reached amount in USD (6 decimals) - pub funding_amount_reached_usd: Balance, - /// Information about the total amount bonded, and the outcome in regards to reward/slash/nothing - pub evaluation_round_info: EvaluationRoundInfo, - /// If the auction was oversubscribed, how much USD was raised across all winning bids - pub usd_bid_on_oversubscription: Option, - /// When the Funding Round ends - pub funding_end_block: Option, - pub migration_type: Option, - } - #[derive( - Default, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen, Serialize, Deserialize, - )] - pub enum OldProjectStatus { - #[default] - Application, - EvaluationRound, - AuctionInitializePeriod, - AuctionOpening, - AuctionClosing, - CalculatingWAP, - CommunityRound, - RemainderRound, - FundingFailed, - AwaitingProjectDecision, - FundingSuccessful, - SettlementStarted(OldFundingOutcome), - SettlementFinished(OldFundingOutcome), - CTMigrationStarted, - CTMigrationFinished, - } - - #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen, Serialize, Deserialize)] - pub enum OldFundingOutcome { - FundingSuccessful, - FundingFailed, - } - - #[derive(Default, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] - pub struct OldPhaseTransitionPoints { - pub application: OldBlockNumberPair, - pub evaluation: OldBlockNumberPair, - pub auction_initialize_period: OldBlockNumberPair, - pub auction_opening: OldBlockNumberPair, - pub random_closing_ending: Option, - pub auction_closing: OldBlockNumberPair, - pub community: OldBlockNumberPair, - pub remainder: OldBlockNumberPair, - } - - #[derive(Default, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] - pub struct OldBlockNumberPair { - pub start: Option, - pub end: Option, - } - - #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] - pub struct OldEvaluationRoundInfo { - pub total_bonded_usd: Balance, - pub total_bonded_plmc: Balance, - pub evaluators_outcome: OldEvaluatorsOutcome, - } - - #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] - pub enum OldEvaluatorsOutcome { - Unchanged, - Rewarded(RewardInfo), - Slashed, - } - - #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] - pub enum OldMigrationType { - Offchain, - Pallet(OldPalletMigrationInfo), - } - - #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] - pub struct OldPalletMigrationInfo { - /// ParaId of project - pub parachain_id: ParaId, - /// HRMP Channel status - pub hrmp_channel_status: HRMPChannelStatus, - /// Migration readiness check - pub migration_readiness_check: Option, - } - - #[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] - pub struct OldPalletMigrationReadinessCheck { - pub holding_check: (xcm::v3::QueryId, CheckOutcome), - pub pallet_check: (xcm::v3::QueryId, CheckOutcome), - } - - type OldProjectDetailsOf = OldProjectDetails< - AccountIdOf, - Did, - BlockNumberFor, - PriceOf, - BalanceOf, - OldEvaluationRoundInfo>, - >; - - pub struct UncheckedMigrationToV5(PhantomData); - impl UncheckedOnRuntimeUpgrade for UncheckedMigrationToV5 { - fn on_runtime_upgrade() -> frame_support::weights::Weight { - let mut items = 0; - log::info!("Starting migration to V5"); - let mut translate_project_details = |key, item: OldProjectDetailsOf| -> Option> { - items += 1; - log::info!("project_details item {:?}", items); - let round_duration: BlockNumberPair>; - let new_status = match item.status { - OldProjectStatus::Application => { - let start = - item.phase_transition_points.application.start.expect("Application start block is missing"); - let end = - item.phase_transition_points.application.end.expect("Application end block is missing"); - round_duration = BlockNumberPair::new(Some(start), Some(end)); - ProjectStatus::Application - }, - OldProjectStatus::EvaluationRound => { - let start = - item.phase_transition_points.evaluation.start.expect("Evaluation start block is missing"); - let end = item.phase_transition_points.evaluation.end.expect("Evaluation end block is missing"); - round_duration = BlockNumberPair::new(Some(start), Some(end)); - ProjectStatus::EvaluationRound - }, - OldProjectStatus::AuctionInitializePeriod => { - let now = frame_system::Pallet::::block_number(); - let start = now; - let end = now + ::AuctionRoundDuration::get(); - round_duration = BlockNumberPair::new(Some(start), Some(end)); - debug_assert!(false, "AuctionInitializePeriod is not supported in V5, no project should be in this state when upgrading storage"); - log::error!("AuctionInitializePeriod is not supported in V5, no project should be in this state when upgrading storage"); - ProjectStatus::AuctionRound - }, - OldProjectStatus::AuctionOpening => { - let start = item - .phase_transition_points - .auction_opening - .start - .expect("AuctionOpening start block is missing"); - let end = start + ::AuctionRoundDuration::get(); - round_duration = BlockNumberPair::new(Some(start), Some(end)); - debug_assert!(false, "AuctionOpening is not supported in V5, no project should be in this state when upgrading storage"); - log::error!("AuctionOpening is not supported in V5, no project should be in this state when upgrading storage"); - ProjectStatus::AuctionRound - }, - OldProjectStatus::AuctionClosing => { - let start = item - .phase_transition_points - .auction_opening - .start - .expect("AuctionOpening start block is missing"); - let end = start + ::AuctionRoundDuration::get(); - round_duration = BlockNumberPair::new(Some(start), Some(end)); - debug_assert!(false, "AuctionClosing is not supported in V5, no project should be in this state when upgrading storage"); - log::error!("AuctionClosing is not supported in V5, no project should be in this state when upgrading storage"); - ProjectStatus::AuctionRound - }, - OldProjectStatus::CalculatingWAP => { - let start = item - .phase_transition_points - .auction_opening - .start - .expect("AuctionOpening start block is missing"); - let end = start + ::AuctionRoundDuration::get(); - round_duration = BlockNumberPair::new(Some(start), Some(end)); - debug_assert!(false, "CalculatingWAP is not supported in V5, no project should be in this state when upgrading storage"); - log::error!("CalculatingWAP is not supported in V5, no project should be in this state when upgrading storage"); - ProjectStatus::AuctionRound - }, - OldProjectStatus::CommunityRound => { - let start = item - .phase_transition_points - .community - .start - .expect("CommunityRound start block is missing"); - let end = start + - ::CommunityRoundDuration::get() + - ::RemainderRoundDuration::get(); - round_duration = BlockNumberPair::new(Some(start), Some(end)); - debug_assert!( - false, - "We should not upgrade runtime while a project is still in community round" - ); - ProjectStatus::CommunityRound( - item.phase_transition_points.community.end.expect("CommunityRound end block is missing") + - One::one(), - ) - }, - OldProjectStatus::RemainderRound => { - let start = item - .phase_transition_points - .community - .start - .expect("CommunityRound start block is missing"); - let end = start + - ::CommunityRoundDuration::get() + - ::RemainderRoundDuration::get(); - round_duration = BlockNumberPair::new(Some(start), Some(end)); - ProjectStatus::CommunityRound( - item.phase_transition_points.remainder.start.expect("Remainder start block is missing"), - ) - }, - OldProjectStatus::FundingFailed => { - round_duration = BlockNumberPair::new(None, None); - ProjectStatus::SettlementStarted(FundingOutcome::Failure) - }, - OldProjectStatus::AwaitingProjectDecision => { - round_duration = BlockNumberPair::new(None, None); - debug_assert!(false, "AwaitingProjectDecision is not supported in V5, no project should be in this state when upgrading storage"); - log::error!("AwaitingProjectDecision is not supported in V5, no project should be in this state when upgrading storage"); - ProjectStatus::FundingSuccessful - }, - OldProjectStatus::FundingSuccessful => { - round_duration = BlockNumberPair::new(None, None); - ProjectStatus::SettlementStarted(FundingOutcome::Success) - }, - OldProjectStatus::SettlementStarted(old_outcome) => { - round_duration = BlockNumberPair::new(None, None); - let outcome = match old_outcome { - OldFundingOutcome::FundingSuccessful => FundingOutcome::Success, - OldFundingOutcome::FundingFailed => FundingOutcome::Failure, - }; - ProjectStatus::SettlementStarted(outcome) - }, - OldProjectStatus::SettlementFinished(old_outcome) => { - round_duration = BlockNumberPair::new(None, None); - let outcome = match old_outcome { - OldFundingOutcome::FundingSuccessful => FundingOutcome::Success, - OldFundingOutcome::FundingFailed => FundingOutcome::Failure, - }; - ProjectStatus::SettlementFinished(outcome) - }, - OldProjectStatus::CTMigrationStarted => { - round_duration = BlockNumberPair::new(None, None); - ProjectStatus::CTMigrationStarted - }, - OldProjectStatus::CTMigrationFinished => { - round_duration = BlockNumberPair::new(None, None); - ProjectStatus::CTMigrationFinished - }, - }; - - let evaluators_outcome = Some(match item.evaluation_round_info.evaluators_outcome { - OldEvaluatorsOutcome::Unchanged => EvaluatorsOutcome::Rewarded( - >::generate_evaluator_rewards_info(key) - .expect("Evaluator rewards info should be generated"), - ), - OldEvaluatorsOutcome::Rewarded(info) => EvaluatorsOutcome::>::Rewarded(info), - OldEvaluatorsOutcome::Slashed => EvaluatorsOutcome::>::Slashed, - }); - let evaluation_round_info = EvaluationRoundInfoOf:: { - total_bonded_usd: item.evaluation_round_info.total_bonded_usd, - total_bonded_plmc: item.evaluation_round_info.total_bonded_plmc, - evaluators_outcome, - }; - Some(ProjectDetailsOf:: { - issuer_account: item.issuer_account, - issuer_did: item.issuer_did, - is_frozen: item.is_frozen, - weighted_average_price: item.weighted_average_price, - status: new_status, - round_duration, - fundraising_target_usd: item.fundraising_target_usd, - remaining_contribution_tokens: item.remaining_contribution_tokens, - funding_amount_reached_usd: item.funding_amount_reached_usd, - evaluation_round_info, - usd_bid_on_oversubscription: item.usd_bid_on_oversubscription, - funding_end_block: item.funding_end_block, - migration_type: None, - }) - }; - crate::ProjectsDetails::::translate(|key, object: OldProjectDetailsOf| { - translate_project_details(key, object) - }); - - T::DbWeight::get().reads_writes(items, items) - } - } - - pub type MigrationToV5 = frame_support::migrations::VersionedMigration< - 4, - 5, - UncheckedMigrationToV5, - crate::Pallet, - ::DbWeight, - >; -} +pub const LOG: &str = "runtime::funding::migration"; \ No newline at end of file diff --git a/runtimes/polimec/src/lib.rs b/runtimes/polimec/src/lib.rs index 88796a8be..4bf89f4dd 100644 --- a/runtimes/polimec/src/lib.rs +++ b/runtimes/polimec/src/lib.rs @@ -169,7 +169,6 @@ pub mod migrations { pub type Unreleased = ( cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5, crate::custom_migrations::funding_holds::FromFundingV4Migration, - pallet_funding::storage_migrations::v5::MigrationToV5, ); }