Implement a proper generic resolution in decl_storage! (#2913)

* Add failing test case

* move storage maps to blake2_128 (#2268)

* remove default hash, introduce twox_128 and blake2

* use blake2_128 & create ext_blake2_128

* refactor code

* add benchmark

* factorize generator

* fix

* parameterizable hasher

* some fix

* fix

* fix

* fix

* metadata

* fix

* remove debug print

* map -> blake2_256

* fix test

* fix test

* Apply suggestions from code review

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>

* impl twox 128 concat (#2353)

* impl twox_128_concat

* comment addressed

* fix

* impl twox_128->64_concat

* fix test

* Fix compilation and cleanup some docs

* Lol

* Remove traits from storage types that are not generic

* Get instance test almost working as wanted

* Make `srml-support-test` compile again :)

* Fixes test of srml-support

* Fix compilation

* Break some lines

* Remove incorrect macro match arm

* Integrates review feedback

* Update documentation

* Fix compilation
This commit is contained in:
Bastian Köcher
2019-06-27 13:40:22 +02:00
committed by GitHub
parent 23ea5d1795
commit 62b7c05def
55 changed files with 1441 additions and 860 deletions
+5 -5
View File
@@ -866,7 +866,7 @@ decl_module! {
/// The ideal number of validators.
fn set_validator_count(#[compact] new: u32) {
<ValidatorCount<T>>::put(new);
ValidatorCount::put(new);
}
// ----- Root calls.
@@ -885,7 +885,7 @@ decl_module! {
/// Set the offline slash grace period.
fn set_offline_slash_grace(#[compact] new: u32) {
<OfflineSlashGrace<T>>::put(new);
OfflineSlashGrace::put(new);
}
/// Set the validators who cannot be slashed (if any).
@@ -1004,7 +1004,7 @@ impl<T: Trait> Module<T> {
let reward = Self::current_session_reward();
<CurrentEraReward<T>>::mutate(|r| *r += reward);
if <ForceNewEra<T>>::take() || session_index % T::SessionsPerEra::get() == 0 {
if ForceNewEra::take() || session_index % T::SessionsPerEra::get() == 0 {
Self::new_era()
} else {
None
@@ -1032,7 +1032,7 @@ impl<T: Trait> Module<T> {
}
// Increment current era.
<CurrentEra<T>>::mutate(|s| *s += 1);
CurrentEra::mutate(|s| *s += 1);
// Reassign all Stakers.
let (slot_stake, maybe_new_validators) = Self::select_validators();
@@ -1161,7 +1161,7 @@ impl<T: Trait> Module<T> {
}
fn apply_force_new_era() {
<ForceNewEra<T>>::put(true);
ForceNewEra::put(true);
}
/// Call when a validator is determined to be offline. `count` is the
+2 -2
View File
@@ -17,7 +17,7 @@
//! Test utilities
use std::{collections::HashSet, cell::RefCell};
use primitives::{BuildStorage, Perbill};
use primitives::Perbill;
use primitives::traits::{IdentityLookup, Convert, OpaqueKeys, OnInitialize};
use primitives::testing::{Header, UintAuthorityId};
use substrate_primitives::{H256, Blake2Hasher};
@@ -179,7 +179,7 @@ impl ExtBuilder {
self
}
pub fn build(self) -> runtime_io::TestExternalities<Blake2Hasher> {
let (mut t, mut c) = system::GenesisConfig::<Test>::default().build_storage().unwrap();
let (mut t, mut c) = system::GenesisConfig::default().build_storage::<Test>().unwrap();
let balance_factor = if self.existential_deposit > 0 {
256
} else {
+2 -2
View File
@@ -257,7 +257,7 @@ fn max_unstake_threshold_works() {
validator_payment: 0,
});
<OfflineSlash<Test>>::put(Perbill::from_fraction(0.0001));
OfflineSlash::put(Perbill::from_fraction(0.0001));
// Report each user 1 more than the max_unstake_threshold
Staking::on_offline_validator(10, MAX_UNSTAKE_THRESHOLD as usize + 1);
@@ -696,7 +696,7 @@ fn nominators_also_get_slashed() {
assert_eq!(Staking::offline_slash_grace(), 0);
// Account 10 has not been reported offline
assert_eq!(Staking::slash_count(&10), 0);
<OfflineSlash<Test>>::put(Perbill::from_percent(12));
OfflineSlash::put(Perbill::from_percent(12));
// Set payee to controller
assert_ok!(Staking::set_payee(Origin::signed(10), RewardDestination::Controller));