Refactor/substrate state machine generic (#553)

* Genric over hasher

* WIP start adding NodeCodec

* Add codec to TrieBackend

* Typechecks

* Fix error type

* Cleanup

* Tests build (and fail)

* Fix tests: don't use MemoryDB::default()

* Lockfile

* Address grumbles

* Teach environmental! about generics

* Add Finder artifacts

* whitespace

* Add a toy impl of Hasher and plug it in to Externalities

* Use `uint` and `fixed-hash` from `parity-common`
Remove unused U512
Add test to ensure H256 impls heapsizeof

* lock file updates

* Make hashes Encodable/Decodable

* lock file updates

* Impl FromIterator for TestExternalities so we can collect() and use map!

* Use rustc-hex from crates
Use rlp from master so dependencies do not mess up the scope

* Fix tests in runtime-io

* lockfile shenanigans

* Add a BlakeHasher impl

* Use BlakeHasher in runtime-io

* lockfile updates

* ws

* Add a Blake2/RLP-flavoured NodeCodec

* Use Blake-flavoured Hasher and NodeCodec

* lockfile

* Implement PartialEq and Default for TestExternalities

* Add note about limitations of environmental!

* Make it compile, but this is probably broken

* Derive Debug so tests in executor can work

* Make executor use BlakeHasher

* ws

* WIP make client generic

* typechecks

* cleanup

* client tests pass

* Fix client/db

* cleanup

* Fix network

* Fix rpc

* Fix service

* Make TestExternalities work better au lieu d'un HashMap

* Fix tests in council

* Fix tests in contract

* Fix tests in council

* Fix democracy

* Add comment about odd-looking reexports in tests

* Don't need to load branch

* Fix staking

* Fix session

* Some polkadot fixes and lockfile

* Fix executive

* fixup lockfile

* Fix polkadot/api

* Fix polkadot/service

* Fix polkadot/runtime tests

* Fix tests in test-runtime

* Test fixes

* Fix missing component in the `std` feature

* Use PhantomData and Result from core

* Fix paths
Use core

* load heapsize on wasm

* implement `HeapSizeOf` for wasm

* Add toy impl of `blake2_256` for no_std

* lockfile

* Use kvdb* from parity-common and fix errors

* rebuilt lockfile

* Add dummy impl of `on_advance_round` for rhododendron::Context

* Fix build after merge

* Add HeapSizeOf bound where needed

* Sort out dependencies for no_std

* Add HeapSizeOf bound where needed

* use temp branch pending PR merges

* Remove unneeded tests

* Lock file and wasm artifacts

* lockfile

* Use magic commit for libp2p

* Cleanup

* Implement blake2_256 for no_std

* Back on parity-common master

* missing type params

* Update Cargo.lock

* whitespace

* Rename concrete Rlp node codec "RlpCodec" and use everywhere
Implement a Keccak-flavoured Rlp NodeCodec and use everywhere
Add a KeccakHasher

* Switch to use KeccakHasher

* Lock file and runtimes

* fixup lockfile

* Fix outstanding issue using concrete types (thanks @gnunicorn)

* Cleanup

* More cleanup

* Comment out Blake2 Hasher

* implement ext_keccak256

* Address todo: FetchChecker is generic

* all tests passing
This commit is contained in:
Gav Wood
2018-08-15 13:13:11 +02:00
committed by Robert Habermeier
parent 8db30afe53
commit c5e68a7b9b
12 changed files with 109 additions and 284 deletions
+10 -8
View File
@@ -30,7 +30,10 @@ use substrate_runtime_support::dispatch::Result;
use rstd::marker::PhantomData;
#[cfg(any(feature = "std", test))]
use {runtime_io, runtime_primitives};
use runtime_primitives;
#[cfg(any(feature = "std", test))]
use std::collections::HashMap;
pub trait Trait: system::Trait<Hash = ::primitives::Hash> + session::Trait {
/// The position of the set_heads call in the block.
@@ -214,8 +217,7 @@ impl<T: Trait> Default for GenesisConfig<T> {
#[cfg(any(feature = "std", test))]
impl<T: Trait> runtime_primitives::BuildStorage for GenesisConfig<T>
{
fn build_storage(mut self) -> ::std::result::Result<runtime_io::TestExternalities, String> {
use std::collections::HashMap;
fn build_storage(mut self) -> ::std::result::Result<HashMap<Vec<u8>, Vec<u8>>, String> {
use codec::Encode;
self.parachains.sort_unstable_by_key(|&(ref id, _, _)| id.clone());
@@ -235,15 +237,15 @@ impl<T: Trait> runtime_primitives::BuildStorage for GenesisConfig<T>
map.insert(head_key, genesis.encode());
}
Ok(map.into())
Ok(map)
}
}
#[cfg(test)]
mod tests {
use super::*;
use runtime_io::with_externalities;
use substrate_primitives::H256;
use runtime_io::{TestExternalities, with_externalities};
use substrate_primitives::{H256, KeccakHasher};
use runtime_primitives::BuildStorage;
use runtime_primitives::traits::{HasPublicAux, Identity, BlakeTwo256};
use runtime_primitives::testing::{Digest, Header};
@@ -284,7 +286,7 @@ mod tests {
type Parachains = Module<Test>;
fn new_test_ext(parachains: Vec<(Id, Vec<u8>, Vec<u8>)>) -> runtime_io::TestExternalities {
fn new_test_ext(parachains: Vec<(Id, Vec<u8>, Vec<u8>)>) -> TestExternalities<KeccakHasher> {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
t.extend(consensus::GenesisConfig::<Test>{
code: vec![],
@@ -299,7 +301,7 @@ mod tests {
parachains: parachains,
phantom: PhantomData,
}.build_storage().unwrap());
t
t.into()
}
#[test]