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
+15 -5
View File
@@ -50,7 +50,12 @@ mod local_executor {
#![allow(missing_docs)]
use super::runtime;
// TODO: change the macro and pass in the `BlakeHasher` that dispatch needs from here instead
native_executor_instance!(pub LocalExecutor, runtime::api::dispatch, runtime::native_version, include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm"));
native_executor_instance!(
pub LocalExecutor,
runtime::api::dispatch,
runtime::native_version,
include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm")
);
}
/// Native executor used for tests.
@@ -71,7 +76,9 @@ pub fn new() -> client::Client<Backend, Executor, runtime::Block, runtime::Runti
}
/// Creates new test client instance that suports changes trie creation.
pub fn new_with_changes_trie() -> client::Client<Backend, Executor, runtime::Block, runtime::RuntimeApi> {
pub fn new_with_changes_trie()
-> client::Client<Backend, Executor, runtime::Block, runtime::RuntimeApi>
{
new_with_backend(Arc::new(Backend::new()), true)
}
@@ -80,9 +87,12 @@ pub fn new_with_changes_trie() -> client::Client<Backend, Executor, runtime::Blo
pub fn new_with_backend<B>(
backend: Arc<B>,
support_changes_trie: bool
) -> client::Client<B, client::LocalCallExecutor<B, executor::NativeExecutor<LocalExecutor>>, runtime::Block, runtime::RuntimeApi>
where
B: backend::LocalBackend<runtime::Block, Blake2Hasher>,
) -> client::Client<
B,
client::LocalCallExecutor<B, executor::NativeExecutor<LocalExecutor>>,
runtime::Block,
runtime::RuntimeApi
> where B: backend::LocalBackend<runtime::Block, Blake2Hasher>
{
let executor = NativeExecutor::new();
client::new_with_backend(backend, executor, genesis_storage(support_changes_trie)).unwrap()
@@ -32,7 +32,7 @@ use runtime::{self, Transfer};
use runtime_primitives::generic::BlockId;
/// helper to test the `leaves` implementation for various backends
pub fn test_leaves_for_backend<B>(backend: Arc<B>) where
pub fn test_leaves_for_backend<B: 'static>(backend: Arc<B>) where
B: backend::LocalBackend<runtime::Block, Blake2Hasher>,
{
// block tree:
@@ -145,7 +145,7 @@ pub fn test_leaves_for_backend<B>(backend: Arc<B>) where
}
pub fn test_blockchain_query_by_number_gets_canonical<B>(backend: Arc<B>) where
pub fn test_blockchain_query_by_number_gets_canonical<B: 'static>(backend: Arc<B>) where
B: backend::LocalBackend<runtime::Block, Blake2Hasher>,
{
// block tree: