Prerequisites for validate_block in Cumulus (#1926)

* Adds benchmark for direct/indirect wasm function calls

* Store the benchmark function pointer in a `Cell`

* Add some documentation

* Make function implementations exchangeable

* Add parachain stub

* Add macro for registering the `validate_block` function

* Make all functions replace-able by unimplemented

* Some more refactoring

* Adds tests for executing empty parachain block

* Work on a new test with empty witness data

* Don't exchange `ext_print_*` stuff

* Some cleanup and one more function for `validate_block`

* More tests and more functions

* Fixes after merging master

* Use `parity-codec` `derive` feature

* CHange implementation of `wasm-nice-panic-message`

* Move `parachain` stuff to cumulus

* Updated wasm files

* Integrate feedback

* Switch to `ExchangeableFunction` struct

* More fixes

* Switch to Cell and panic on multiple replaces

* Increase `impl_version`

* Fix shifting

* Make the API more verbose of `ExchangeableFunction`

* Increase `impl_version`
This commit is contained in:
Bastian Köcher
2019-03-14 21:29:12 +01:00
committed by GitHub
parent b92b2cc29b
commit 990d368f0d
17 changed files with 578 additions and 170 deletions
+42 -2
View File
@@ -18,7 +18,8 @@
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "std")] pub mod genesismap;
#[cfg(feature = "std")]
pub mod genesismap;
pub mod system;
use rstd::{prelude::*, marker::PhantomData};
@@ -77,6 +78,16 @@ pub struct Transfer {
pub nonce: u64,
}
impl Transfer {
/// Convert into a signed extrinsic.
#[cfg(feature = "std")]
pub fn into_signed_tx(self) -> Extrinsic {
let signature = keyring::AccountKeyring::from_public(&self.from)
.expect("Creates keyring from public key.").sign(&self.encode()).into();
Extrinsic::Transfer(self, signature)
}
}
/// Extrinsic for test-runtime.
#[derive(Clone, PartialEq, Eq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
@@ -219,6 +230,8 @@ cfg_if! {
fn function_signature_changed() -> u64;
fn fail_on_native() -> u64;
fn fail_on_wasm() -> u64;
fn benchmark_indirect_call() -> u64;
fn benchmark_direct_call() -> u64;
}
}
} else {
@@ -239,6 +252,8 @@ cfg_if! {
fn function_signature_changed() -> Vec<u64>;
fn fail_on_native() -> u64;
fn fail_on_wasm() -> u64;
fn benchmark_indirect_call() -> u64;
fn benchmark_direct_call() -> u64;
}
}
}
@@ -254,6 +269,16 @@ impl GetRuntimeBlockType for Runtime {
type RuntimeBlock = Block;
}
/// Adds one to the given input and returns the final result.
#[inline(never)]
fn benchmark_add_one(i: u64) -> u64 {
i + 1
}
/// The `benchmark_add_one` function as function pointer.
#[cfg(not(feature = "std"))]
static BENCHMARK_ADD_ONE: runtime_io::ExchangeableFunction<fn(u64) -> u64> = runtime_io::ExchangeableFunction::new(benchmark_add_one);
cfg_if! {
if #[cfg(feature = "std")] {
impl_runtime_apis! {
@@ -340,6 +365,13 @@ cfg_if! {
fn fail_on_wasm() -> u64 {
1
}
fn benchmark_indirect_call() -> u64 {
let function = benchmark_add_one;
(0..1000).fold(0, |p, i| p + function(i))
}
fn benchmark_direct_call() -> u64 {
(0..1000).fold(0, |p, i| p + benchmark_add_one(i))
}
}
impl consensus_aura::AuraApi<Block> for Runtime {
@@ -435,6 +467,14 @@ cfg_if! {
fn fail_on_wasm() -> u64 {
panic!("Failing because we are on wasm")
}
fn benchmark_indirect_call() -> u64 {
(0..10000).fold(0, |p, i| p + BENCHMARK_ADD_ONE.get()(i))
}
fn benchmark_direct_call() -> u64 {
(0..10000).fold(0, |p, i| p + benchmark_add_one(i))
}
}
impl consensus_aura::AuraApi<Block> for Runtime {
@@ -442,4 +482,4 @@ cfg_if! {
}
}
}
}
}