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
+3 -3
View File
@@ -41,7 +41,7 @@ mod tests {
use srml_support::{impl_outer_origin, impl_outer_event, impl_outer_dispatch, parameter_types};
pub use substrate_primitives::{H256, Blake2Hasher, u32_trait::{_1, _2, _3, _4}};
pub use primitives::{
BuildStorage, traits::{BlakeTwo256, IdentityLookup}, testing::{Digest, DigestItem, Header}
traits::{BlakeTwo256, IdentityLookup}, testing::{Digest, DigestItem, Header}
};
pub use {seats, motions};
@@ -172,8 +172,8 @@ mod tests {
self
}
pub fn build(self) -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
t.extend(balances::GenesisConfig::<Test>{
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap().0;
t.extend(balances::GenesisConfig::<Test> {
transaction_base_fee: 0,
transaction_byte_fee: 0,
balances: vec![
+1 -1
View File
@@ -139,7 +139,7 @@ decl_module! {
Self::deposit_event(RawEvent::Executed(proposal_hash, ok));
} else {
let index = Self::proposal_count();
<ProposalCount<T>>::mutate(|i| *i += 1);
ProposalCount::mutate(|i| *i += 1);
<Proposals<T>>::mutate(|proposals| proposals.push(proposal_hash));
<ProposalOf<T>>::insert(proposal_hash, *proposal);
let votes = Votes { index, threshold, ayes: vec![who.clone()], nays: vec![] };
+8 -8
View File
@@ -329,7 +329,7 @@ decl_module! {
candidates[slot] = who;
}
<Candidates<T>>::put(candidates);
<CandidateCount<T>>::put(count as u32 + 1);
CandidateCount::put(count as u32 + 1);
}
/// Claim that `signed` is one of the top Self::carry_count() + current_vote().1 candidates.
@@ -409,7 +409,7 @@ decl_module! {
/// election when they expire. If more, then a new vote will be started if one is not
/// already in progress.
fn set_desired_seats(#[compact] count: u32) {
<DesiredSeats<T>>::put(count);
DesiredSeats::put(count);
}
/// Remove a particular member from the council. This is effective immediately.
@@ -613,7 +613,7 @@ impl<T: Trait> Module<T> {
let mut set = Self::voters(set_index);
set[vec_index] = None;
<Voters<T>>::insert(set_index, set);
<VoterCount<T>>::mutate(|c| *c = *c - 1);
VoterCount::mutate(|c| *c = *c - 1);
Self::remove_all_approvals_of(voter);
<VoterInfoOf<T>>::remove(voter);
}
@@ -683,7 +683,7 @@ impl<T: Trait> Module<T> {
}
T::Currency::reserve(&who, Self::voting_bond())?;
<VoterCount<T>>::mutate(|c| *c = *c + 1);
VoterCount::mutate(|c| *c = *c + 1);
}
T::Currency::set_lock(
@@ -802,8 +802,8 @@ impl<T: Trait> Module<T> {
Self::deposit_event(RawEvent::TallyFinalized(incoming, outgoing));
<Candidates<T>>::put(new_candidates);
<CandidateCount<T>>::put(count);
<VoteCount<T>>::put(Self::vote_index() + 1);
CandidateCount::put(count);
VoteCount::put(Self::vote_index() + 1);
Ok(())
}
@@ -815,7 +815,7 @@ impl<T: Trait> Module<T> {
set.push(Some(who));
if len + 1 == VOTER_SET_SIZE {
<NextVoterSet<T>>::put(index + 1);
NextVoterSet::put(index + 1);
}
}
@@ -1356,7 +1356,7 @@ mod tests {
let mut t = ExtBuilder::default().build();
with_externalities(&mut t, || {
<Candidates<Test>>::put(vec![0, 0, 1]);
<CandidateCount<Test>>::put(1);
CandidateCount::put(1);
<RegisterInfoOf<Test>>::insert(1, (0, 2));
});
t