From 6893c2f15dd583203223e756a46263f71d10b51f Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 22 Jun 2020 21:52:31 +0200 Subject: [PATCH 1/3] Remove lingering runtime upgrades --- frame/democracy/src/lib.rs | 16 -------------- frame/indices/src/lib.rs | 10 --------- frame/multisig/src/lib.rs | 11 ---------- frame/staking/src/lib.rs | 28 +++--------------------- frame/transaction-payment/src/lib.rs | 32 ---------------------------- 5 files changed, 3 insertions(+), 94 deletions(-) diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 841281c125b75..1d9154fabf1b1 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -602,22 +602,6 @@ decl_module! { fn deposit_event() = default; - fn on_runtime_upgrade() -> Weight { - if let None = StorageVersion::get() { - StorageVersion::put(Releases::V1); - - DepositOf::::translate::< - (BalanceOf, Vec), _ - >(|_, (balance, accounts)| { - Some((accounts, balance)) - }); - - T::MaximumBlockWeight::get() - } else { - T::DbWeight::get().reads(1) - } - } - /// Propose a sensitive action to be taken. /// /// The dispatch origin of this call must be _Signed_ and the sender must diff --git a/frame/indices/src/lib.rs b/frame/indices/src/lib.rs index 048a5b9936ad4..b8a51e2bf59e1 100644 --- a/frame/indices/src/lib.rs +++ b/frame/indices/src/lib.rs @@ -104,16 +104,6 @@ decl_module! { pub struct Module for enum Call where origin: T::Origin, system = frame_system { fn deposit_event() = default; - fn on_runtime_upgrade() -> Weight { - use frame_support::migration::{StorageIterator, put_storage_value}; - for (key, value) in StorageIterator::< - (T::AccountId, BalanceOf) - >::new(b"Indices", b"Accounts").drain() { - put_storage_value(b"Indices", b"Accounts", &key, (value.0, value.1, false)); - } - 1_000_000_000 - } - /// Assign an previously unassigned index. /// /// Payment: `Deposit` is reserved from the sender account. diff --git a/frame/multisig/src/lib.rs b/frame/multisig/src/lib.rs index fc7a6c25b30b4..bcea34f9b36fa 100644 --- a/frame/multisig/src/lib.rs +++ b/frame/multisig/src/lib.rs @@ -235,17 +235,6 @@ decl_module! { /// Deposit one of this module's events by using the default implementation. fn deposit_event() = default; - fn on_runtime_upgrade() -> Weight { - // Utility.Multisigs -> Multisig.Multisigs - use frame_support::migration::{StorageIterator, put_storage_value}; - for (key, value) in StorageIterator::< - Multisig, T::AccountId> - >::new(b"Utility", b"Multisigs").drain() { - put_storage_value(b"Multisig", b"Multisigs", &key, value); - } - 1_000_000_000 - } - /// Immediately dispatch a multi-signature call using a single approval from the caller. /// /// The dispatch origin for this call must be _Signed_. diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index 63b427a5ab6e2..de61b25483d01 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -1278,9 +1278,9 @@ decl_module! { /// Number of eras that staked funds must remain bonded for. const BondingDuration: EraIndex = T::BondingDuration::get(); - /// Number of eras that slashes are deferred by, after computation. + /// Number of eras that slashes are deferred by, after computation. /// - /// This should be less than the bonding duration. + /// This should be less than the bonding duration. /// Set to 0 if slashes should be applied immediately, without opportunity for /// intervention. const SlashDeferDuration: EraIndex = T::SlashDeferDuration::get(); @@ -1294,7 +1294,7 @@ decl_module! { /// length of a session will be pointless. const ElectionLookahead: T::BlockNumber = T::ElectionLookahead::get(); - /// Maximum number of balancing iterations to run in the offchain submission. + /// Maximum number of balancing iterations to run in the offchain submission. /// /// If set to 0, balance_solution will not be executed at all. const MaxIterations: u32 = T::MaxIterations::get(); @@ -1312,28 +1312,6 @@ decl_module! { fn deposit_event() = default; - fn on_runtime_upgrade() -> Weight { - #[allow(dead_code)] - mod inner { - pub struct Module(sp_std::marker::PhantomData); - frame_support::decl_storage! { - trait Store for Module as Staking { - pub MigrateEra: Option; - } - } - } - - if let Releases::V3_0_0 = StorageVersion::get() { - StorageVersion::put(Releases::V4_0_0); - inner::MigrateEra::kill(); - - T::DbWeight::get().reads_writes(1, 1) - } else { - T::DbWeight::get().reads(1) - } - } - - /// sets `ElectionStatus` to `Open(now)` where `now` is the block number at which the /// election window has opened, if we are at the last session and less blocks than /// `T::ElectionLookahead` is remaining until the next new session schedule. The offchain diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 31d0cfb20ded0..0f5292cdea621 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -230,38 +230,6 @@ decl_module! { ).unwrap(), ); } - - fn on_runtime_upgrade() -> Weight { - use frame_support::migration::take_storage_value; - use sp_std::convert::TryInto; - use frame_support::debug::native::error; - - type OldMultiplier = sp_runtime::FixedI128; - type OldInner = ::Inner; - type Inner = ::Inner; - - if let Releases::V1Ancient = StorageVersion::get() { - StorageVersion::put(Releases::V2); - - if let Some(old) = take_storage_value::( - b"TransactionPayment", - b"NextFeeMultiplier", - &[], - ) { - let inner = old.into_inner(); - let new_inner = >::try_into(inner) - .unwrap_or_default(); - let new = Multiplier::from_inner(new_inner); - NextFeeMultiplier::put(new); - T::DbWeight::get().reads_writes(1, 1) - } else { - error!("transaction-payment migration failed."); - T::DbWeight::get().reads(1) - } - } else { - T::DbWeight::get().reads(1) - } - } } } From 4346ff543ed3847f9705d48863a38ba8565ff9d3 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 22 Jun 2020 22:09:32 +0200 Subject: [PATCH 2/3] remove unused warnings --- frame/democracy/src/lib.rs | 1 - frame/indices/src/lib.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 1d9154fabf1b1..79cc136d45875 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -160,7 +160,6 @@ use sp_runtime::{ use codec::{Encode, Decode, Input}; use frame_support::{ decl_module, decl_storage, decl_event, decl_error, ensure, Parameter, - storage::IterableStorageMap, weights::{Weight, DispatchClass}, traits::{ Currency, ReservableCurrency, LockableCurrency, WithdrawReason, LockIdentifier, Get, diff --git a/frame/indices/src/lib.rs b/frame/indices/src/lib.rs index b8a51e2bf59e1..e58112403f628 100644 --- a/frame/indices/src/lib.rs +++ b/frame/indices/src/lib.rs @@ -26,7 +26,7 @@ use sp_runtime::traits::{ StaticLookup, Member, LookupError, Zero, Saturating, AtLeast32Bit }; use frame_support::{Parameter, decl_module, decl_error, decl_event, decl_storage, ensure}; -use frame_support::dispatch::{DispatchResult, Weight}; +use frame_support::dispatch::DispatchResult; use frame_support::traits::{Currency, ReservableCurrency, Get, BalanceStatus::Reserved}; use frame_support::weights::constants::WEIGHT_PER_MICROS; use frame_system::{ensure_signed, ensure_root}; From 887150b72911df02e643e94e322722763151c786 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 22 Jun 2020 22:44:48 +0200 Subject: [PATCH 3/3] remove tests --- frame/democracy/src/tests.rs | 1 - frame/democracy/src/tests/migration.rs | 45 -------------------------- frame/transaction-payment/src/lib.rs | 31 ------------------ 3 files changed, 77 deletions(-) delete mode 100644 frame/democracy/src/tests/migration.rs diff --git a/frame/democracy/src/tests.rs b/frame/democracy/src/tests.rs index c1bab3c0212e3..b92f4bd0760f6 100644 --- a/frame/democracy/src/tests.rs +++ b/frame/democracy/src/tests.rs @@ -42,7 +42,6 @@ mod preimage; mod public_proposals; mod scheduling; mod voting; -mod migration; mod decoders; const AYE: Vote = Vote { aye: true, conviction: Conviction::None }; diff --git a/frame/democracy/src/tests/migration.rs b/frame/democracy/src/tests/migration.rs deleted file mode 100644 index cab8f7f5c936c..0000000000000 --- a/frame/democracy/src/tests/migration.rs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -//! The tests for migration. - -use super::*; -use frame_support::{storage::migration, Hashable, traits::OnRuntimeUpgrade}; -use substrate_test_utils::assert_eq_uvec; - -#[test] -fn migration() { - new_test_ext().execute_with(|| { - for i in 0..3 { - let k = i.twox_64_concat(); - let v: (BalanceOf, Vec) = (i * 1000, vec![i]); - migration::put_storage_value(b"Democracy", b"DepositOf", &k, v); - } - StorageVersion::kill(); - - Democracy::on_runtime_upgrade(); - - assert_eq!(StorageVersion::get(), Some(Releases::V1)); - assert_eq_uvec!( - DepositOf::::iter().collect::>(), - vec![ - (0, (vec![0u64], >::from(0u32))), - (1, (vec![1u64], >::from(1000u32))), - (2, (vec![2u64], >::from(2000u32))), - ] - ); - }) -} diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 0f5292cdea621..4d920f8ec53b8 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -708,37 +708,6 @@ mod tests { PostDispatchInfo { actual_weight: None, } } - #[test] - fn migration_to_v2_works() { - use sp_runtime::FixedI128; - use frame_support::traits::OnRuntimeUpgrade; - - let with_old_multiplier = |mul: FixedI128, expected: FixedU128| { - ExtBuilder::default().build().execute_with(|| { - frame_support::migration::put_storage_value( - b"TransactionPayment", - b"NextFeeMultiplier", - &[], - mul, - ); - - assert_eq!(StorageVersion::get(), Releases::V1Ancient); - - TransactionPayment::on_runtime_upgrade(); - - assert_eq!(StorageVersion::get(), Releases::V2); - assert_eq!(NextFeeMultiplier::get(), expected); - }) - }; - - with_old_multiplier(FixedI128::saturating_from_integer(-1), FixedU128::zero()); - with_old_multiplier(FixedI128::saturating_from_rational(-1, 2), FixedU128::zero()); - with_old_multiplier( - FixedI128::saturating_from_rational(1, 2), - FixedU128::saturating_from_rational(1, 2), - ); - } - #[test] fn signed_extension_transaction_payment_work() { ExtBuilder::default()