Make runtime api calls native when possible (#1302)

* Add simple benchmark for the runtime api

* Make the executor support native calls

* Some documentation

* Hide behind `feature = "std"`

* Rework the native calls

* Make all tests compile again

* Make every parameter using the Block serialized/deserialized in the native call

* Forward `UnwindSafe` requirement

* Remove debug stuff

* Add some documentation

* Fixes warnings

* Fixes errors after master rebase

* Fixes compilation after master rebase

* Fixes compilation after rebase
This commit is contained in:
Bastian Köcher
2019-01-21 14:32:53 +01:00
committed by Gav Wood
parent f0dbcf5401
commit 010e63116f
37 changed files with 1152 additions and 363 deletions
@@ -1,13 +1,13 @@
#[macro_use]
extern crate substrate_client;
extern crate substrate_client as client;
extern crate sr_primitives as runtime_primitives;
extern crate substrate_primitives as primitives;
extern crate substrate_test_client as test_client;
use runtime_primitives::traits::{GetNodeBlockType, Block as BlockT, AuthorityIdFor};
use runtime_primitives::generic::BlockId;
use substrate_client::runtime_api::{self, RuntimeApiInfo};
use substrate_client::error::Result;
use client::runtime_api::{self, RuntimeApiInfo};
use client::error::Result;
use test_client::runtime::Block;
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
@@ -62,17 +62,21 @@ impl_runtime_apis! {
fn execute_block(_: Block) {
unimplemented!()
}
fn initialise_block(_: <Block as BlockT>::Header) {
fn initialise_block(_: &<Block as BlockT>::Header) {
unimplemented!()
}
}
}
type TestClient = client::Client<test_client::Backend, test_client::Executor, Block, RuntimeApi>;
#[test]
fn test_client_side_function_signature() {
let _test: fn(&RuntimeApi, &BlockId<Block>, &u64) -> Result<()> = RuntimeApi::test;
let _something_with_block: fn(&RuntimeApi, &BlockId<Block>, &Block) -> Result<Block> =
RuntimeApi::something_with_block;
let _test: fn(&RuntimeApiImpl<TestClient>, &BlockId<Block>, u64) -> Result<()> =
RuntimeApiImpl::<TestClient>::test;
let _something_with_block:
fn(&RuntimeApiImpl<TestClient>, &BlockId<Block>, Block) -> Result<Block> =
RuntimeApiImpl::<TestClient>::something_with_block;
}
#[test]