Make substrate generic (#169)

* Some initial work on RPC and client

* Rephrase as params

* More work on traitifying substrate.

* Traitify in_mem.rs

* traitify client.rs

* Make new primitives (mainly traits) build again.

* Many (superficial) build fixes throughout.

* Fix remaining build issues up to bft interface.

* Make bft primitives be generic.

* Switch out MisBehaviorReport for generic version.

* Merge Hashing into Header.

* Update runtime for new generics (with Hashing).

* Update demo runtime.

* Make runtime compile.

* Build fixes for runtime

* Remove old modules.

* port substrate-bft to use generic substrate types

* port client

* port substrate-test-runtime

* mostly port test-runtime to get compiling for std

* Ensure `AccountId` has a `Default`.

* Fix type deps.

* finish porting

* initialize test_runtime from genesis correctly

* remove commented code

* maybe unsigned signatures

* runtimes compile

* port over most of network

* serialization for generic types

* fix comment

* remove some unnecessary trait bounds

* network compiles

* tests compile for sync

* fix deserialization

* temporarily remove deserialize derives

* workarounds for serde issues for deriving deserialization

* get demo-runtime compiling on std

* port extrinsic-pool

* primitives reshuffling

* get network compiling again

* remove debugging file

* runtime tests now passing

* port client-db

* start to port over substrate-rpc

* mostly port over PolkadotApi

* test_runtime follows normal conventions

* substrate runtime tests pass

* deal with inherent extrinsics correctly in polkadot-api

* port transaction-pool

* port polkadot-consensus

* port substrate-rpc

* everything compiles

* tests compile

* fix grumbles

* test-runtime uses its own transfer type

* switch to master branch of jsonrpc

* fix network tests and some warnings

* all tests pass locally

* [ci-skip] add another comment about issue

* remove some curlies
This commit is contained in:
Gav Wood
2018-06-06 17:58:45 +02:00
committed by Robert Habermeier
parent 4e844760a3
commit b94cf078af
132 changed files with 4695 additions and 4303 deletions
@@ -12,3 +12,4 @@ substrate-keyring = { path = "../../substrate/keyring" }
substrate-primitives = { path = "../primitives" }
substrate-runtime-support = { path = "../runtime-support" }
substrate-test-runtime = { path = "../test-runtime" }
substrate-runtime-primitives = { path = "../runtime/primitives" }
@@ -16,12 +16,10 @@
//! Client extension for tests.
use codec::Slicable;
use client::{self, Client};
use keyring::Keyring;
use runtime_support::Hashable;
use runtime::genesismap::{GenesisConfig, additional_storage_with_genesis};
use primitives::block;
use runtime;
use bft;
use {Backend, Executor, NativeExecutor};
@@ -31,26 +29,26 @@ pub trait TestClient {
fn new_for_tests() -> Self;
/// Justify and import block to the chain.
fn justify_and_import(&self, origin: client::BlockOrigin, block: block::Block) -> client::error::Result<()>;
fn justify_and_import(&self, origin: client::BlockOrigin, block: runtime::Block) -> client::error::Result<()>;
/// Returns hash of the genesis block.
fn genesis_hash(&self) -> block::HeaderHash;
fn genesis_hash(&self) -> runtime::Hash;
}
impl TestClient for Client<Backend, Executor> {
impl TestClient for Client<Backend, Executor, runtime::Block> {
fn new_for_tests() -> Self {
client::new_in_mem(NativeExecutor::new(), GenesisBuilder).unwrap()
}
fn justify_and_import(&self, origin: client::BlockOrigin, block: block::Block) -> client::error::Result<()> {
fn justify_and_import(&self, origin: client::BlockOrigin, block: runtime::Block) -> client::error::Result<()> {
let justification = fake_justify(&block.header);
let justified = self.check_justification(block.header, justification)?;
self.import_block(origin, justified, Some(block.transactions))?;
self.import_block(origin, justified, Some(block.extrinsics))?;
Ok(())
}
fn genesis_hash(&self) -> block::HeaderHash {
fn genesis_hash(&self) -> runtime::Hash {
self.block_hash(0).unwrap().unwrap()
}
}
@@ -61,8 +59,8 @@ impl TestClient for Client<Backend, Executor> {
/// headers.
/// TODO: remove this in favor of custom verification pipelines for the
/// client
fn fake_justify(header: &block::Header) -> bft::UncheckedJustification {
let hash = header.blake2_256().into();
fn fake_justify(header: &runtime::Header) -> bft::UncheckedJustification<runtime::Hash> {
let hash = header.hash();
let authorities = vec![
Keyring::Alice.into(),
Keyring::Bob.into(),
@@ -72,7 +70,7 @@ fn fake_justify(header: &block::Header) -> bft::UncheckedJustification {
bft::UncheckedJustification {
digest: hash,
signatures: authorities.iter().map(|key| {
let msg = bft::sign_message(
let msg = bft::sign_message::<runtime::Block>(
bft::generic::Vote::Commit(1, hash).into(),
key,
header.parent_hash
@@ -97,15 +95,14 @@ fn genesis_config() -> GenesisConfig {
struct GenesisBuilder;
impl client::GenesisBuilder for GenesisBuilder {
fn build(self) -> (block::Header, Vec<(Vec<u8>, Vec<u8>)>) {
impl client::GenesisBuilder<runtime::Block> for GenesisBuilder {
fn build(self) -> (runtime::Header, Vec<(Vec<u8>, Vec<u8>)>) {
let mut storage = genesis_config().genesis_map();
let block = client::genesis::construct_genesis_block(&storage);
let block: runtime::Block = client::genesis::construct_genesis_block(&storage);
storage.extend(additional_storage_with_genesis(&block));
(
block::Header::decode(&mut block.header.encode().as_ref())
.expect("to_vec() always gives a valid serialisation; qed"),
block.header,
storage.into_iter().collect()
)
}
+3 -2
View File
@@ -23,6 +23,7 @@ extern crate substrate_codec as codec;
extern crate substrate_keyring as keyring;
extern crate substrate_primitives as primitives;
extern crate substrate_runtime_support as runtime_support;
extern crate substrate_runtime_primitives as runtime_primitives;
#[macro_use] extern crate substrate_executor as executor;
pub extern crate substrate_test_runtime as runtime;
@@ -43,12 +44,12 @@ mod native_executor {
pub use self::native_executor::NativeExecutor;
/// Test client database backend.
pub type Backend = client::in_mem::Backend;
pub type Backend = client::in_mem::Backend<runtime::Block>;
/// Test client executor.
pub type Executor = client::LocalCallExecutor<Backend, executor::NativeExecutor<NativeExecutor>>;
/// Creates new client instance used for tests.
pub fn new() -> client::Client<Backend, Executor> {
pub fn new() -> client::Client<Backend, Executor, runtime::Block> {
TestClient::new_for_tests()
}