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
+16 -8
View File
@@ -84,18 +84,18 @@
use sp_std::prelude::*;
use sp_runtime::{
print, DispatchResult, DispatchError, Perbill,
traits::{Zero, StaticLookup, Convert},
print, DispatchResult, DispatchError, Perbill, traits::{Zero, StaticLookup, Convert},
};
use frame_support::{
decl_storage, decl_event, ensure, decl_module, decl_error, weights::SimpleDispatchInfo,
traits::{
storage::{StorageMap, IterableStorageMap}, traits::{
Currency, Get, LockableCurrency, LockIdentifier, ReservableCurrency, WithdrawReasons,
ChangeMembers, OnUnbalanced, WithdrawReason, Contains, BalanceStatus
}
};
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";
@@ -160,9 +160,9 @@ decl_storage! {
pub ElectionRounds get(fn election_rounds): u32 = Zero::zero();
/// Votes of a particular voter, with the round index of the votes.
pub VotesOf get(fn votes_of): linked_map hasher(blake2_256) T::AccountId => Vec<T::AccountId>;
pub VotesOf get(fn votes_of): map hasher(twox_64_concat) T::AccountId => Vec<T::AccountId>;
/// Locked stake of a voter.
pub StakeOf get(fn stake_of): map hasher(blake2_256) T::AccountId => BalanceOf<T>;
pub StakeOf get(fn stake_of): map hasher(twox_64_concat) T::AccountId => BalanceOf<T>;
/// The present candidate list. Sorted based on account-id. A current member or a runner can
/// never enter this vector and is always implicitly assumed to be a candidate.
@@ -474,6 +474,14 @@ 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.
@@ -637,7 +645,7 @@ impl<T: Trait> Module<T> {
// previous runners_up are also always candidates for the next round.
candidates.append(&mut Self::runners_up_ids());
let voters_and_votes = <VotesOf<T>>::enumerate()
let voters_and_votes = VotesOf::<T>::iter()
.map(|(v, i)| (v, i))
.collect::<Vec<(T::AccountId, Vec<T::AccountId>)>>();
let maybe_phragmen_result = sp_phragmen::elect::<_, _, _, T::CurrencyToVote, Perbill>(
@@ -817,7 +825,7 @@ mod tests {
type Version = ();
type ModuleToIndex = ();
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type MigrateAccount = (); type OnNewAccount = ();
type OnKilledAccount = ();
}
@@ -1001,7 +1009,7 @@ mod tests {
}
fn all_voters() -> Vec<u64> {
<VotesOf<Test>>::enumerate().map(|(v, _)| v).collect::<Vec<u64>>()
<VotesOf<Test>>::iter().map(|(v, _)| v).collect::<Vec<u64>>()
}
fn balances(who: &u64) -> (u64, u64) {