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
+20 -9
View File
@@ -186,13 +186,14 @@ pub fn changes_trie_config() -> primitives::ChangesTrieConfiguration {
}
}
pub mod test_api {
use super::AccountId;
decl_runtime_apis! {
pub trait TestAPI {
fn balance_of(id: AccountId) -> u64;
}
decl_runtime_apis! {
pub trait TestAPI {
fn balance_of(id: AccountId) -> u64;
/// A benchmkark function that adds one to the given value and returns the result.
fn benchmark_add_one(val: &u64) -> u64;
/// A benchmark function that adds one to each value in the given vector and returns the
/// result.
fn benchmark_vector_add_one(vec: &Vec<u64>) -> Vec<u64>;
}
}
@@ -220,7 +221,7 @@ impl_runtime_apis! {
system::execute_block(block)
}
fn initialise_block(header: <Block as BlockT>::Header) {
fn initialise_block(header: &<Block as BlockT>::Header) {
system::initialise_block(header)
}
}
@@ -259,10 +260,20 @@ impl_runtime_apis! {
}
}
impl self::test_api::TestAPI<Block> for Runtime {
impl self::TestAPI<Block> for Runtime {
fn balance_of(id: AccountId) -> u64 {
system::balance_of(id)
}
fn benchmark_add_one(val: &u64) -> u64 {
val + 1
}
fn benchmark_vector_add_one(vec: &Vec<u64>) -> Vec<u64> {
let mut vec = vec.clone();
vec.iter_mut().for_each(|v| *v += 1);
vec
}
}
impl aura_api::AuraApi<Block> for Runtime {