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

Refactor away from opaque hashes #5226

Merged
merged 44 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0b6f313
System.BlockHash
gavofyork Mar 11, 2020
051967a
Fix hash
gavofyork Mar 11, 2020
5fb1aeb
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
gavofyork Mar 11, 2020
3921666
Introduce K/V iteration in all _concat maps
gavofyork Mar 11, 2020
a926a45
Build fixes
gavofyork Mar 11, 2020
e73f349
Ensure migration happens in correct order
gavofyork Mar 11, 2020
1e8230d
Staking.*
gavofyork Mar 12, 2020
855f20e
Vesting.* Offences.*
gavofyork Mar 12, 2020
d195330
Democracy.*
gavofyork Mar 12, 2020
cc6a4d0
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
gavofyork Mar 12, 2020
c82856e
Babe.* Collective.*
gavofyork Mar 12, 2020
13ad20c
Grandpa.*
gavofyork Mar 12, 2020
bdde997
Assets.* Benchmark.* Contracts.* Elections.* Asset.* Nicks.*
gavofyork Mar 12, 2020
2cbc09e
ImOnline.*
gavofyork Mar 12, 2020
182ec5a
Treasury.*
gavofyork Mar 12, 2020
c573e56
Recovery.*
gavofyork Mar 12, 2020
cf69961
Final bits.
gavofyork Mar 12, 2020
c03a485
Docs
gavofyork Mar 12, 2020
0e3d187
Fix one test
gavofyork Mar 12, 2020
990e972
Fix test
gavofyork Mar 12, 2020
4e2acc9
All passing except the UI tests
gavofyork Mar 12, 2020
1c73a1f
Remove linked_map part 1
gavofyork Mar 12, 2020
5108dc9
Remove linked_map
gavofyork Mar 12, 2020
11a8b94
Some iterator utils for double maps.
gavofyork Mar 12, 2020
d14ba60
Remove old migrations
gavofyork Mar 12, 2020
becb495
Introduce tombstone for LinkedMap type
gavofyork Mar 13, 2020
fb97b30
Migration for genesis hash
gavofyork Mar 13, 2020
7ee5cee
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
gavofyork Mar 15, 2020
0d95a1e
Fix build
gavofyork Mar 15, 2020
1e52937
Fix hash
gavofyork Mar 15, 2020
869b18f
Rename Map is_linked -> unused, keeping backwards compat (#5256)
jacogr Mar 16, 2020
9eb0ea3
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
gavofyork Mar 16, 2020
f4e3c00
Update frame/balances/src/lib.rs
gavofyork Mar 16, 2020
43f3fb0
Update frame/elections/src/lib.rs
gavofyork Mar 16, 2020
3e50210
Remove old migration code.
gavofyork Mar 16, 2020
c90efd0
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
gavofyork Mar 16, 2020
fbbcf01
Update frame/system/src/lib.rs
gavofyork Mar 16, 2020
84af903
Update bin/node/runtime/src/lib.rs
gavofyork Mar 16, 2020
9bcf544
Merge branch 'gav-refactor-hashing' of github.com:paritytech/substrat…
gavofyork Mar 16, 2020
12382d8
Fix hash
gavofyork Mar 16, 2020
07e3361
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
gavofyork Mar 16, 2020
e971241
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
gavofyork Mar 16, 2020
a2ca4ea
fix session migration
rphmeier Mar 16, 2020
c34e064
Fix watning
gavofyork Mar 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 OnNewAccount = ();
type MigrateAccount = (); type OnNewAccount = ();
bkchr marked this conversation as resolved.
Show resolved Hide resolved
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 OnNewAccount = ();
type MigrateAccount = (); 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
1 change: 1 addition & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for people using this as inspiration for migration:
This order is incorrect because the account migration for Session depends on the migration for Staking. It thus needs to be e.g. ... Recovery, Staking, Session, Society, ...

type OnNewAccount = ();
type OnKilledAccount = ();
}
Expand Down
6 changes: 3 additions & 3 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ decl_error! {
decl_storage! {
trait Store for Module<T: Trait> as Assets {
/// The number of units of assets held by any given account.
Balances: map hasher(blake2_256) (T::AssetId, T::AccountId) => T::Balance;
Balances: map hasher(blake2_128_concat) (T::AssetId, T::AccountId) => T::Balance;
/// The next asset identifier up for grabs.
NextAssetId get(fn next_asset_id): T::AssetId;
/// The total unit supply of an asset.
TotalSupply: map hasher(blake2_256) T::AssetId => T::Balance;
TotalSupply: map hasher(twox_64_concat) T::AssetId => T::Balance;
}
}

Expand Down Expand Up @@ -294,7 +294,7 @@ mod tests {
type Version = ();
type ModuleToIndex = ();
type AccountData = ();
type OnNewAccount = ();
type MigrateAccount = (); 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 OnNewAccount = ();
type MigrateAccount = (); 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 OnNewAccount = ();
type MigrateAccount = (); 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 OnNewAccount = ();
type MigrateAccount = (); type OnNewAccount = ();
type OnKilledAccount = ();
}

Expand Down
8 changes: 7 additions & 1 deletion frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ decl_storage! {
/// We reset all segments and return to `0` at the beginning of every
/// epoch.
SegmentIndex build(|_| 0): u32;
UnderConstruction: map hasher(blake2_256) u32 => Vec<[u8; 32 /* VRF_OUTPUT_LENGTH */]>;
UnderConstruction: map hasher(twox_64_concat) u32 => Vec<[u8; 32 /* VRF_OUTPUT_LENGTH */]>;

/// Temporary value (cleared at block finalization) which is `Some`
/// if per-block initialization has already been called for current block.
Expand Down Expand Up @@ -188,6 +188,12 @@ decl_module! {
Self::deposit_vrf_output(&vrf_output);
}
}

fn on_runtime_upgrade() {
for i in 0..=SegmentIndex::get() {
UnderConstruction::migrate_key_from_blake(i);
rphmeier marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}

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 OnNewAccount = ();
type MigrateAccount = (); type OnNewAccount = ();
type OnKilledAccount = ();
}

Expand Down
14 changes: 10 additions & 4 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
ExistenceRequirement::AllowDeath, IsDeadAccount, BalanceStatus as Status, MigrateAccount,
}
};
use sp_runtime::{
Expand Down Expand Up @@ -372,11 +372,11 @@ decl_storage! {
/// is ever zero, then the entry *MUST* be removed.
///
/// NOTE: This is only used in the case that this module is used to store balances.
pub Account: map hasher(blake2_256) T::AccountId => AccountData<T::Balance>;
pub Account: map hasher(blake2_128_concat) T::AccountId => AccountData<T::Balance>;

/// Any liquidity locks on some account balances.
/// NOTE: Should only be accessed when setting, changing and freeing a lock.
pub Locks get(fn locks): map hasher(blake2_256) T::AccountId => Vec<BalanceLock<T::Balance>>;
pub Locks get(fn locks): map hasher(blake2_128_concat) T::AccountId => Vec<BalanceLock<T::Balance>>;

/// Storage version of the pallet.
///
Expand Down Expand Up @@ -531,6 +531,12 @@ 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 @@ -850,7 +856,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 OnNewAccount = T::OnNewAccount;
type MigrateAccount = (); 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 OnNewAccount = ();
type MigrateAccount = (); 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 OnNewAccount = ();
type MigrateAccount = (); type OnNewAccount = ();
type OnKilledAccount = Module<Test>;
}
parameter_types! {
Expand Down
6 changes: 3 additions & 3 deletions frame/benchmark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ pub trait Trait: system::Trait {
decl_storage! {
trait Store for Module<T: Trait> as Benchmark {
MyMemberList: Vec<T::AccountId>;
MyMemberMap: map hasher(blake2_256) T::AccountId => bool;
MyMemberMap: map hasher(blake2_128_concat) T::AccountId => bool;
MyValue: u32;
MyMap: map hasher(blake2_256) u32 => u32;
MyDoubleMap: double_map hasher(blake2_256) u32, hasher(blake2_256) u32 => u32;
MyMap: map hasher(twox_64_concat) u32 => u32;
MyDoubleMap: double_map hasher(twox_64_concat) u32, hasher(identity) u32 => u32;
}
}

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 OnNewAccount = ();
type MigrateAccount = (); type OnNewAccount = ();
type OnKilledAccount = ();
}

Expand Down
21 changes: 18 additions & 3 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ decl_storage! {
pub Proposals get(fn proposals): Vec<T::Hash>;
/// Actual proposal for a given hash, if it's current.
pub ProposalOf get(fn proposal_of):
map hasher(blake2_256) T::Hash => Option<<T as Trait<I>>::Proposal>;
map hasher(identity) T::Hash => Option<<T as Trait<I>>::Proposal>;
/// Votes on a given proposal, if it is ongoing.
pub Voting get(fn voting):
map hasher(blake2_256) T::Hash => Option<Votes<T::AccountId, T::BlockNumber>>;
map hasher(identity) T::Hash => Option<Votes<T::AccountId, T::BlockNumber>>;
/// Proposals so far.
pub ProposalCount get(fn proposal_count): u32;
/// The current members of the collective. This is stored sorted (just by value).
Expand Down Expand Up @@ -168,6 +168,17 @@ 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 @@ -177,6 +188,10 @@ 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 @@ -535,7 +550,7 @@ mod tests {
type Version = ();
type ModuleToIndex = ();
type AccountData = ();
type OnNewAccount = ();
type MigrateAccount = (); type OnNewAccount = ();
type OnKilledAccount = ();
}
impl Trait<Instance1> for Test {
Expand Down
11 changes: 3 additions & 8 deletions frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ mod rent;

#[cfg(test)]
mod tests;
mod migration;

use crate::exec::ExecutionContext;
use crate::account_db::{AccountDb, DirectAccountDb};
Expand Down Expand Up @@ -667,10 +666,6 @@ decl_module! {
fn on_finalize() {
GasSpent::kill();
}

fn on_runtime_upgrade() {
migration::on_runtime_upgrade::<T>()
}
}
}

Expand Down Expand Up @@ -934,13 +929,13 @@ decl_storage! {
/// Current cost schedule for contracts.
CurrentSchedule get(fn current_schedule) config(): Schedule = Schedule::default();
/// A mapping from an original code hash to the original code, untouched by instrumentation.
pub PristineCode: map hasher(blake2_256) CodeHash<T> => Option<Vec<u8>>;
pub PristineCode: map hasher(identity) CodeHash<T> => Option<Vec<u8>>;
/// A mapping between an original code hash and instrumented wasm code, ready for execution.
pub CodeStorage: map hasher(blake2_256) CodeHash<T> => Option<wasm::PrefabWasmModule>;
pub CodeStorage: map hasher(identity) CodeHash<T> => Option<wasm::PrefabWasmModule>;
/// The subtrie counter.
pub AccountCounter: u64 = 0;
/// The code associated with a given account.
pub ContractInfoOf: map hasher(blake2_256) T::AccountId => Option<ContractInfo<T>>;
pub ContractInfoOf: map hasher(twox_64_concat) T::AccountId => Option<ContractInfo<T>>;
/// The price of one unit of gas.
GasPrice get(fn gas_price) config(): BalanceOf<T> = 1.into();
}
Expand Down
62 changes: 0 additions & 62 deletions frame/contracts/src/migration.rs

This file was deleted.

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 OnNewAccount = ();
type MigrateAccount = (); type OnNewAccount = ();
type OnKilledAccount = Contracts;
}
impl pallet_balances::Trait for Test {
Expand Down
Loading