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 unused migration. #111

Merged
merged 3 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 1 addition & 14 deletions control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub mod weights;

use codec::Codec;
use frame_support::{dispatch::{DispatchResult, DispatchError, RawOrigin},
ensure, PalletId, traits::{Get, StorageVersion}, weights::Weight, BoundedVec, transactional
ensure, PalletId, traits::Get, weights::Weight, BoundedVec, transactional
};
use gamedao_traits::{ControlTrait, ControlBenchmarkingTrait};
use orml_traits::{MultiCurrency, MultiReservableCurrency};
Expand Down Expand Up @@ -53,12 +53,8 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);

#[pallet::config]
Expand Down Expand Up @@ -272,15 +268,6 @@ pub mod pallet {
WrongOrganizationType
}

#[pallet::hooks]
impl<T: Config> Hooks<T::BlockNumber> for Pallet<T> {

fn on_runtime_upgrade() -> Weight {
migration::migrate::<T, Self>()
}

}

#[pallet::call]
impl<T: Config> Pallet<T> {

Expand Down
73 changes: 39 additions & 34 deletions control/src/migration.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
use frame_support::{
traits::{Get, GetStorageVersion, PalletInfoAccess, StorageVersion},
Blake2_128Concat,
BoundedVec
};
use sp_std::prelude::*;
use crate::{Config, Pallet, Weight};


pub fn migrate<T: Config, P: GetStorageVersion + PalletInfoAccess>() -> Weight {

let version = StorageVersion::get::<Pallet<T>>();
let mut weight: Weight = 0;

if version < 1 {
weight = weight.saturating_add(v1::migrate::<T, P>());
StorageVersion::new(1).put::<Pallet<T>>();
}

weight
}

mod v1 {
use super::*;
use sp_io::hashing::twox_128;

pub fn migrate<T: Config, P: GetStorageVersion + PalletInfoAccess>() -> Weight {
let _ = frame_support::storage::unhashed::clear_prefix(
&twox_128(<Pallet<T>>::name().as_bytes()), None, None
);

T::DbWeight::get().writes(1)
}
}
// _______ ________ ________ ________ ______ _______ _______
// ╱╱ ╲╱ ╲╱ ╲╱ ╲_╱ ╲╲╱ ╲╲╱ ╲╲
// ╱╱ __╱ ╱ ╱ ╱ ╱╱ ╱╱ ╱╱
// ╱ ╱ ╱ ╱ ╱ _╱ ╱ ╱ ╱
// ╲________╱╲___╱____╱╲__╱__╱__╱╲________╱╲________╱╲___╱____╱╲________╱
//
// This file is part of GameDAO Protocol.
// Copyright (C) 2018-2022 GameDAO AG.
// SPDX-License-Identifier: Apache-2.0

// use frame_support::{
// traits::{Get, PalletInfoAccess, StorageVersion},
// };
// use crate::{Config, Pallet, Weight};


// pub fn migrate<T: Config, P: PalletInfoAccess>() -> Weight {

// let version = StorageVersion::get::<Pallet<T>>();
// let mut weight: Weight = 0;

// if version == 0 {
// weight = weight.saturating_add(v1::migrate::<T, P>());
// StorageVersion::new(1).put::<Pallet<T>>();
// }

// weight
// }

// mod v1 {
// use super::*;

// pub fn migrate<T: Config, P: PalletInfoAccess>() -> Weight {
// //
// // Migration logic should be placed here
// //
// T::DbWeight::get().writes(1)
// }
// }
12 changes: 2 additions & 10 deletions flow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub mod weights;

use frame_support::{
dispatch::{DispatchResult, DispatchError, DispatchResultWithPostInfo},
traits::{Get, BalanceStatus, Hooks, StorageVersion},
traits::{Get, BalanceStatus, Hooks},
weights::Weight, BoundedVec, log, transactional
};

Expand Down Expand Up @@ -77,12 +77,8 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);

#[pallet::config]
Expand Down Expand Up @@ -366,11 +362,7 @@ pub mod pallet {
}
let c = BoundedVec::try_from(contributors.clone()).unwrap();
CampaignFinalizationQueue::<T>::insert(campaign_id, (campaign, campaign_balance, state, treasury_id, c));
}
}

fn on_runtime_upgrade() -> Weight {
migration::migrate::<T, Self>()
}
}
}

Expand Down
80 changes: 39 additions & 41 deletions flow/src/migration.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
use frame_support::{
traits::{Get, GetStorageVersion, PalletInfoAccess, StorageVersion},
Blake2_128Concat,
BoundedVec
};
use sp_std::prelude::*;
use crate::{
// CampaignsByState as CampaignsByStateNew,
// CampaignOrg,
Config,
// FlowState,
Pallet,
Weight
};


pub fn migrate<T: Config, P: GetStorageVersion + PalletInfoAccess>() -> Weight {

let version = StorageVersion::get::<Pallet<T>>();
let mut weight: Weight = 0;

if version < 2 {
weight = weight.saturating_add(v2::migrate::<T, P>());
StorageVersion::new(2).put::<Pallet<T>>();
}

weight
}

mod v2 {
use super::*;
use sp_io::hashing::twox_128;

pub fn migrate<T: Config, P: GetStorageVersion + PalletInfoAccess>() -> Weight {
let _ = frame_support::storage::unhashed::clear_prefix(
&twox_128(<Pallet<T>>::name().as_bytes()), None, None
);

T::DbWeight::get().writes(1)
}
}
// _______ ________ ________ ________ ______ _______ _______
// ╱╱ ╲╱ ╲╱ ╲╱ ╲_╱ ╲╲╱ ╲╲╱ ╲╲
// ╱╱ __╱ ╱ ╱ ╱ ╱╱ ╱╱ ╱╱
// ╱ ╱ ╱ ╱ ╱ _╱ ╱ ╱ ╱
// ╲________╱╲___╱____╱╲__╱__╱__╱╲________╱╲________╱╲___╱____╱╲________╱
//
// This file is part of GameDAO Protocol.
// Copyright (C) 2018-2022 GameDAO AG.
// SPDX-License-Identifier: Apache-2.0

// use frame_support::{
// traits::{Get, PalletInfoAccess, StorageVersion},
// };
// use crate::{Config, Pallet, Weight};


// pub fn migrate<T: Config, P: PalletInfoAccess>() -> Weight {

// let version = StorageVersion::get::<Pallet<T>>();
// let mut weight: Weight = 0;

// if version == 0 {
// weight = weight.saturating_add(v1::migrate::<T, P>());
// StorageVersion::new(1).put::<Pallet<T>>();
// }

// weight
// }

// mod v1 {
// use super::*;

// pub fn migrate<T: Config, P: PalletInfoAccess>() -> Weight {
// //
// // Migration logic should be placed here
// //
// T::DbWeight::get().writes(1)
// }
// }
9 changes: 1 addition & 8 deletions signal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub mod weights;

use frame_support::{
BoundedVec,
traits::{StorageVersion, BalanceStatus},
traits::BalanceStatus,
dispatch::DispatchResult,
weights::Weight,
transactional
Expand Down Expand Up @@ -67,12 +67,8 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);

#[pallet::config]
Expand Down Expand Up @@ -401,9 +397,6 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {

fn on_runtime_upgrade() -> Weight {
migration::migrate::<T>()
}

fn on_initialize(block_number: T::BlockNumber) -> Weight {
let proposals = ProposalsByBlock::<T>::get(BlockType::Start, &block_number);
Expand Down
66 changes: 29 additions & 37 deletions signal/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,32 @@
// Copyright (C) 2018-2022 GameDAO AG.
// SPDX-License-Identifier: Apache-2.0

use crate::{Config, Pallet, Weight};
use frame_support::{
traits::{Get, PalletInfoAccess},
};

pub fn migrate<T: Config>() -> Weight {
use frame_support::traits::StorageVersion;

let version = StorageVersion::get::<Pallet<T>>();
let mut weight: Weight = 0;

if version < 1 {
weight = weight.saturating_add(v1::migrate::<T>());
StorageVersion::new(1).put::<Pallet<T>>();
}
if version < 2 {
weight = weight.saturating_add(v1::migrate::<T>());
StorageVersion::new(2).put::<Pallet<T>>();
}

weight
}

/// V1: Clean up pallet storage
mod v1 {
use super::*;
use sp_io::hashing::twox_128;

pub fn migrate<T: Config>() -> Weight {

let _ = frame_support::storage::unhashed::clear_prefix(
&twox_128(<Pallet<T>>::name().as_bytes()), None, None
);

T::DbWeight::get().writes(1)
}
}
// use frame_support::{
// traits::{Get, PalletInfoAccess, StorageVersion},
// };
// use crate::{Config, Pallet, Weight};


// pub fn migrate<T: Config, P: PalletInfoAccess>() -> Weight {

// let version = StorageVersion::get::<Pallet<T>>();
// let mut weight: Weight = 0;

// if version == 0 {
// weight = weight.saturating_add(v1::migrate::<T, P>());
// StorageVersion::new(1).put::<Pallet<T>>();
// }

// weight
// }

// mod v1 {
// use super::*;

// pub fn migrate<T: Config, P: PalletInfoAccess>() -> Weight {
// //
// // Migration logic should be placed here
// //
// T::DbWeight::get().writes(1)
// }
// }