Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Remove migration code. (#5291)
Browse files Browse the repository at this point in the history
* Remove migration code.

* Fix cargo

* Bump spec version
  • Loading branch information
gavofyork authored and bkchr committed Mar 24, 2020
1 parent 5794cf4 commit 8200778
Show file tree
Hide file tree
Showing 61 changed files with 61 additions and 514 deletions.
2 changes: 1 addition & 1 deletion bin/node-template/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 4 additions & 6 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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",
]
3 changes: 1 addition & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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 = ();
}
Expand Down
77 changes: 2 additions & 75 deletions client/consensus/babe/src/aux_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
)?,
Expand Down Expand Up @@ -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),
);
}
}
2 changes: 0 additions & 2 deletions client/consensus/epochs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
55 changes: 0 additions & 55 deletions client/consensus/epochs/src/migration.rs

This file was deleted.

2 changes: 1 addition & 1 deletion frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ mod tests {
type Version = ();
type ModuleToIndex = ();
type AccountData = ();
type MigrateAccount = (); type OnNewAccount = ();
type OnNewAccount = ();
type OnKilledAccount = ();
}
impl Trait for Test {
Expand Down
2 changes: 1 addition & 1 deletion frame/aura/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl frame_system::Trait for Test {
type Version = ();
type ModuleToIndex = ();
type AccountData = ();
type MigrateAccount = (); type OnNewAccount = ();
type OnNewAccount = ();
type OnKilledAccount = ();
}

Expand Down
2 changes: 1 addition & 1 deletion frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ mod tests {
type Version = ();
type ModuleToIndex = ();
type AccountData = ();
type MigrateAccount = (); type OnNewAccount = ();
type OnNewAccount = ();
type OnKilledAccount = ();
}

Expand Down
2 changes: 1 addition & 1 deletion frame/authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ mod tests {
type Version = ();
type ModuleToIndex = ();
type AccountData = ();
type MigrateAccount = (); type OnNewAccount = ();
type OnNewAccount = ();
type OnKilledAccount = ();
}

Expand Down
6 changes: 0 additions & 6 deletions frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ();
}

Expand Down
10 changes: 2 additions & 8 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion frame/balances/src/tests_composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
2 changes: 1 addition & 1 deletion frame/balances/src/tests_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
2 changes: 1 addition & 1 deletion frame/benchmarking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl frame_system::Trait for Test {
type Version = ();
type ModuleToIndex = ();
type AccountData = ();
type MigrateAccount = (); type OnNewAccount = ();
type OnNewAccount = ();
type OnKilledAccount = ();
}

Expand Down
17 changes: 1 addition & 16 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 8200778

Please sign in to comment.