Refactor away from opaque hashes (#5226)

* System.BlockHash

* Fix hash

* Introduce K/V iteration in all _concat maps

Also move across:
- System.Account (blake2_128_concat)
- Balances.Locks (twox_64_concat)
- ElectionsPhragmen.VotesOf (twox_64_concat)
- ElectionsPhragmen.StakeOf (twox_64_concat)
- Identity.IdentityOf (twox_64_concat)
- Identity.SubsOf (twox_64_concat)
- Society.Payouts (twox_64_concat)
- Session.NextKeys (twox_64_concat)
- Identity.SuperOf (blake2_128_concat)
- Session.KeyOwner (blake2_128_concat)
- Society.SuspendedCandidates (twox_64_concat)
- Society.SuspendedMembers (twox_64_concat)
- Society.Vouching (twox_64_concat)
- Society.Strikes (twox_64_concat)
- System.EventTopics
- Balances.Account

* Build fixes

* Ensure migration happens in correct order

* Staking.*

* Vesting.* Offences.*

* Democracy.*

* Babe.* Collective.*

* Grandpa.*

* Assets.* Benchmark.* Contracts.* Elections.* Asset.* Nicks.*

Also introduce real account list

* ImOnline.*

* Treasury.*

* Recovery.*

* Final bits.

* Docs

* Fix one test

* Fix test

* All passing except the UI tests

* Remove linked_map part 1

* Remove linked_map

* Some iterator utils for double maps.

* Remove old migrations

* Introduce tombstone for LinkedMap type

* Migration for genesis hash

* Fix build

* Fix hash

* Rename Map is_linked -> unused, keeping backwards compat (#5256)

* Update frame/balances/src/lib.rs

Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update frame/elections/src/lib.rs

Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>

* Remove old migration code.

* Update frame/system/src/lib.rs

Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update bin/node/runtime/src/lib.rs

Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>

* Fix hash

* fix session migration

* Fix watning

Co-authored-by: Jaco Greeff <jacogr@gmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Robert Habermeier <rphmeier@gmail.com>
This commit is contained in:
Gavin Wood
2020-03-16 23:19:53 +01:00
committed by GitHub
parent 846a9ce8c6
commit af9083f53b
94 changed files with 1111 additions and 2020 deletions
+17 -9
View File
@@ -77,10 +77,10 @@ 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;
mod migration;
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
type NegativeImbalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
@@ -386,18 +386,18 @@ decl_storage! {
trait Store for Module<T: Trait> as Identity {
/// Information that is pertinent to identify the entity behind an account.
pub IdentityOf get(fn identity):
map hasher(blake2_256) T::AccountId => Option<Registration<BalanceOf<T>>>;
map hasher(twox_64_concat) T::AccountId => Option<Registration<BalanceOf<T>>>;
/// The super-identity of an alternative "sub" identity together with its name, within that
/// context. If the account is not some other account's sub-identity, then just `None`.
pub SuperOf get(fn super_of):
map hasher(blake2_256) T::AccountId => Option<(T::AccountId, Data)>;
map hasher(blake2_128_concat) T::AccountId => Option<(T::AccountId, Data)>;
/// Alternative "sub" identities of this account.
///
/// The first item is the deposit, the second is a vector of the accounts.
pub SubsOf get(fn subs_of):
map hasher(blake2_256) T::AccountId => (BalanceOf<T>, Vec<T::AccountId>);
map hasher(twox_64_concat) T::AccountId => (BalanceOf<T>, Vec<T::AccountId>);
/// The set of registrars. Not expected to get very big as can only be added through a
/// special origin (likely a council motion).
@@ -874,10 +874,6 @@ decl_module! {
Self::deposit_event(RawEvent::IdentityKilled(target, deposit));
}
fn on_runtime_upgrade() {
migration::on_runtime_upgrade::<T>()
}
}
}
@@ -891,6 +887,18 @@ 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::*;
@@ -941,7 +949,7 @@ mod tests {
type Version = ();
type ModuleToIndex = ();
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type MigrateAccount = (); type OnNewAccount = ();
type OnKilledAccount = ();
}
parameter_types! {
-52
View File
@@ -1,52 +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/>.
//! Migration code to update storage.
use super::*;
use frame_support::storage::migration::{put_storage_value, take_storage_value, StorageIterator};
pub fn on_runtime_upgrade<T: Trait>() {
change_name_sudo_to_identity::<T>()
}
// Change the storage name used by this pallet from `Sudo` to `Identity`.
//
// Since the format of the storage items themselves have not changed, we do not
// need to keep track of a storage version. If the runtime does not need to be
// upgraded, nothing here will happen anyway.
fn change_name_sudo_to_identity<T: Trait>() {
sp_runtime::print("Migrating Identity.");
for (hash, identity_of) in StorageIterator::<Registration<BalanceOf<T>>>::new(b"Sudo", b"IdentityOf").drain() {
put_storage_value(b"Identity", b"IdentityOf", &hash, identity_of);
}
for (hash, super_of) in StorageIterator::<(T::AccountId, Data)>::new(b"Sudo", b"SuperOf").drain() {
put_storage_value(b"Identity", b"SuperOf", &hash, super_of);
}
for (hash, subs_of) in StorageIterator::<(BalanceOf<T>, Vec<T::AccountId>)>::new(b"Sudo", b"SubsOf").drain() {
put_storage_value(b"Identity", b"SubsOf", &hash, subs_of);
}
if let Some(registrars) = take_storage_value::<Vec<Option<RegistrarInfo<BalanceOf<T>, T::AccountId>>>>(b"Sudo", b"Registrars", &[]) {
put_storage_value(b"Identity", b"Registrars", &[], registrars);
}
sp_runtime::print("Done Identity.");
}