diff --git a/substrate/frame/democracy/src/lib.rs b/substrate/frame/democracy/src/lib.rs index b60d658cde59d5954b617465251373bda4cd9b86..ddc3b36f4c8779fe8532467ee1253d5bcca5b070 100644 --- a/substrate/frame/democracy/src/lib.rs +++ b/substrate/frame/democracy/src/lib.rs @@ -525,12 +525,6 @@ decl_module! { fn deposit_event() = default; - fn on_runtime_upgrade() -> Weight { - Self::migrate(); - - 0 - } - /// Propose a sensitive action to be taken. /// /// The dispatch origin of this call must be _Signed_ and the sender must @@ -1268,25 +1262,6 @@ decl_module! { } impl<T: Trait> Module<T> { - fn migrate() { - use frame_support::{Twox64Concat, migration::{StorageKeyIterator, remove_storage_prefix}}; - remove_storage_prefix(b"Democracy", b"VotesOf", &[]); - remove_storage_prefix(b"Democracy", b"VotersFor", &[]); - remove_storage_prefix(b"Democracy", b"Delegations", &[]); - for (who, (end, proposal_hash, threshold, delay)) - in StorageKeyIterator::< - ReferendumIndex, - (T::BlockNumber, T::Hash, VoteThreshold, T::BlockNumber), - Twox64Concat, - >::new(b"Democracy", b"ReferendumInfoOf").drain() - { - let status = ReferendumStatus { - end, proposal_hash, threshold, delay, tally: Tally::default() - }; - ReferendumInfoOf::<T>::insert(who, ReferendumInfo::Ongoing(status)) - } - } - // exposed immutables. /// Get the amount locked in support of `proposal`; `None` if proposal isn't a valid proposal diff --git a/substrate/frame/indices/src/lib.rs b/substrate/frame/indices/src/lib.rs index 4861197eda371199abbd2906ea9635d528402b01..8c17fed5921301c0f2ac5ad1bba6d30bde0e89fb 100644 --- a/substrate/frame/indices/src/lib.rs +++ b/substrate/frame/indices/src/lib.rs @@ -22,13 +22,11 @@ use sp_std::prelude::*; use codec::Codec; use sp_runtime::traits::{ - StaticLookup, Member, LookupError, Zero, One, BlakeTwo256, Hash, Saturating, AtLeast32Bit + StaticLookup, Member, LookupError, Zero, Saturating, AtLeast32Bit }; use frame_support::{Parameter, decl_module, decl_error, decl_event, decl_storage, ensure}; -use frame_support::weights::Weight; use frame_support::dispatch::DispatchResult; use frame_support::traits::{Currency, ReservableCurrency, Get, BalanceStatus::Reserved}; -use frame_support::storage::migration::take_storage_value; use frame_system::{ensure_signed, ensure_root}; use self::address::Address as RawAddress; @@ -99,12 +97,6 @@ decl_module! { pub struct Module<T: Trait> for enum Call where origin: T::Origin, system = frame_system { fn deposit_event() = default; - fn on_initialize() -> Weight { - Self::migrations(); - - 0 - } - /// Assign an previously unassigned index. /// /// Payment: `Deposit` is reserved from the sender account. @@ -241,30 +233,6 @@ impl<T: Trait> Module<T> { address::Address::Index(i) => Self::lookup_index(i), } } - - /// Do any migrations. - fn migrations() { - if let Some(set_count) = take_storage_value::<T::AccountIndex>(b"Indices", b"NextEnumSet", b"") { - // migrations need doing. - let set_size: T::AccountIndex = 64.into(); - - let mut set_index: T::AccountIndex = Zero::zero(); - while set_index < set_count { - let maybe_accounts = take_storage_value::<Vec<T::AccountId>>(b"Indices", b"EnumSet", BlakeTwo256::hash_of(&set_index).as_ref()); - if let Some(accounts) = maybe_accounts { - for (item_index, target) in accounts.into_iter().enumerate() { - if target != T::AccountId::default() && !T::Currency::total_balance(&target).is_zero() { - let index = set_index * set_size + T::AccountIndex::from(item_index as u32); - Accounts::<T>::insert(index, (target, BalanceOf::<T>::zero())); - } - } - } else { - break; - } - set_index += One::one(); - } - } - } } impl<T: Trait> StaticLookup for Module<T> { diff --git a/substrate/frame/offences/src/lib.rs b/substrate/frame/offences/src/lib.rs index 1ad188a7a8364bb225c7575088cab252276b2f4b..b877d1e2b20dd1972c2dd6db776e984b76c9de56 100644 --- a/substrate/frame/offences/src/lib.rs +++ b/substrate/frame/offences/src/lib.rs @@ -99,14 +99,6 @@ decl_module! { pub struct Module<T: Trait> for enum Call where origin: T::Origin { fn deposit_event() = default; - fn on_runtime_upgrade() -> Weight { - Reports::<T>::remove_all(); - ConcurrentReportsIndex::<T>::remove_all(); - ReportsByKindIndex::remove_all(); - - 0 - } - fn on_initialize(now: T::BlockNumber) -> Weight { // only decode storage if we can actually submit anything again. if T::OnOffenceHandler::can_report() { diff --git a/substrate/frame/staking/src/lib.rs b/substrate/frame/staking/src/lib.rs index 67240d8d34b2a212186b7a9c0eeaa51d08c17d29..ca3fb51ecb74919fe775fd320fd61bb132f4c7b8 100644 --- a/substrate/frame/staking/src/lib.rs +++ b/substrate/frame/staking/src/lib.rs @@ -1246,18 +1246,6 @@ decl_module! { } } - fn on_runtime_upgrade() -> Weight { - // For Kusama the type hasn't actually changed as Moment was u64 and was the number of - // millisecond since unix epoch. - StorageVersion::mutate(|v| { - if matches!(v, Releases::V2_0_0) { - Self::migrate_last_reward_to_claimed_rewards(); - } - *v = Releases::V3_0_0; - }); - 0 - } - /// Take the origin account as a stash and lock up `value` of its balance. `controller` will /// be the account that controls it. /// @@ -1935,43 +1923,6 @@ decl_module! { } impl<T: Trait> Module<T> { - /// Migrate `last_reward` to `claimed_rewards` - pub fn migrate_last_reward_to_claimed_rewards() { - use frame_support::migration::{StorageIterator, put_storage_value}; - // Migrate from `last_reward` to `claimed_rewards`. - // We will construct a vector from `current_era - history_depth` to `last_reward` - // for each validator and nominator. - // - // Old Staking Ledger - #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)] - struct OldStakingLedger<AccountId, Balance: HasCompact> { - pub stash: AccountId, - #[codec(compact)] - pub total: Balance, - #[codec(compact)] - pub active: Balance, - pub unlocking: Vec<UnlockChunk<Balance>>, - pub last_reward: Option<EraIndex>, - } - // Current era and history depth - let current_era = Self::current_era().unwrap_or(0); - let history_depth = Self::history_depth(); - let last_payout_era = current_era.saturating_sub(history_depth); - // Convert all ledgers to the new format. - for (hash, old_ledger) in StorageIterator::<OldStakingLedger<T::AccountId, BalanceOf<T>>>::new(b"Staking", b"Ledger").drain() { - let last_reward = old_ledger.last_reward.unwrap_or(0); - let new_ledger = StakingLedger { - stash: old_ledger.stash, - total: old_ledger.total, - active: old_ledger.active, - unlocking: old_ledger.unlocking, - claimed_rewards: (last_payout_era..=last_reward).collect(), - }; - put_storage_value(b"Staking", b"Ledger", &hash, new_ledger); - } - MigrateEra::put(current_era); - } - /// The total balance that can be slashed from a stash account as of right now. pub fn slashable_balance_of(stash: &T::AccountId) -> BalanceOf<T> { Self::bonded(stash).and_then(Self::ledger).map(|l| l.active).unwrap_or_default() diff --git a/substrate/frame/staking/src/tests.rs b/substrate/frame/staking/src/tests.rs index 84c937d324cab2f2f47feb979c88d955dba72aad..f3dddc87ed776ba40925f8691663b7f5c862bc7b 100644 --- a/substrate/frame/staking/src/tests.rs +++ b/substrate/frame/staking/src/tests.rs @@ -4267,141 +4267,6 @@ fn bond_during_era_correctly_populates_claimed_rewards() { /* These migration tests below can be removed once migration code is removed */ -#[test] -fn assert_migration_is_noop() { - let kusama_active_era = "4a0200000190e2721171010000"; - let era = ActiveEraInfo::decode(&mut &hex::decode(kusama_active_era).unwrap()[..]).unwrap(); - assert_eq!(era.index, 586); - assert_eq!(era.start, Some(1585135674000)); -} - -#[test] -fn test_last_reward_migration() { - use sp_storage::Storage; - - let mut s = Storage::default(); - - #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)] - struct OldStakingLedger<AccountId, Balance: HasCompact> { - pub stash: AccountId, - #[codec(compact)] - pub total: Balance, - #[codec(compact)] - pub active: Balance, - pub unlocking: Vec<UnlockChunk<Balance>>, - pub last_reward: Option<EraIndex>, - } - - let old_staking10 = OldStakingLedger::<u64, u64> { - stash: 0, - total: 10, - active: 10, - unlocking: vec![UnlockChunk{ value: 1234, era: 56}], - last_reward: Some(8), - }; - - let old_staking11 = OldStakingLedger::<u64, u64> { - stash: 1, - total: 0, - active: 0, - unlocking: vec![], - last_reward: None, - }; - - let old_staking12 = OldStakingLedger::<u64, u64> { - stash: 2, - total: 100, - active: 100, - unlocking: vec![UnlockChunk{ value: 9876, era: 54}, UnlockChunk{ value: 98, era: 76}], - last_reward: Some(23), - }; - - let old_staking13 = OldStakingLedger::<u64, u64> { - stash: 3, - total: 100, - active: 100, - unlocking: vec![], - last_reward: Some(23), - }; - - let data = vec![ - ( - Ledger::<Test>::hashed_key_for(10), - old_staking10.encode().to_vec() - ), - ( - Ledger::<Test>::hashed_key_for(11), - old_staking11.encode().to_vec() - ), - ( - Ledger::<Test>::hashed_key_for(12), - old_staking12.encode().to_vec() - ), - ( - Ledger::<Test>::hashed_key_for(13), - old_staking13.encode().to_vec() - ), - ]; - - s.top = data.into_iter().collect(); - sp_io::TestExternalities::new(s).execute_with(|| { - HistoryDepth::put(84); - CurrentEra::put(99); - let nominations = Nominations::<AccountId> { - targets: vec![], - submitted_in: 0, - suppressed: false - }; - Nominators::<Test>::insert(3, nominations); - Bonded::<Test>::insert(3, 13); - Staking::migrate_last_reward_to_claimed_rewards(); - // Test staker out of range - assert_eq!( - Ledger::<Test>::get(10), - Some(StakingLedger { - stash: 0, - total: 10, - active: 10, - unlocking: vec![UnlockChunk{ value: 1234, era: 56}], - claimed_rewards: vec![], - }) - ); - // Test staker none - assert_eq!( - Ledger::<Test>::get(11), - Some(StakingLedger { - stash: 1, - total: 0, - active: 0, - unlocking: vec![], - claimed_rewards: vec![], - }) - ); - // Test staker migration - assert_eq!( - Ledger::<Test>::get(12), - Some(StakingLedger { - stash: 2, - total: 100, - active: 100, - unlocking: vec![UnlockChunk{ value: 9876, era: 54}, UnlockChunk{ value: 98, era: 76}], - claimed_rewards: vec![15,16,17,18,19,20,21,22,23], - }) - ); - // Test nominator migration - assert_eq!( - Ledger::<Test>::get(13), - Some(StakingLedger { - stash: 3, - total: 100, - active: 100, - unlocking: vec![], - claimed_rewards: vec![15,16,17,18,19,20,21,22,23], - }) - ); - }); -} - #[test] fn rewards_should_work_before_migration() { // should check that before migration: diff --git a/substrate/frame/transaction-payment/src/lib.rs b/substrate/frame/transaction-payment/src/lib.rs index c5992ab1298b8b293eb9c149121afbcbf76a45f8..fdcb9122a25e38d727e25572a59d9dc4a5a20981 100644 --- a/substrate/frame/transaction-payment/src/lib.rs +++ b/substrate/frame/transaction-payment/src/lib.rs @@ -93,20 +93,6 @@ decl_module! { *fm = T::FeeMultiplierUpdate::convert(*fm) }); } - - fn on_runtime_upgrade() -> Weight { - // TODO: Remove this code after on-chain upgrade from u32 to u64 weights - use sp_runtime::Fixed64; - use frame_support::migration::take_storage_value; - if let Some(old_next_fee_multiplier) = take_storage_value::<Fixed64>(b"TransactionPayment", b"NextFeeMultiplier", &[]) { - let raw_multiplier = old_next_fee_multiplier.into_inner() as i128; - // Fixed64 used 10^9 precision, where Fixed128 uses 10^18, so we need to add 9 zeros. - let new_raw_multiplier: i128 = raw_multiplier.saturating_mul(1_000_000_000); - let new_next_fee_multiplier: Fixed128 = Fixed128::from_parts(new_raw_multiplier); - NextFeeMultiplier::put(new_next_fee_multiplier); - } - 0 - } } } @@ -844,38 +830,4 @@ mod tests { assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 100 - 5); }); } - - // TODO Remove after u32 to u64 weights upgrade - #[test] - fn upgrade_to_fixed128_works() { - // TODO You can remove this from dev-dependencies after removing this test - use sp_storage::Storage; - use sp_runtime::Fixed64; - use frame_support::storage::generator::StorageValue; - use frame_support::traits::OnRuntimeUpgrade; - use core::num::NonZeroI128; - - let mut s = Storage::default(); - - let original_multiplier = Fixed64::from_rational(1, 2); - - let data = vec![ - ( - NextFeeMultiplier::storage_value_final_key().to_vec(), - original_multiplier.encode().to_vec() - ), - ]; - - s.top = data.into_iter().collect(); - - sp_io::TestExternalities::new(s).execute_with(|| { - let old_value = NextFeeMultiplier::get(); - assert!(old_value != Fixed128::from_rational(1, NonZeroI128::new(2).unwrap())); - - // Convert Fixed64(.5) to Fixed128(.5) - TransactionPayment::on_runtime_upgrade(); - let new_value = NextFeeMultiplier::get(); - assert_eq!(new_value, Fixed128::from_rational(1, NonZeroI128::new(2).unwrap())); - }); - } }