mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 07:01:03 +00:00
Remove lingering runtime upgrades (#6476)
* Remove lingering runtime upgrades * remove unused warnings * remove tests
This commit is contained in:
@@ -160,7 +160,6 @@ use sp_runtime::{
|
|||||||
use codec::{Encode, Decode, Input};
|
use codec::{Encode, Decode, Input};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
decl_module, decl_storage, decl_event, decl_error, ensure, Parameter,
|
decl_module, decl_storage, decl_event, decl_error, ensure, Parameter,
|
||||||
storage::IterableStorageMap,
|
|
||||||
weights::{Weight, DispatchClass},
|
weights::{Weight, DispatchClass},
|
||||||
traits::{
|
traits::{
|
||||||
Currency, ReservableCurrency, LockableCurrency, WithdrawReason, LockIdentifier, Get,
|
Currency, ReservableCurrency, LockableCurrency, WithdrawReason, LockIdentifier, Get,
|
||||||
@@ -602,22 +601,6 @@ decl_module! {
|
|||||||
|
|
||||||
fn deposit_event() = default;
|
fn deposit_event() = default;
|
||||||
|
|
||||||
fn on_runtime_upgrade() -> Weight {
|
|
||||||
if let None = StorageVersion::get() {
|
|
||||||
StorageVersion::put(Releases::V1);
|
|
||||||
|
|
||||||
DepositOf::<T>::translate::<
|
|
||||||
(BalanceOf<T>, Vec<T::AccountId>), _
|
|
||||||
>(|_, (balance, accounts)| {
|
|
||||||
Some((accounts, balance))
|
|
||||||
});
|
|
||||||
|
|
||||||
T::MaximumBlockWeight::get()
|
|
||||||
} else {
|
|
||||||
T::DbWeight::get().reads(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Propose a sensitive action to be taken.
|
/// Propose a sensitive action to be taken.
|
||||||
///
|
///
|
||||||
/// The dispatch origin of this call must be _Signed_ and the sender must
|
/// The dispatch origin of this call must be _Signed_ and the sender must
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ mod preimage;
|
|||||||
mod public_proposals;
|
mod public_proposals;
|
||||||
mod scheduling;
|
mod scheduling;
|
||||||
mod voting;
|
mod voting;
|
||||||
mod migration;
|
|
||||||
mod decoders;
|
mod decoders;
|
||||||
|
|
||||||
const AYE: Vote = Vote { aye: true, conviction: Conviction::None };
|
const AYE: Vote = Vote { aye: true, conviction: Conviction::None };
|
||||||
|
|||||||
@@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
//! 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<Test>, Vec<u64>) = (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::<Test>::iter().collect::<Vec<_>>(),
|
|
||||||
vec![
|
|
||||||
(0, (vec![0u64], <BalanceOf<Test>>::from(0u32))),
|
|
||||||
(1, (vec![1u64], <BalanceOf<Test>>::from(1000u32))),
|
|
||||||
(2, (vec![2u64], <BalanceOf<Test>>::from(2000u32))),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -26,7 +26,7 @@ use sp_runtime::traits::{
|
|||||||
StaticLookup, Member, LookupError, Zero, Saturating, AtLeast32Bit
|
StaticLookup, Member, LookupError, Zero, Saturating, AtLeast32Bit
|
||||||
};
|
};
|
||||||
use frame_support::{Parameter, decl_module, decl_error, decl_event, decl_storage, ensure};
|
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::traits::{Currency, ReservableCurrency, Get, BalanceStatus::Reserved};
|
||||||
use frame_support::weights::constants::WEIGHT_PER_MICROS;
|
use frame_support::weights::constants::WEIGHT_PER_MICROS;
|
||||||
use frame_system::{ensure_signed, ensure_root};
|
use frame_system::{ensure_signed, ensure_root};
|
||||||
@@ -104,16 +104,6 @@ decl_module! {
|
|||||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system = frame_system {
|
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system = frame_system {
|
||||||
fn deposit_event() = default;
|
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<T>)
|
|
||||||
>::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.
|
/// Assign an previously unassigned index.
|
||||||
///
|
///
|
||||||
/// Payment: `Deposit` is reserved from the sender account.
|
/// Payment: `Deposit` is reserved from the sender account.
|
||||||
|
|||||||
@@ -235,17 +235,6 @@ decl_module! {
|
|||||||
/// Deposit one of this module's events by using the default implementation.
|
/// Deposit one of this module's events by using the default implementation.
|
||||||
fn deposit_event() = default;
|
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::BlockNumber, BalanceOf<T>, 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.
|
/// Immediately dispatch a multi-signature call using a single approval from the caller.
|
||||||
///
|
///
|
||||||
/// The dispatch origin for this call must be _Signed_.
|
/// The dispatch origin for this call must be _Signed_.
|
||||||
|
|||||||
@@ -1312,28 +1312,6 @@ decl_module! {
|
|||||||
|
|
||||||
fn deposit_event() = default;
|
fn deposit_event() = default;
|
||||||
|
|
||||||
fn on_runtime_upgrade() -> Weight {
|
|
||||||
#[allow(dead_code)]
|
|
||||||
mod inner {
|
|
||||||
pub struct Module<T>(sp_std::marker::PhantomData<T>);
|
|
||||||
frame_support::decl_storage! {
|
|
||||||
trait Store for Module<T: super::Trait> as Staking {
|
|
||||||
pub MigrateEra: Option<super::EraIndex>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
/// 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
|
/// 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
|
/// `T::ElectionLookahead` is remaining until the next new session schedule. The offchain
|
||||||
|
|||||||
@@ -230,38 +230,6 @@ decl_module! {
|
|||||||
).unwrap(),
|
).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 = <OldMultiplier as FixedPointNumber>::Inner;
|
|
||||||
type Inner = <Multiplier as FixedPointNumber>::Inner;
|
|
||||||
|
|
||||||
if let Releases::V1Ancient = StorageVersion::get() {
|
|
||||||
StorageVersion::put(Releases::V2);
|
|
||||||
|
|
||||||
if let Some(old) = take_storage_value::<OldMultiplier>(
|
|
||||||
b"TransactionPayment",
|
|
||||||
b"NextFeeMultiplier",
|
|
||||||
&[],
|
|
||||||
) {
|
|
||||||
let inner = old.into_inner();
|
|
||||||
let new_inner = <OldInner as TryInto<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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -740,37 +708,6 @@ mod tests {
|
|||||||
PostDispatchInfo { actual_weight: None, }
|
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]
|
#[test]
|
||||||
fn signed_extension_transaction_payment_work() {
|
fn signed_extension_transaction_payment_work() {
|
||||||
ExtBuilder::default()
|
ExtBuilder::default()
|
||||||
|
|||||||
Reference in New Issue
Block a user