mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 18:51:12 +00:00
Remove migration code. (#5291)
* Remove migration code. * Fix cargo * Bump spec version
This commit is contained in:
@@ -40,7 +40,7 @@ impl system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
impl Trait for Test {
|
||||
|
||||
@@ -162,7 +162,7 @@ impl system::Trait for Runtime {
|
||||
/// This type is being generated by `construct_runtime!`.
|
||||
type ModuleToIndex = ModuleToIndex;
|
||||
/// What to do if a new account is created.
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
/// What to do if an account is fully reaped from the system.
|
||||
type OnKilledAccount = ();
|
||||
/// The data to be stored in an account.
|
||||
|
||||
@@ -60,8 +60,8 @@ pallet-randomness-collective-flip = { version = "2.0.0-alpha.4", default-feature
|
||||
pallet-recovery = { version = "2.0.0-alpha.4", default-features = false, path = "../../../frame/recovery" }
|
||||
pallet-session = { version = "2.0.0-alpha.4", features = ["historical"], path = "../../../frame/session", default-features = false }
|
||||
pallet-session-benchmarking = { version = "2.0.0-alpha.4", path = "../../../frame/session/benchmarking", default-features = false, optional = true }
|
||||
pallet-staking = { version = "2.0.0-alpha.4", features = ["migrate"], path = "../../../frame/staking", default-features = false }
|
||||
pallet-staking-reward-curve = { version = "2.0.0-alpha.4", path = "../../../frame/staking/reward-curve" }
|
||||
pallet-staking = { version = "2.0.0-alpha.4", default-features = false, path = "../../../frame/staking" }
|
||||
pallet-staking-reward-curve = { version = "2.0.0-alpha.4", default-features = false, path = "../../../frame/staking/reward-curve" }
|
||||
pallet-sudo = { version = "2.0.0-alpha.4", default-features = false, path = "../../../frame/sudo" }
|
||||
pallet-society = { version = "2.0.0-alpha.4", default-features = false, path = "../../../frame/society" }
|
||||
pallet-timestamp = { version = "2.0.0-alpha.4", default-features = false, path = "../../../frame/timestamp" }
|
||||
@@ -135,10 +135,8 @@ std = [
|
||||
]
|
||||
runtime-benchmarks = [
|
||||
"frame-benchmarking",
|
||||
"pallet-balances/runtime-benchmarks",
|
||||
"pallet-identity/runtime-benchmarks",
|
||||
"pallet-session-benchmarking",
|
||||
"pallet-timestamp/runtime-benchmarks",
|
||||
"pallet-identity/runtime-benchmarks",
|
||||
"pallet-balances/runtime-benchmarks",
|
||||
"pallet-vesting/runtime-benchmarks",
|
||||
"pallet-staking/runtime-benchmarks",
|
||||
]
|
||||
|
||||
@@ -82,7 +82,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
// and set impl_version to 0. If only runtime
|
||||
// implementation changes and behavior does not, then leave spec_version as
|
||||
// is and increment impl_version.
|
||||
spec_version: 237,
|
||||
spec_version: 238,
|
||||
impl_version: 0,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
@@ -140,7 +140,6 @@ impl frame_system::Trait for Runtime {
|
||||
type Version = Version;
|
||||
type ModuleToIndex = ModuleToIndex;
|
||||
type AccountData = pallet_balances::AccountData<Balance>;
|
||||
type MigrateAccount = (Balances, Identity, Democracy, Elections, ImOnline, Recovery, Session, Society, Staking, Vesting);
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ use sc_client_api::backend::AuxStore;
|
||||
use sp_blockchain::{Result as ClientResult, Error as ClientError};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use sp_consensus_babe::BabeBlockWeight;
|
||||
use sc_consensus_epochs::{EpochChangesFor, SharedEpochChanges, migration::EpochChangesForV0};
|
||||
use sc_consensus_epochs::{EpochChangesFor, SharedEpochChanges};
|
||||
use crate::Epoch;
|
||||
|
||||
const BABE_EPOCH_CHANGES_VERSION: &[u8] = b"babe_epoch_changes_version";
|
||||
@@ -57,11 +57,7 @@ pub(crate) fn load_epoch_changes<Block: BlockT, B: AuxStore>(
|
||||
let version = load_decode::<_, u32>(backend, BABE_EPOCH_CHANGES_VERSION)?;
|
||||
|
||||
let maybe_epoch_changes = match version {
|
||||
None => load_decode::<_, EpochChangesForV0<Block, Epoch>>(
|
||||
backend,
|
||||
BABE_EPOCH_CHANGES_KEY,
|
||||
)?.map(|v0| v0.migrate()),
|
||||
Some(BABE_EPOCH_CHANGES_CURRENT_VERSION) => load_decode::<_, EpochChangesFor<Block, Epoch>>(
|
||||
None | Some(BABE_EPOCH_CHANGES_CURRENT_VERSION) => load_decode::<_, EpochChangesFor<Block, Epoch>>(
|
||||
backend,
|
||||
BABE_EPOCH_CHANGES_KEY,
|
||||
)?,
|
||||
@@ -127,72 +123,3 @@ pub(crate) fn load_block_weight<H: Encode, B: AuxStore>(
|
||||
) -> ClientResult<Option<BabeBlockWeight>> {
|
||||
load_decode(backend, block_weight_key(block_hash).as_slice())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::Epoch;
|
||||
use fork_tree::ForkTree;
|
||||
use substrate_test_runtime_client;
|
||||
use sp_core::H256;
|
||||
use sp_runtime::traits::NumberFor;
|
||||
use sc_consensus_epochs::{PersistedEpoch, PersistedEpochHeader, EpochHeader};
|
||||
use sp_consensus::Error as ConsensusError;
|
||||
use sc_network_test::Block as TestBlock;
|
||||
|
||||
#[test]
|
||||
fn load_decode_from_v0_epoch_changes() {
|
||||
let epoch = Epoch {
|
||||
start_slot: 0,
|
||||
authorities: vec![],
|
||||
randomness: [0; 32],
|
||||
epoch_index: 1,
|
||||
duration: 100,
|
||||
};
|
||||
let client = substrate_test_runtime_client::new();
|
||||
let mut v0_tree = ForkTree::<H256, NumberFor<TestBlock>, _>::new();
|
||||
v0_tree.import::<_, ConsensusError>(
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
PersistedEpoch::Regular(epoch),
|
||||
&|_, _| Ok(false), // Test is single item only so this can be set to false.
|
||||
).unwrap();
|
||||
|
||||
client.insert_aux(
|
||||
&[(BABE_EPOCH_CHANGES_KEY,
|
||||
&EpochChangesForV0::<TestBlock, Epoch>::from_raw(v0_tree).encode()[..])],
|
||||
&[],
|
||||
).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
load_decode::<_, u32>(&client, BABE_EPOCH_CHANGES_VERSION).unwrap(),
|
||||
None,
|
||||
);
|
||||
|
||||
let epoch_changes = load_epoch_changes::<TestBlock, _>(&client).unwrap();
|
||||
|
||||
assert!(
|
||||
epoch_changes.lock()
|
||||
.tree()
|
||||
.iter()
|
||||
.map(|(_, _, epoch)| epoch.clone())
|
||||
.collect::<Vec<_>>() ==
|
||||
vec![PersistedEpochHeader::Regular(EpochHeader {
|
||||
start_slot: 0,
|
||||
end_slot: 100,
|
||||
})],
|
||||
); // PersistedEpochHeader does not implement Debug, so we use assert! directly.
|
||||
|
||||
write_epoch_changes::<TestBlock, _, _>(
|
||||
&epoch_changes.lock(),
|
||||
|values| {
|
||||
client.insert_aux(values, &[]).unwrap();
|
||||
},
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
load_decode::<_, u32>(&client, BABE_EPOCH_CHANGES_VERSION).unwrap(),
|
||||
Some(1),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
//! Generic utilities for epoch-based consensus engines.
|
||||
|
||||
pub mod migration;
|
||||
|
||||
use std::{sync::Arc, ops::Add, collections::BTreeMap, borrow::{Borrow, BorrowMut}};
|
||||
use parking_lot::Mutex;
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
// Copyright 2019-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/>.
|
||||
|
||||
//! Migration types for epoch changes.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use codec::{Encode, Decode};
|
||||
use fork_tree::ForkTree;
|
||||
use sp_runtime::traits::{Block as BlockT, NumberFor};
|
||||
use crate::{Epoch, EpochChanges, PersistedEpoch, PersistedEpochHeader};
|
||||
|
||||
/// Legacy definition of epoch changes.
|
||||
#[derive(Clone, Encode, Decode)]
|
||||
pub struct EpochChangesV0<Hash, Number, E: Epoch> {
|
||||
inner: ForkTree<Hash, Number, PersistedEpoch<E>>,
|
||||
}
|
||||
|
||||
/// Type alias for legacy definition of epoch changes.
|
||||
pub type EpochChangesForV0<Block, Epoch> = EpochChangesV0<<Block as BlockT>::Hash, NumberFor<Block>, Epoch>;
|
||||
|
||||
impl<Hash, Number, E: Epoch> EpochChangesV0<Hash, Number, E> where
|
||||
Hash: PartialEq + Ord + Copy,
|
||||
Number: Ord + Copy,
|
||||
{
|
||||
/// Create a new value of this type from raw.
|
||||
pub fn from_raw(inner: ForkTree<Hash, Number, PersistedEpoch<E>>) -> Self {
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
/// Migrate the type into current epoch changes definition.
|
||||
pub fn migrate(self) -> EpochChanges<Hash, Number, E> {
|
||||
let mut epochs = BTreeMap::new();
|
||||
|
||||
let inner = self.inner.map(&mut |hash, number, data| {
|
||||
let header = PersistedEpochHeader::from(&data);
|
||||
epochs.insert((*hash, *number), data);
|
||||
header
|
||||
});
|
||||
|
||||
EpochChanges { inner, epochs }
|
||||
}
|
||||
}
|
||||
@@ -294,7 +294,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
impl Trait for Test {
|
||||
|
||||
@@ -62,7 +62,7 @@ impl frame_system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -432,7 +432,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -188,12 +188,6 @@ decl_module! {
|
||||
Self::deposit_vrf_output(&vrf_output);
|
||||
}
|
||||
}
|
||||
|
||||
fn on_runtime_upgrade() {
|
||||
for i in 0..=SegmentIndex::get() {
|
||||
UnderConstruction::migrate_key_from_blake(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ impl frame_system::Trait for Test {
|
||||
type MaximumBlockLength = MaximumBlockLength;
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ use frame_support::{
|
||||
Currency, OnKilledAccount, OnUnbalanced, TryDrop, StoredMap,
|
||||
WithdrawReason, WithdrawReasons, LockIdentifier, LockableCurrency, ExistenceRequirement,
|
||||
Imbalance, SignedImbalance, ReservableCurrency, Get, ExistenceRequirement::KeepAlive,
|
||||
ExistenceRequirement::AllowDeath, IsDeadAccount, BalanceStatus as Status, MigrateAccount,
|
||||
ExistenceRequirement::AllowDeath, IsDeadAccount, BalanceStatus as Status,
|
||||
}
|
||||
};
|
||||
use sp_runtime::{
|
||||
@@ -531,12 +531,6 @@ decl_module! {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait<I>, I: Instance> MigrateAccount<T::AccountId> for Module<T, I> {
|
||||
fn migrate_account(account: &T::AccountId) {
|
||||
Locks::<T, I>::migrate_key_from_blake(account);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait<I>, I: Instance> Module<T, I> {
|
||||
// PRIVATE MUTABLES
|
||||
|
||||
@@ -856,7 +850,7 @@ impl<T: Subtrait<I>, I: Instance> frame_system::Trait for ElevatedTrait<T, I> {
|
||||
type AvailableBlockRatio = T::AvailableBlockRatio;
|
||||
type Version = T::Version;
|
||||
type ModuleToIndex = T::ModuleToIndex;
|
||||
type MigrateAccount = (); type OnNewAccount = T::OnNewAccount;
|
||||
type OnNewAccount = T::OnNewAccount;
|
||||
type OnKilledAccount = T::OnKilledAccount;
|
||||
type AccountData = T::AccountData;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ impl frame_system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = super::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -66,7 +66,7 @@ impl frame_system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = super::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = Module<Test>;
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -71,7 +71,7 @@ impl frame_system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -168,17 +168,6 @@ decl_error! {
|
||||
}
|
||||
}
|
||||
|
||||
mod migration {
|
||||
use super::*;
|
||||
|
||||
pub fn migrate<T: Trait<I>, I: Instance>() {
|
||||
for p in Proposals::<T, I>::get().into_iter() {
|
||||
ProposalOf::<T, I>::migrate_key_from_blake(&p);
|
||||
Voting::<T, I>::migrate_key_from_blake(&p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Note: this module is not benchmarked. The weights are obtained based on the similarity of the
|
||||
// executed logic with other democracy function. Note that councillor operations are assigned to the
|
||||
// operational class.
|
||||
@@ -188,10 +177,6 @@ decl_module! {
|
||||
|
||||
fn deposit_event() = default;
|
||||
|
||||
fn on_runtime_upgrade() {
|
||||
migration::migrate::<T, I>();
|
||||
}
|
||||
|
||||
/// Set the collective's membership.
|
||||
///
|
||||
/// - `new_members`: The new member list. Be nice to the chain and
|
||||
@@ -550,7 +535,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
impl Trait<Instance1> for Test {
|
||||
|
||||
@@ -116,7 +116,7 @@ impl frame_system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = Contracts;
|
||||
}
|
||||
impl pallet_balances::Trait for Test {
|
||||
|
||||
@@ -170,7 +170,6 @@ use frame_system::{self as system, ensure_signed, ensure_root};
|
||||
|
||||
mod vote_threshold;
|
||||
pub use vote_threshold::{Approved, VoteThreshold};
|
||||
use frame_support::traits::MigrateAccount;
|
||||
|
||||
const DEMOCRACY_ID: LockIdentifier = *b"democrac";
|
||||
|
||||
@@ -584,41 +583,10 @@ decl_error! {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> MigrateAccount<T::AccountId> for Module<T> {
|
||||
fn migrate_account(a: &T::AccountId) {
|
||||
Proxy::<T>::migrate_key_from_blake(a);
|
||||
Locks::<T>::migrate_key_from_blake(a);
|
||||
Delegations::<T>::migrate_key_from_blake(a);
|
||||
for i in LowestUnbaked::get()..ReferendumCount::get() {
|
||||
VoteOf::<T>::migrate_key_from_blake((i, a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod migration {
|
||||
use super::*;
|
||||
pub fn migrate<T: Trait>() {
|
||||
Blacklist::<T>::remove_all();
|
||||
Cancellations::<T>::remove_all();
|
||||
for i in LowestUnbaked::get()..ReferendumCount::get() {
|
||||
VotersFor::<T>::migrate_key_from_blake(i);
|
||||
ReferendumInfoOf::<T>::migrate_key_from_blake(i);
|
||||
}
|
||||
for (p, h, _) in PublicProps::<T>::get().into_iter() {
|
||||
DepositOf::<T>::migrate_key_from_blake(p);
|
||||
Preimages::<T>::migrate_key_from_blake(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
type Error = Error<T>;
|
||||
|
||||
fn on_runtime_upgrade() {
|
||||
migration::migrate::<T>();
|
||||
}
|
||||
|
||||
/// The minimum period of locking and the period between a proposal being approved and enacted.
|
||||
///
|
||||
/// It should generally be a little more than the unstake period to ensure that
|
||||
@@ -1639,7 +1607,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -95,7 +95,6 @@ use frame_support::{
|
||||
};
|
||||
use sp_phragmen::ExtendedBalance;
|
||||
use frame_system::{self as system, ensure_signed, ensure_root};
|
||||
use frame_support::traits::MigrateAccount;
|
||||
|
||||
const MODULE_ID: LockIdentifier = *b"phrelect";
|
||||
|
||||
@@ -474,14 +473,6 @@ decl_event!(
|
||||
}
|
||||
);
|
||||
|
||||
impl<T: Trait> MigrateAccount<T::AccountId> for Module<T> {
|
||||
fn migrate_account(a: &T::AccountId) {
|
||||
if StakeOf::<T>::migrate_key_from_blake(a).is_some() {
|
||||
VotesOf::<T>::migrate_key_from_blake(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> Module<T> {
|
||||
/// Attempts to remove a member `who`. If a runner up exists, it is used as the replacement.
|
||||
/// Otherwise, `Ok(false)` is returned to signal the caller.
|
||||
@@ -825,7 +816,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ impl frame_system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ impl frame_system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -731,7 +731,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -481,7 +481,7 @@ mod tests {
|
||||
type Version = RuntimeVersion;
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -262,7 +262,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -1123,7 +1123,7 @@ impl<T: Subtrait> frame_system::Trait for ElevatedTrait<T> {
|
||||
type Version = T::Version;
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
impl<T: Subtrait> Trait for ElevatedTrait<T> {
|
||||
|
||||
@@ -63,7 +63,7 @@ impl frame_system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -39,4 +39,3 @@ std = [
|
||||
"pallet-session/std",
|
||||
"pallet-finality-tracker/std",
|
||||
]
|
||||
migrate-authorities = []
|
||||
|
||||
@@ -151,13 +151,6 @@ decl_error! {
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as GrandpaFinality {
|
||||
/// DEPRECATED
|
||||
///
|
||||
/// This used to store the current authority set, which has been migrated to the well-known
|
||||
/// GRANDPA_AUTHORITIES_KEY unhashed key.
|
||||
#[cfg(feature = "migrate-authorities")]
|
||||
pub(crate) Authorities get(fn authorities): AuthorityList;
|
||||
|
||||
/// State of the current authority set.
|
||||
State get(fn state): StoredState<T::BlockNumber> = StoredState::Live;
|
||||
|
||||
@@ -184,15 +177,6 @@ decl_storage! {
|
||||
}
|
||||
}
|
||||
|
||||
mod migration {
|
||||
use super::*;
|
||||
pub fn migrate<T: Trait>() {
|
||||
for i in 0..=CurrentSetId::get() {
|
||||
SetIdSession::migrate_key_from_blake(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
type Error = Error<T>;
|
||||
@@ -205,15 +189,6 @@ decl_module! {
|
||||
// FIXME: https://github.com/paritytech/substrate/issues/1112
|
||||
}
|
||||
|
||||
fn on_runtime_upgrade() {
|
||||
migration::migrate::<T>();
|
||||
}
|
||||
|
||||
fn on_initialize() {
|
||||
#[cfg(feature = "migrate-authorities")]
|
||||
Self::migrate_authorities();
|
||||
}
|
||||
|
||||
fn on_finalize(block_number: T::BlockNumber) {
|
||||
// check for scheduled pending authority set changes
|
||||
if let Some(pending_change) = <PendingChange<T>>::get() {
|
||||
@@ -384,13 +359,6 @@ impl<T: Trait> Module<T> {
|
||||
Self::set_grandpa_authorities(authorities);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "migrate-authorities")]
|
||||
fn migrate_authorities() {
|
||||
if Authorities::exists() {
|
||||
Self::set_grandpa_authorities(&Authorities::take());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> Module<T> {
|
||||
|
||||
@@ -66,7 +66,7 @@ impl frame_system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -318,21 +318,3 @@ fn time_slot_have_sane_ord() {
|
||||
];
|
||||
assert!(FIXTURE.windows(2).all(|f| f[0] < f[1]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "migrate-authorities")]
|
||||
fn authorities_migration() {
|
||||
use sp_runtime::traits::OnInitialize;
|
||||
|
||||
with_externalities(&mut new_test_ext(vec![]), || {
|
||||
let authorities = to_authorities(vec![(1, 1), (2, 1), (3, 1)]);
|
||||
|
||||
Authorities::put(authorities.clone());
|
||||
assert!(Grandpa::grandpa_authorities().is_empty());
|
||||
|
||||
Grandpa::on_initialize(1);
|
||||
|
||||
assert!(!Authorities::exists());
|
||||
assert_eq!(Grandpa::grandpa_authorities(), authorities);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@ use frame_support::{
|
||||
weights::SimpleDispatchInfo,
|
||||
};
|
||||
use frame_system::{self as system, ensure_signed, ensure_root};
|
||||
use frame_support::traits::MigrateAccount;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
pub mod benchmarking;
|
||||
@@ -887,18 +886,6 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> MigrateAccount<T::AccountId> for Module<T> {
|
||||
fn migrate_account(a: &T::AccountId) {
|
||||
if IdentityOf::<T>::migrate_key_from_blake(a).is_some() {
|
||||
if let Some((_, subs)) = SubsOf::<T>::migrate_key_from_blake(a) {
|
||||
for sub in subs.into_iter() {
|
||||
SuperOf::<T>::migrate_key_from_blake(sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -949,7 +936,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -95,7 +95,6 @@ use frame_support::{
|
||||
};
|
||||
use frame_system::{self as system, ensure_none};
|
||||
use frame_system::offchain::SubmitUnsignedTransaction;
|
||||
use frame_support::traits::MigrateAccount;
|
||||
|
||||
pub mod sr25519 {
|
||||
mod app_sr25519 {
|
||||
@@ -303,38 +302,12 @@ decl_error! {
|
||||
}
|
||||
}
|
||||
|
||||
mod migration {
|
||||
use super::*;
|
||||
use frame_support::Blake2_256;
|
||||
pub fn migrate<T: Trait>() {
|
||||
let current_index = <pallet_session::Module<T>>::current_index();
|
||||
let key_count = Keys::<T>::get().len() as AuthIndex;
|
||||
for i in 0..key_count {
|
||||
ReceivedHeartbeats::migrate_keys::<Blake2_256, Blake2_256, _, _>(current_index, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> MigrateAccount<T::AccountId> for Module<T> {
|
||||
fn migrate_account(a: &T::AccountId) {
|
||||
use frame_support::Blake2_256;
|
||||
let current_index = <pallet_session::Module<T>>::current_index();
|
||||
if let Ok(v) = a.using_encoded(|mut d| T::ValidatorId::decode(&mut d)) {
|
||||
AuthoredBlocks::<T>::migrate_keys::<Blake2_256, Blake2_256, _, _>(current_index, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
type Error = Error<T>;
|
||||
|
||||
fn deposit_event() = default;
|
||||
|
||||
fn on_runtime_upgrade() {
|
||||
migration::migrate::<T>();
|
||||
}
|
||||
|
||||
fn heartbeat(
|
||||
origin,
|
||||
heartbeat: Heartbeat<T::BlockNumber>,
|
||||
|
||||
@@ -119,7 +119,7 @@ impl frame_system::Trait for Runtime {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ impl frame_system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -321,7 +321,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
ord_parameter_types! {
|
||||
|
||||
@@ -286,7 +286,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -90,7 +90,7 @@ impl frame_system::Trait for Runtime {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,6 @@ use frame_support::{
|
||||
traits::{Currency, ReservableCurrency, Get, BalanceStatus},
|
||||
};
|
||||
use frame_system::{self as system, ensure_signed, ensure_root};
|
||||
use frame_support::traits::MigrateAccount;
|
||||
|
||||
#[cfg(test)]
|
||||
mod mock;
|
||||
@@ -258,13 +257,6 @@ decl_storage! {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> MigrateAccount<T::AccountId> for Module<T> {
|
||||
fn migrate_account(a: &T::AccountId) {
|
||||
Recoverable::<T>::migrate_key_from_blake(a);
|
||||
Proxy::<T>::migrate_key_from_blake(a);
|
||||
}
|
||||
}
|
||||
|
||||
decl_event! {
|
||||
/// Events type.
|
||||
pub enum Event<T> where
|
||||
|
||||
@@ -79,7 +79,7 @@ impl frame_system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u128>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ impl frame_system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -67,25 +67,7 @@ decl_storage! {
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
fn on_initialize(_n: T::BlockNumber) {
|
||||
CachedObsolete::<T>::remove_all();
|
||||
}
|
||||
fn on_runtime_upgrade() {
|
||||
migration::migrate::<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod migration {
|
||||
use super::*;
|
||||
pub fn migrate<T: Trait>() {
|
||||
if let Some((begin, end)) = StoredRange::get() {
|
||||
for i in begin..end {
|
||||
HistoricalSessions::<T>::migrate_key_from_blake(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
|
||||
}
|
||||
|
||||
impl<T: Trait> Module<T> {
|
||||
|
||||
@@ -109,7 +109,6 @@ use frame_support::{ensure, decl_module, decl_event, decl_storage, decl_error, C
|
||||
use frame_support::{traits::{Get, FindAuthor, ValidatorRegistration}, Parameter};
|
||||
use frame_support::dispatch::{self, DispatchResult, DispatchError};
|
||||
use frame_system::{self as system, ensure_signed};
|
||||
use frame_support::traits::MigrateAccount;
|
||||
|
||||
#[cfg(test)]
|
||||
mod mock;
|
||||
@@ -504,18 +503,6 @@ decl_module! {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> MigrateAccount<T::AccountId> for Module<T> {
|
||||
fn migrate_account(a: &T::AccountId) {
|
||||
if let Some(v) = T::ValidatorIdOf::convert(a.clone()) {
|
||||
if let Some(keys) = NextKeys::<T>::migrate_key_from_blake(v) {
|
||||
for id in T::Keys::key_ids() {
|
||||
KeyOwner::<T>::migrate_key_from_blake((*id, keys.get_raw(*id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> Module<T> {
|
||||
/// Move on to next session. Register new validator set and session keys. Changes
|
||||
/// to the validator set have a session of delay to take effect. This allows for
|
||||
|
||||
@@ -179,7 +179,7 @@ impl frame_system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -261,7 +261,10 @@ use sp_runtime::{Percent, ModuleId, RuntimeDebug,
|
||||
};
|
||||
use frame_support::{decl_error, decl_module, decl_storage, decl_event, ensure, dispatch::DispatchResult};
|
||||
use frame_support::weights::SimpleDispatchInfo;
|
||||
use frame_support::traits::{Currency, ReservableCurrency, Randomness, Get, ChangeMembers, BalanceStatus, ExistenceRequirement::AllowDeath, MigrateAccount};
|
||||
use frame_support::traits::{
|
||||
Currency, ReservableCurrency, Randomness, Get, ChangeMembers, BalanceStatus,
|
||||
ExistenceRequirement::AllowDeath
|
||||
};
|
||||
use frame_system::{self as system, ensure_signed, ensure_root};
|
||||
|
||||
type BalanceOf<T, I> = <<T as Trait<I>>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
|
||||
@@ -1130,12 +1133,6 @@ decl_event! {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> MigrateAccount<T::AccountId> for Module<T> {
|
||||
fn migrate_account(a: &T::AccountId) {
|
||||
Payouts::<T>::migrate_key_from_blake(a);
|
||||
}
|
||||
}
|
||||
|
||||
/// Simple ensure origin struct to filter for the founder account.
|
||||
pub struct EnsureFounder<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<T: Trait> EnsureOrigin<T::Origin> for EnsureFounder<T> {
|
||||
|
||||
@@ -77,7 +77,7 @@ impl frame_system::Trait for Test {
|
||||
type AvailableBlockRatio = AvailableBlockRatio;
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ frame-benchmarking = { version = "2.0.0-alpha.4", path = "../benchmarking" }
|
||||
rand_chacha = { version = "0.2" }
|
||||
|
||||
[features]
|
||||
migrate = []
|
||||
default = ["std"]
|
||||
std = [
|
||||
"serde",
|
||||
|
||||
@@ -286,7 +286,6 @@ use sp_runtime::{Serialize, Deserialize};
|
||||
use frame_system::{self as system, ensure_signed, ensure_root};
|
||||
|
||||
use sp_phragmen::ExtendedBalance;
|
||||
use frame_support::traits::MigrateAccount;
|
||||
|
||||
const DEFAULT_MINIMUM_VALIDATOR_COUNT: u32 = 4;
|
||||
pub const MAX_NOMINATIONS: usize = 16;
|
||||
@@ -956,10 +955,6 @@ decl_module! {
|
||||
|
||||
fn deposit_event() = default;
|
||||
|
||||
fn on_runtime_upgrade() {
|
||||
migrate::<T>();
|
||||
}
|
||||
|
||||
fn on_finalize() {
|
||||
// Set the start of the first era.
|
||||
if let Some(mut active_era) = Self::active_era() {
|
||||
@@ -1480,30 +1475,6 @@ decl_module! {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> MigrateAccount<T::AccountId> for Module<T> {
|
||||
fn migrate_account(a: &T::AccountId) {
|
||||
if let Some(controller) = Bonded::<T>::migrate_key_from_blake(a) {
|
||||
Ledger::<T>::migrate_key_from_blake(controller);
|
||||
Payee::<T>::migrate_key_from_blake(a);
|
||||
Validators::<T>::migrate_key_from_blake(a);
|
||||
Nominators::<T>::migrate_key_from_blake(a);
|
||||
SlashingSpans::<T>::migrate_key_from_blake(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn migrate<T: Trait>() {
|
||||
if let Some(current_era) = CurrentEra::get() {
|
||||
let history_depth = HistoryDepth::get();
|
||||
for era in current_era.saturating_sub(history_depth)..=current_era {
|
||||
ErasStartSessionIndex::migrate_key_from_blake(era);
|
||||
ErasValidatorReward::<T>::migrate_key_from_blake(era);
|
||||
ErasRewardPoints::<T>::migrate_key_from_blake(era);
|
||||
ErasTotalStake::<T>::migrate_key_from_blake(era);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> Module<T> {
|
||||
// PUBLIC IMMUTABLES
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ impl frame_system::Trait for Test {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
impl pallet_balances::Trait for Test {
|
||||
|
||||
@@ -29,13 +29,6 @@ use sp_runtime::{
|
||||
use crate::dispatch::Parameter;
|
||||
use crate::storage::StorageMap;
|
||||
|
||||
/// Migrate a given account.
|
||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||
pub trait MigrateAccount<A> {
|
||||
/// Migrate the `account`.
|
||||
fn migrate_account(account: &A);
|
||||
}
|
||||
|
||||
/// An abstraction of a value stored within storage, but possibly as part of a larger composite
|
||||
/// item.
|
||||
pub trait StoredMap<K, T> {
|
||||
|
||||
@@ -77,7 +77,7 @@ impl system::Trait for Runtime {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ use frame_support::{
|
||||
decl_module, decl_event, decl_storage, decl_error, storage, Parameter, ensure, debug,
|
||||
traits::{
|
||||
Contains, Get, ModuleToIndex, OnNewAccount, OnKilledAccount, IsDeadAccount, Happened,
|
||||
StoredMap, MigrateAccount,
|
||||
StoredMap,
|
||||
},
|
||||
weights::{Weight, DispatchInfo, DispatchClass, SimpleDispatchInfo, FunctionOf},
|
||||
};
|
||||
@@ -126,7 +126,6 @@ use codec::{Encode, Decode, FullCodec, EncodeLike};
|
||||
use sp_io::TestExternalities;
|
||||
|
||||
pub mod offchain;
|
||||
mod migration;
|
||||
|
||||
/// Compute the trie root of a list of extrinsics.
|
||||
pub fn extrinsics_root<H: Hash, E: codec::Encode>(extrinsics: &[E]) -> H::Output {
|
||||
@@ -222,9 +221,6 @@ pub trait Trait: 'static + Eq + Clone {
|
||||
///
|
||||
/// All resources should be cleaned up associated with the given account.
|
||||
type OnKilledAccount: OnKilledAccount<Self::AccountId>;
|
||||
|
||||
/// Migrate an account.
|
||||
type MigrateAccount: MigrateAccount<Self::AccountId>;
|
||||
}
|
||||
|
||||
pub type DigestOf<T> = generic::Digest<<T as Trait>::Hash>;
|
||||
@@ -460,15 +456,6 @@ decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
type Error = Error<T>;
|
||||
|
||||
fn on_runtime_upgrade() {
|
||||
migration::migrate::<T>();
|
||||
|
||||
// Remove the old `RuntimeUpgraded` storage entry.
|
||||
let mut runtime_upgraded_key = sp_io::hashing::twox_128(b"System").to_vec();
|
||||
runtime_upgraded_key.extend(&sp_io::hashing::twox_128(b"RuntimeUpgraded"));
|
||||
sp_io::storage::clear(&runtime_upgraded_key);
|
||||
}
|
||||
|
||||
/// A dispatch that will fill the block weight up to the given ratio.
|
||||
// TODO: This should only be available for testing, rather than in general usage, but
|
||||
// that's not possible at present (since it's within the decl_module macro).
|
||||
@@ -577,21 +564,6 @@ decl_module! {
|
||||
ensure!(account.data == T::AccountData::default(), Error::<T>::NonDefaultComposite);
|
||||
Account::<T>::remove(who);
|
||||
}
|
||||
|
||||
#[weight = FunctionOf(
|
||||
|(accounts,): (&Vec<T::AccountId>,)| accounts.len() as u32 * 10_000,
|
||||
DispatchClass::Normal,
|
||||
true,
|
||||
)]
|
||||
fn migrate_accounts(origin, accounts: Vec<T::AccountId>) {
|
||||
let _ = ensure_signed(origin)?;
|
||||
for a in &accounts {
|
||||
if Account::<T>::migrate_key_from_blake(a).is_some() {
|
||||
// Inform other modules about the account.
|
||||
T::MigrateAccount::migrate_account(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1570,7 +1542,7 @@ mod tests {
|
||||
type Version = Version;
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = u32;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = RecordKilled;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
use super::*;
|
||||
use sp_runtime::traits::SaturatedConversion;
|
||||
|
||||
pub fn migrate<T: Trait>() {
|
||||
// Number is current block - we obviously don't know that hash.
|
||||
// Number - 1 is the parent block, who hash we record in this block, but then that's already
|
||||
// with the new storage so we don't migrate it.
|
||||
// Number - 2 is therefore the most recent block's hash that needs migrating.
|
||||
if Number::<T>::get() > One::one() {
|
||||
sp_runtime::print("Migrating BlockHash...");
|
||||
BlockHash::<T>::migrate_key_from_blake(T::BlockNumber::zero());
|
||||
let mut n = Number::<T>::get() - One::one() - One::one();
|
||||
while !n.is_zero() {
|
||||
sp_runtime::print(n.saturated_into::<u32>());
|
||||
if BlockHash::<T>::migrate_key_from_blake(n).is_none() {
|
||||
break;
|
||||
}
|
||||
n -= One::one();
|
||||
}
|
||||
}
|
||||
|
||||
sp_runtime::print("Migrating Accounts...");
|
||||
let mut count = 0u32;
|
||||
if let Ok(accounts) = Vec::<T::AccountId>::decode(&mut &include_bytes!("accounts.scale")[..]) {
|
||||
for a in &accounts {
|
||||
if Account::<T>::migrate_key_from_blake(a).is_some() {
|
||||
// Inform other modules about the account.
|
||||
T::MigrateAccount::migrate_account(a);
|
||||
count += 1;
|
||||
if count % 1000 == 0 {
|
||||
sp_runtime::print(count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sp_runtime::print(count);
|
||||
}
|
||||
@@ -278,7 +278,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -310,7 +310,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -283,22 +283,8 @@ decl_error! {
|
||||
}
|
||||
}
|
||||
|
||||
mod migration {
|
||||
use super::*;
|
||||
pub fn migrate<T: Trait>() {
|
||||
for i in 0..ProposalCount::get() {
|
||||
Proposals::<T>::migrate_key_from_blake(i);
|
||||
}
|
||||
Reasons::<T>::remove_all();
|
||||
}
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
fn on_runtime_upgrade() {
|
||||
migration::migrate::<T>();
|
||||
}
|
||||
|
||||
/// Fraction of a proposal's value that should be bonded in order to place the proposal.
|
||||
/// An accepted proposal gets these back. A rejected proposal does not.
|
||||
const ProposalBond: Permill = T::ProposalBond::get();
|
||||
@@ -776,7 +762,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -623,7 +623,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -53,7 +53,10 @@ use sp_runtime::{DispatchResult, RuntimeDebug, traits::{
|
||||
StaticLookup, Zero, AtLeast32Bit, MaybeSerializeDeserialize, Convert
|
||||
}};
|
||||
use frame_support::{decl_module, decl_event, decl_storage, decl_error, ensure};
|
||||
use frame_support::traits::{Currency, LockableCurrency, VestingSchedule, WithdrawReason, LockIdentifier, ExistenceRequirement, Get, MigrateAccount};
|
||||
use frame_support::traits::{
|
||||
Currency, LockableCurrency, VestingSchedule, WithdrawReason, LockIdentifier,
|
||||
ExistenceRequirement, Get
|
||||
};
|
||||
use frame_support::weights::SimpleDispatchInfo;
|
||||
use frame_system::{self as system, ensure_signed};
|
||||
|
||||
@@ -254,12 +257,6 @@ decl_module! {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> MigrateAccount<T::AccountId> for Module<T> {
|
||||
fn migrate_account(a: &T::AccountId) {
|
||||
Vesting::<T>::migrate_key_from_blake(a);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> Module<T> {
|
||||
/// (Re)set or remove the module's currency lock on `who`'s account in accordance with their
|
||||
/// current unvested amount.
|
||||
@@ -388,7 +385,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
impl pallet_balances::Trait for Test {
|
||||
|
||||
@@ -391,7 +391,7 @@ impl frame_system::Trait for Runtime {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user