diff --git a/Cargo.lock b/Cargo.lock index 0da61066df86a..9eb942aae82bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -136,7 +136,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -194,7 +194,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "clang-sys 0.26.4 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -330,7 +330,7 @@ dependencies = [ [[package]] name = "cfg-if" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -453,7 +453,7 @@ name = "crossbeam" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-epoch 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -496,7 +496,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -510,7 +510,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -522,7 +522,7 @@ name = "crossbeam-utils" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -530,7 +530,7 @@ name = "crossbeam-utils" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1675,7 +1675,7 @@ name = "log" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1701,7 +1701,7 @@ name = "memchr" version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1838,7 +1838,7 @@ name = "net2" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1850,7 +1850,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2095,7 +2095,7 @@ version = "0.10.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4176,7 +4176,7 @@ dependencies = [ name = "substrate-test-runtime" version = "0.1.0" dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4186,6 +4186,7 @@ dependencies = [ "sr-primitives 0.1.0", "sr-std 0.1.0", "sr-version 0.1.0", + "srml-executive 0.1.0", "srml-support 0.1.0", "substrate-client 0.1.0", "substrate-consensus-aura-primitives 0.1.0", @@ -4282,7 +4283,7 @@ name = "sysinfo" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4312,7 +4313,7 @@ name = "tempfile" version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5034,7 +5035,7 @@ dependencies = [ "checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427" "checksum cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)" = "389803e36973d242e7fecb092b2de44a3d35ac62524b3b9339e51d577d668e02" "checksum cexpr 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "644d693ecfa91955ed32dcc7eda4914e1be97a641fb6f0645a37348e20b230da" -"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" +"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" "checksum clang-sys 0.26.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6ef0c1bcf2e99c649104bd7a7012d8f8802684400e03db0ec0af48583c6fa0e4" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" diff --git a/core/executor/src/wasm_executor.rs b/core/executor/src/wasm_executor.rs index 7e459826989d4..7e6833bb7839f 100644 --- a/core/executor/src/wasm_executor.rs +++ b/core/executor/src/wasm_executor.rs @@ -23,7 +23,7 @@ use secp256k1; use wasmi::{ Module, ModuleInstance, MemoryInstance, MemoryRef, TableRef, ImportsBuilder, ModuleRef, }; -use wasmi::RuntimeValue::{I32, I64}; +use wasmi::RuntimeValue::{I32, I64, self}; use wasmi::memory_units::{Pages}; use state_machine::Externalities; use crate::error::{Error, ErrorKind, Result}; @@ -393,10 +393,12 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, .map_err(|_| UserError("Invalid attempt to get parent_hash in ext_storage_changes_root"))?; parent_hash.as_mut().copy_from_slice(&raw_parent_hash[..]); let r = this.ext.storage_changes_root(parent_hash, parent_number); - if let Some(ref r) = r { + if let Some(r) = r { this.memory.set(result, &r[..]).map_err(|_| UserError("Invalid attempt to set memory in ext_storage_changes_root"))?; + Ok(1) + } else { + Ok(0) } - Ok(if r.is_some() { 1u32 } else { 0u32 }) }, ext_blake2_256_enumerated_trie_root(values_data: *const u8, lens_data: *const u32, lens_len: u32, result: *mut u8) => { let values = (0..lens_len) @@ -637,17 +639,19 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, /// /// Executes the provided code in a sandboxed wasm runtime. #[derive(Debug, Clone)] -pub struct WasmExecutor { -} +pub struct WasmExecutor; impl WasmExecutor { /// Create a new instance. pub fn new() -> Self { - WasmExecutor{} + WasmExecutor } /// Call a given method in the given code. + /// + /// Signature of this method needs to be `(I32, I32) -> I64`. + /// /// This should be used for tests only. pub fn call>( &self, @@ -656,12 +660,34 @@ impl WasmExecutor { code: &[u8], method: &str, data: &[u8], - ) -> Result> { + ) -> Result> { let module = ::wasmi::Module::from_buffer(code)?; let module = self.prepare_module(ext, heap_pages, &module)?; self.call_in_wasm_module(ext, &module, method, data) } + /// Call a given method with a custom signature in the given code. + /// + /// This should be used for tests only. + pub fn call_with_custom_signature< + E: Externalities, + F: FnOnce(&mut FnMut(&[u8]) -> Result) -> Result>, + FR: FnOnce(Option, &MemoryRef) -> Result>, + R, + >( + &self, + ext: &mut E, + heap_pages: usize, + code: &[u8], + method: &str, + create_parameters: F, + filter_result: FR, + ) -> Result { + let module = wasmi::Module::from_buffer(code)?; + let module = self.prepare_module(ext, heap_pages, &module)?; + self.call_in_wasm_module_with_custom_signature(ext, &module, method, create_parameters, filter_result) + } + fn get_mem_instance(module: &ModuleRef) -> Result { Ok(module .export_by_name("memory") @@ -679,6 +705,40 @@ impl WasmExecutor { method: &str, data: &[u8], ) -> Result> { + self.call_in_wasm_module_with_custom_signature( + ext, + module_instance, + method, + |alloc| { + let offset = alloc(data)?; + Ok(vec![I32(offset as i32), I32(data.len() as i32)]) + }, + |res, memory| { + if let Some(I64(r)) = res { + let offset = r as u32; + let length = (r as u64 >> 32) as usize; + memory.get(offset, length).map_err(|_| ErrorKind::Runtime.into()).map(Some) + } else { + Ok(None) + } + } + ) + } + + /// Call a given method in the given wasm-module runtime. + fn call_in_wasm_module_with_custom_signature< + E: Externalities, + F: FnOnce(&mut FnMut(&[u8]) -> Result) -> Result>, + FR: FnOnce(Option, &MemoryRef) -> Result>, + R, + >( + &self, + ext: &mut E, + module_instance: &ModuleRef, + method: &str, + create_parameters: F, + filter_result: FR, + ) -> Result { // extract a reference to a linear memory, optional reference to a table // and then initialize FunctionExecutor. let memory = Self::get_mem_instance(module_instance)?; @@ -689,26 +749,22 @@ impl WasmExecutor { let low = memory.lowest_used(); let used_mem = memory.used_size(); let mut fec = FunctionExecutor::new(memory.clone(), table, ext)?; - let size = data.len() as u32; - let offset = fec.heap.allocate(size).map_err(|_| ErrorKind::Runtime)?; - memory.set(offset, &data)?; + let parameters = create_parameters(&mut |data: &[u8]| { + let offset = fec.heap.allocate(data.len() as u32).map_err(|_| ErrorKind::Runtime)?; + memory.set(offset, &data)?; + Ok(offset) + })?; let result = module_instance.invoke_export( method, - &[ - I32(offset as i32), - I32(size as i32) - ], + ¶meters, &mut fec ); let result = match result { - Ok(Some(I64(r))) => { - let offset = r as u32; - let length = (r >> 32) as u32 as usize; - memory.get(offset, length) - .map_err(|_| ErrorKind::Runtime.into()) + Ok(val) => match filter_result(val, &memory)? { + Some(val) => Ok(val), + None => Err(ErrorKind::InvalidReturn.into()), }, - Ok(_) => Err(ErrorKind::InvalidReturn.into()), Err(e) => { trace!(target: "wasm-executor", "Failed to execute code with {} pages", memory.current_size().0); Err(e.into()) @@ -738,7 +794,7 @@ impl WasmExecutor { module, &ImportsBuilder::new() .with_resolver("env", FunctionExecutor::::resolver()) - )?; + )?; // extract a reference to a linear memory, optional reference to a table // and then initialize FunctionExecutor. @@ -759,7 +815,7 @@ impl WasmExecutor { #[cfg(test)] mod tests { use super::*; - + use parity_codec::Encode; use state_machine::TestExternalities; diff --git a/core/sr-api-macros/benches/bench.rs b/core/sr-api-macros/benches/bench.rs index 85ea3d6f88dd3..f467721789792 100644 --- a/core/sr-api-macros/benches/bench.rs +++ b/core/sr-api-macros/benches/bench.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -use criterion::Criterion; +use criterion::{Criterion, criterion_group, criterion_main}; use test_client::runtime::TestAPI; use runtime_primitives::{generic::BlockId, traits::ProvideRuntimeApi}; +use state_machine::ExecutionStrategy; fn sr_api_benchmark(c: &mut Criterion) { c.bench_function("add one with same runtime api", |b| { @@ -50,6 +51,18 @@ fn sr_api_benchmark(c: &mut Criterion) { b.iter_with_large_drop(|| client.runtime_api().benchmark_vector_add_one(&block_id, &data)) }); + + c.bench_function("calling function by function pointer in wasm", |b| { + let client = test_client::new_with_execution_strategy(ExecutionStrategy::AlwaysWasm); + let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + b.iter(|| client.runtime_api().benchmark_indirect_call(&block_id).unwrap()) + }); + + c.bench_function("calling function in wasm", |b| { + let client = test_client::new_with_execution_strategy(ExecutionStrategy::AlwaysWasm); + let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + b.iter(|| client.runtime_api().benchmark_direct_call(&block_id).unwrap()) + }); } criterion_group!(benches, sr_api_benchmark); diff --git a/core/sr-io/Cargo.toml b/core/sr-io/Cargo.toml index 01907832f8a25..fa04c17e3fd9a 100644 --- a/core/sr-io/Cargo.toml +++ b/core/sr-io/Cargo.toml @@ -35,3 +35,4 @@ std = [ ] nightly = [] strict = [] +wasm-nice-panic-message = [] \ No newline at end of file diff --git a/core/sr-io/without_std.rs b/core/sr-io/without_std.rs index 7763ddf04a1ac..41dc530d5694a 100644 --- a/core/sr-io/without_std.rs +++ b/core/sr-io/without_std.rs @@ -20,19 +20,27 @@ pub use parity_codec as codec; pub use rstd; pub use rstd::{mem, slice}; -use core::intrinsics; -use rstd::vec::Vec; +use core::{intrinsics, panic::PanicInfo}; +use rstd::{vec::Vec, cell::Cell}; use hash_db::Hasher; use primitives::Blake2Hasher; #[panic_handler] #[no_mangle] -pub fn panic(info: &::core::panic::PanicInfo) -> ! { +pub fn panic(info: &PanicInfo) -> ! { unsafe { - if let Some(loc) = info.location() { - ext_print_utf8(loc.file().as_ptr() as *const u8, loc.file().len() as u32); - ext_print_num(loc.line() as u64); - ext_print_num(loc.column() as u64); + #[cfg(feature = "wasm-nice-panic-message")] + { + let message = rstd::alloc::format!("{}", info); + extern_functions_host_impl::ext_print_utf8(message.as_ptr() as *const u8, message.len() as u32); + } + #[cfg(not(feature = "wasm-nice-panic-message"))] + { + if let Some(loc) = info.location() { + extern_functions_host_impl::ext_print_utf8(loc.file().as_ptr() as *const u8, loc.file().len() as u32); + extern_functions_host_impl::ext_print_num(loc.line() as u64); + extern_functions_host_impl::ext_print_num(loc.column() as u64); + } } intrinsics::abort() } @@ -43,41 +51,223 @@ pub extern fn oom(_: ::core::alloc::Layout) -> ! { static OOM_MSG: &str = "Runtime memory exhausted. Aborting"; unsafe { - ext_print_utf8(OOM_MSG.as_ptr(), OOM_MSG.len() as u32); + extern_functions_host_impl::ext_print_utf8(OOM_MSG.as_ptr(), OOM_MSG.len() as u32); intrinsics::abort(); } } +/// The state of an exchangeable function. +#[derive(Clone, Copy)] +enum ExchangeableFunctionState { + Original, + Replaced, +} + +/// A function which implementation can be exchanged. +/// +/// Internally this works by swapping function pointers. +pub struct ExchangeableFunction(Cell<(T, ExchangeableFunctionState)>); + +impl ExchangeableFunction { + /// Create a new instance of `ExchangeableFunction`. + pub const fn new(impl_: T) -> Self { + Self(Cell::new((impl_, ExchangeableFunctionState::Original))) + } +} + +impl ExchangeableFunction { + /// Replace the implementation with `new_impl`. + /// + /// # Panics + /// + /// Panics when trying to replace an already replaced implementation. + /// + /// # Returns + /// + /// Returns the original implementation wrapped in [`RestoreImplementation`]. + pub fn replace_implementation(&'static self, new_impl: T) -> RestoreImplementation { + if let ExchangeableFunctionState::Replaced = self.0.get().1 { + panic!("Trying to replace an already replaced implementation!") + } + + let old = self.0.replace((new_impl, ExchangeableFunctionState::Replaced)); + + RestoreImplementation(self, Some(old.0)) + } + + /// Restore the original implementation. + fn restore_orig_implementation(&self, orig: T) { + self.0.set((orig, ExchangeableFunctionState::Original)); + } + + /// Returns the internal function pointer. + pub fn get(&self) -> T { + self.0.get().0 + } +} + +// WASM does not support threads, so this is safe; qed. +unsafe impl Sync for ExchangeableFunction {} + +/// Restores a function implementation on drop. +/// +/// Stores a static reference to the function object and the original implementation. +pub struct RestoreImplementation(&'static ExchangeableFunction, Option); + +impl Drop for RestoreImplementation { + fn drop(&mut self) { + self.0.restore_orig_implementation(self.1.take().expect("Value is only taken on drop; qed")); + } +} + +/// Declare extern functions +macro_rules! extern_functions { + ( + $( + $( #[$attr:meta] )* + fn $name:ident ( $( $arg:ident : $arg_ty:ty ),* ) $( -> $ret:ty )?; + )* + ) => { + $( + $( #[$attr] )* + #[allow(non_upper_case_globals)] + pub static $name: ExchangeableFunction $ret )?> = + ExchangeableFunction::new(extern_functions_host_impl::$name); + )* + + /// The exchangeable extern functions host implementations. + mod extern_functions_host_impl { + $( + pub unsafe fn $name ( $( $arg : $arg_ty ),* ) $( -> $ret )? { + implementation::$name ( $( $arg ),* ) + } + )* + + mod implementation { + extern "C" { + $( + pub fn $name ( $( $arg : $arg_ty ),* ) $( -> $ret )?; + )* + } + } + } + }; +} + /// Host functions, provided by the executor. /// A WebAssembly runtime module would "import" these to access the execution environment /// (most importantly, storage) or perform heavy hash calculations. /// See also "ext_" functions in sr-sandbox and sr-std -extern "C" { - /// Printing, useful for debugging +extern_functions! { + /// Host functions for printing, useful for debugging. fn ext_print_utf8(utf8_data: *const u8, utf8_len: u32); fn ext_print_hex(data: *const u8, len: u32); fn ext_print_num(value: u64); - /// Host storage access and verification + /// Set value for key in storage. fn ext_set_storage(key_data: *const u8, key_len: u32, value_data: *const u8, value_len: u32); - fn ext_set_child_storage(storage_key_data: *const u8, storage_key_len: u32, key_data: *const u8, key_len: u32, value_data: *const u8, value_len: u32); + /// Remove key and value from storage. fn ext_clear_storage(key_data: *const u8, key_len: u32); - fn ext_clear_child_storage(storage_key_data: *const u8, storage_key_len: u32, key_data: *const u8, key_len: u32); + /// Checks if the given key exists in the storage. + /// + /// # Returns + /// + /// - `1` if the value exists. + /// - `0` if the value does not exists. fn ext_exists_storage(key_data: *const u8, key_len: u32) -> u32; - fn ext_exists_child_storage(storage_key_data: *const u8, storage_key_len: u32, key_data: *const u8, key_len: u32) -> u32; + /// Remove storage entries which key starts with given prefix. fn ext_clear_prefix(prefix_data: *const u8, prefix_len: u32); - fn ext_kill_child_storage(storage_key_data: *const u8, storage_key_len: u32); - /// Host-side result allocation + /// Gets the value of the given key from storage. + /// + /// The host allocates the memory for storing the value. + /// + /// # Returns + /// + /// - `0` if no value exists to the given key. `written_out` is set to `u32::max_value()`. + /// + /// - Otherwise, pointer to the value in memory. `written_out` contains the length of the value. fn ext_get_allocated_storage(key_data: *const u8, key_len: u32, written_out: *mut u32) -> *mut u8; - /// Host-side result allocation - fn ext_get_allocated_child_storage(storage_key_data: *const u8, storage_key_len: u32, key_data: *const u8, key_len: u32, written_out: *mut u32) -> *mut u8; + /// Gets the value of the given key from storage. + /// + /// The value is written into `value` starting at `value_offset`. + /// + /// If the value length is greater than `value_len - value_offset`, the value is written partially. + /// + /// # Returns + /// + /// - `u32::max_value()` if the value does not exists. + /// + /// - Otherwise, the number of bytes written for value. fn ext_get_storage_into(key_data: *const u8, key_len: u32, value_data: *mut u8, value_len: u32, value_offset: u32) -> u32; - fn ext_get_child_storage_into(storage_key_data: *const u8, storage_key_len: u32, key_data: *const u8, key_len: u32, value_data: *mut u8, value_len: u32, value_offset: u32) -> u32; + /// Gets the trie root of the storage. fn ext_storage_root(result: *mut u8); - /// Host-side result allocation - fn ext_child_storage_root(storage_key_data: *const u8, storage_key_len: u32, written_out: *mut u32) -> *mut u8; + /// Get the change trie root of the current storage overlay at a block with given parent. + /// + /// # Returns + /// + /// - `1` if the change trie root was found. + /// - `0` if the change trie root was not found. fn ext_storage_changes_root(parent_hash_data: *const u8, parent_hash_len: u32, parent_num: u64, result: *mut u8) -> u32; + /// A child storage function. + /// + /// See [`ext_set_storage`] for details. + /// + /// A child storage is used e.g. by a contract. + fn ext_set_child_storage(storage_key_data: *const u8, storage_key_len: u32, key_data: *const u8, key_len: u32, value_data: *const u8, value_len: u32); + /// A child storage function. + /// + /// See [`ext_clear_storage`] for details. + /// + /// A child storage is used e.g. by a contract. + fn ext_clear_child_storage(storage_key_data: *const u8, storage_key_len: u32, key_data: *const u8, key_len: u32); + /// A child storage function. + /// + /// See [`ext_exists_storage`] for details. + /// + /// A child storage is used e.g. by a contract. + fn ext_exists_child_storage(storage_key_data: *const u8, storage_key_len: u32, key_data: *const u8, key_len: u32) -> u32; + /// A child storage function. + /// + /// See [`ext_kill_storage`] for details. + /// + /// A child storage is used e.g. by a contract. + fn ext_kill_child_storage(storage_key_data: *const u8, storage_key_len: u32); + /// A child storage function. + /// + /// See [`ext_get_allocated_storage`] for details. + /// + /// A child storage is used e.g. by a contract. + fn ext_get_allocated_child_storage( + storage_key_data: *const u8, + storage_key_len: u32, + key_data: *const u8, + key_len: u32, + written_out: *mut u32 + ) -> *mut u8; + /// A child storage function. + /// + /// See [`ext_get_storage_into`] for details. + /// + /// A child storage is used e.g. by a contract. + fn ext_get_child_storage_into( + storage_key_data: *const u8, + storage_key_len: u32, + key_data: *const u8, + key_len: u32, + value_data: *mut u8, + value_len: u32, + value_offset: u32 + ) -> u32; + /// Commits all changes and calculates the child-storage root. + /// + /// A child storage is used e.g. by a contract. + /// + /// # Returns + /// + /// - The pointer to the result vector and `written_out` contains its length. + fn ext_child_storage_root(storage_key_data: *const u8, storage_key_len: u32, written_out: *mut u32) -> *mut u8; + /// The current relay chain identifier. fn ext_chain_id() -> u64; @@ -107,7 +297,7 @@ impl ExternTrieCrypto for Blake2Hasher { let values = values.iter().fold(Vec::new(), |mut acc, sl| { acc.extend_from_slice(sl); acc }); let mut result: [u8; 32] = Default::default(); unsafe { - ext_blake2_256_enumerated_trie_root( + ext_blake2_256_enumerated_trie_root.get()( values.as_ptr(), lengths.as_ptr(), lengths.len() as u32, @@ -122,7 +312,7 @@ impl ExternTrieCrypto for Blake2Hasher { pub fn storage(key: &[u8]) -> Option> { let mut length: u32 = 0; unsafe { - let ptr = ext_get_allocated_storage(key.as_ptr(), key.len() as u32, &mut length); + let ptr = ext_get_allocated_storage.get()(key.as_ptr(), key.len() as u32, &mut length); if length == u32::max_value() { None } else { @@ -138,7 +328,13 @@ pub fn storage(key: &[u8]) -> Option> { pub fn child_storage(storage_key: &[u8], key: &[u8]) -> Option> { let mut length: u32 = 0; unsafe { - let ptr = ext_get_allocated_child_storage(storage_key.as_ptr(), storage_key.len() as u32, key.as_ptr(), key.len() as u32, &mut length); + let ptr = ext_get_allocated_child_storage.get()( + storage_key.as_ptr(), + storage_key.len() as u32, + key.as_ptr(), + key.len() as u32, + &mut length + ); if length == u32::max_value() { None } else { @@ -153,7 +349,7 @@ pub fn child_storage(storage_key: &[u8], key: &[u8]) -> Option> { /// Set the storage of some particular key to Some value. pub fn set_storage(key: &[u8], value: &[u8]) { unsafe { - ext_set_storage( + ext_set_storage.get()( key.as_ptr(), key.len() as u32, value.as_ptr(), value.len() as u32 ); @@ -163,7 +359,7 @@ pub fn set_storage(key: &[u8], value: &[u8]) { /// Set the child storage of some particular key to Some value. pub fn set_child_storage(storage_key: &[u8], key: &[u8], value: &[u8]) { unsafe { - ext_set_child_storage( + ext_set_child_storage.get()( storage_key.as_ptr(), key.len() as u32, key.as_ptr(), key.len() as u32, value.as_ptr(), value.len() as u32 @@ -174,7 +370,7 @@ pub fn set_child_storage(storage_key: &[u8], key: &[u8], value: &[u8]) { /// Clear the storage of some particular key. pub fn clear_storage(key: &[u8]) { unsafe { - ext_clear_storage( + ext_clear_storage.get()( key.as_ptr(), key.len() as u32 ); } @@ -183,7 +379,7 @@ pub fn clear_storage(key: &[u8]) { /// Clear the storage of some particular key. pub fn clear_child_storage(storage_key: &[u8], key: &[u8]) { unsafe { - ext_clear_child_storage( + ext_clear_child_storage.get()( storage_key.as_ptr(), storage_key.len() as u32, key.as_ptr(), key.len() as u32 ); @@ -193,7 +389,7 @@ pub fn clear_child_storage(storage_key: &[u8], key: &[u8]) { /// Determine whether a particular key exists in storage. pub fn exists_storage(key: &[u8]) -> bool { unsafe { - ext_exists_storage( + ext_exists_storage.get()( key.as_ptr(), key.len() as u32 ) != 0 } @@ -202,7 +398,7 @@ pub fn exists_storage(key: &[u8]) -> bool { /// Determine whether a particular key exists in storage. pub fn exists_child_storage(storage_key: &[u8], key: &[u8]) -> bool { unsafe { - ext_exists_child_storage( + ext_exists_child_storage.get()( storage_key.as_ptr(), storage_key.len() as u32, key.as_ptr(), key.len() as u32 ) != 0 @@ -212,7 +408,7 @@ pub fn exists_child_storage(storage_key: &[u8], key: &[u8]) -> bool { /// Clear the storage entries key of which starts with the given prefix. pub fn clear_prefix(prefix: &[u8]) { unsafe { - ext_clear_prefix( + ext_clear_prefix.get()( prefix.as_ptr(), prefix.len() as u32 ); @@ -222,7 +418,7 @@ pub fn clear_prefix(prefix: &[u8]) { /// Clear an entire child storage. pub fn kill_child_storage(storage_key: &[u8]) { unsafe { - ext_kill_child_storage( + ext_kill_child_storage.get()( storage_key.as_ptr(), storage_key.len() as u32 ); @@ -233,10 +429,12 @@ pub fn kill_child_storage(storage_key: &[u8]) { /// the number of bytes that the key in storage was beyond the offset. pub fn read_storage(key: &[u8], value_out: &mut [u8], value_offset: usize) -> Option { unsafe { - match ext_get_storage_into( - key.as_ptr(), key.len() as u32, - value_out.as_mut_ptr(), value_out.len() as u32, - value_offset as u32 + match ext_get_storage_into.get()( + key.as_ptr(), + key.len() as u32, + value_out.as_mut_ptr(), + value_out.len() as u32, + value_offset as u32, ) { none if none == u32::max_value() => None, length => Some(length as usize), @@ -248,7 +446,7 @@ pub fn read_storage(key: &[u8], value_out: &mut [u8], value_offset: usize) -> Op /// the number of bytes that the key in storage was beyond the offset. pub fn read_child_storage(storage_key: &[u8], key: &[u8], value_out: &mut [u8], value_offset: usize) -> Option { unsafe { - match ext_get_child_storage_into( + match ext_get_child_storage_into.get()( storage_key.as_ptr(), storage_key.len() as u32, key.as_ptr(), key.len() as u32, value_out.as_mut_ptr(), value_out.len() as u32, @@ -264,7 +462,7 @@ pub fn read_child_storage(storage_key: &[u8], key: &[u8], value_out: &mut [u8], pub fn storage_root() -> [u8; 32] { let mut result: [u8; 32] = Default::default(); unsafe { - ext_storage_root(result.as_mut_ptr()); + ext_storage_root.get()(result.as_mut_ptr()); } result } @@ -273,7 +471,7 @@ pub fn storage_root() -> [u8; 32] { pub fn child_storage_root(storage_key: &[u8]) -> Option> { let mut length: u32 = 0; unsafe { - let ptr = ext_child_storage_root(storage_key.as_ptr(), storage_key.len() as u32, &mut length); + let ptr = ext_child_storage_root.get()(storage_key.as_ptr(), storage_key.len() as u32, &mut length); if length == u32::max_value() { None } else { @@ -289,7 +487,7 @@ pub fn child_storage_root(storage_key: &[u8]) -> Option> { pub fn storage_changes_root(parent_hash: [u8; 32], parent_num: u64) -> Option<[u8; 32]> { let mut result: [u8; 32] = Default::default(); let is_set = unsafe { - ext_storage_changes_root(parent_hash.as_ptr(), parent_hash.len() as u32, parent_num, result.as_mut_ptr()) + ext_storage_changes_root.get()(parent_hash.as_ptr(), parent_hash.len() as u32, parent_num, result.as_mut_ptr()) }; if is_set != 0 { @@ -326,7 +524,7 @@ pub fn ordered_trie_root< /// The current relay chain identifier. pub fn chain_id() -> u64 { unsafe { - ext_chain_id() + ext_chain_id.get()() } } @@ -334,7 +532,7 @@ pub fn chain_id() -> u64 { pub fn blake2_256(data: &[u8]) -> [u8; 32] { let mut result: [u8; 32] = Default::default(); unsafe { - ext_blake2_256(data.as_ptr(), data.len() as u32, result.as_mut_ptr()); + ext_blake2_256.get()(data.as_ptr(), data.len() as u32, result.as_mut_ptr()); } result } @@ -343,7 +541,7 @@ pub fn blake2_256(data: &[u8]) -> [u8; 32] { pub fn keccak_256(data: &[u8]) -> [u8; 32] { let mut result: [u8; 32] = Default::default(); unsafe { - ext_keccak_256(data.as_ptr(), data.len() as u32, result.as_mut_ptr()); + ext_keccak_256.get()(data.as_ptr(), data.len() as u32, result.as_mut_ptr()); } result } @@ -352,7 +550,7 @@ pub fn keccak_256(data: &[u8]) -> [u8; 32] { pub fn twox_256(data: &[u8]) -> [u8; 32] { let mut result: [u8; 32] = Default::default(); unsafe { - ext_twox_256(data.as_ptr(), data.len() as u32, result.as_mut_ptr()); + ext_twox_256.get()(data.as_ptr(), data.len() as u32, result.as_mut_ptr()); } result } @@ -361,7 +559,7 @@ pub fn twox_256(data: &[u8]) -> [u8; 32] { pub fn twox_128(data: &[u8]) -> [u8; 16] { let mut result: [u8; 16] = Default::default(); unsafe { - ext_twox_128(data.as_ptr(), data.len() as u32, result.as_mut_ptr()); + ext_twox_128.get()(data.as_ptr(), data.len() as u32, result.as_mut_ptr()); } result } @@ -369,14 +567,14 @@ pub fn twox_128(data: &[u8]) -> [u8; 16] { /// Verify a ed25519 signature. pub fn ed25519_verify>(sig: &[u8; 64], msg: &[u8], pubkey: P) -> bool { unsafe { - ext_ed25519_verify(msg.as_ptr(), msg.len() as u32, sig.as_ptr(), pubkey.as_ref().as_ptr()) == 0 + ext_ed25519_verify.get()(msg.as_ptr(), msg.len() as u32, sig.as_ptr(), pubkey.as_ref().as_ptr()) == 0 } } /// Verify a sr25519 signature. pub fn sr25519_verify>(sig: &[u8; 64], msg: &[u8], pubkey: P) -> bool { unsafe { - ext_sr25519_verify(msg.as_ptr(), msg.len() as u32, sig.as_ptr(), pubkey.as_ref().as_ptr()) == 0 + ext_sr25519_verify.get()(msg.as_ptr(), msg.len() as u32, sig.as_ptr(), pubkey.as_ref().as_ptr()) == 0 } } @@ -386,7 +584,7 @@ pub fn sr25519_verify>(sig: &[u8; 64], msg: &[u8], pubkey: P) -> pub fn secp256k1_ecdsa_recover(sig: &[u8; 65], msg: &[u8; 32]) -> Result<[u8; 64], EcdsaVerifyError> { let mut pubkey = [0u8; 64]; match unsafe { - ext_secp256k1_ecdsa_recover(msg.as_ptr(), sig.as_ptr(), pubkey.as_mut_ptr()) + ext_secp256k1_ecdsa_recover.get()(msg.as_ptr(), sig.as_ptr(), pubkey.as_mut_ptr()) } { 0 => Ok(pubkey), 1 => Err(EcdsaVerifyError::BadRS), @@ -404,7 +602,7 @@ pub trait Printable { impl<'a> Printable for &'a [u8] { fn print(self) { unsafe { - ext_print_hex(self.as_ptr(), self.len() as u32); + ext_print_hex.get()(self.as_ptr(), self.len() as u32); } } } @@ -412,14 +610,14 @@ impl<'a> Printable for &'a [u8] { impl<'a> Printable for &'a str { fn print(self) { unsafe { - ext_print_utf8(self.as_ptr() as *const u8, self.len() as u32); + ext_print_utf8.get()(self.as_ptr() as *const u8, self.len() as u32); } } } impl Printable for u64 { fn print(self) { - unsafe { ext_print_num(self); } + unsafe { ext_print_num.get()(self); } } } diff --git a/core/state-machine/src/lib.rs b/core/state-machine/src/lib.rs index ede2bf40b0f67..135c1dfc6be66 100644 --- a/core/state-machine/src/lib.rs +++ b/core/state-machine/src/lib.rs @@ -151,7 +151,7 @@ pub trait Externalities { /// Returns None if key provided is not a storage key. This can due to not being started with CHILD_STORAGE_KEY_PREFIX, or the trie implementation regards the key as invalid. fn child_storage_root(&mut self, storage_key: &[u8]) -> Option>; - /// Get the change trie root of the current storage overlay at a block wth given parent. + /// Get the change trie root of the current storage overlay at a block with given parent. fn storage_changes_root(&mut self, parent: H::Out, parent_num: u64) -> Option where H::Out: Ord; } diff --git a/core/test-runtime/Cargo.toml b/core/test-runtime/Cargo.toml index e4dda6a397f88..bddabbe928c96 100644 --- a/core/test-runtime/Cargo.toml +++ b/core/test-runtime/Cargo.toml @@ -20,6 +20,7 @@ runtime_io = { package = "sr-io", path = "../sr-io", default-features = false } runtime_primitives = { package = "sr-primitives", path = "../sr-primitives", default-features = false } runtime_version = { package = "sr-version", path = "../sr-version", default-features = false } runtime_support = { package = "srml-support", path = "../../srml/support", default-features = false } +executive = { package = "srml-executive", path = "../../srml/executive", default-features = false } cfg-if = "0.1.6" [dev-dependencies] @@ -44,4 +45,5 @@ std = [ "runtime_primitives/std", "runtime_version/std", "consensus_aura/std", + "executive/std", ] diff --git a/core/test-runtime/src/lib.rs b/core/test-runtime/src/lib.rs index b345c06e6cb4e..9c6f26e4a0455 100644 --- a/core/test-runtime/src/lib.rs +++ b/core/test-runtime/src/lib.rs @@ -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; 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 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 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 for Runtime { @@ -442,4 +482,4 @@ cfg_if! { } } } -} +} \ No newline at end of file diff --git a/core/test-runtime/src/system.rs b/core/test-runtime/src/system.rs index f1e04473ece18..a66eb58c1f482 100644 --- a/core/test-runtime/src/system.rs +++ b/core/test-runtime/src/system.rs @@ -21,7 +21,7 @@ use rstd::prelude::*; use runtime_io::{storage_root, enumerated_trie_root, storage_changes_root, twox_128}; use runtime_support::storage::{self, StorageValue, StorageMap}; use runtime_support::storage_items; -use runtime_primitives::traits::{Hash as HashT, BlakeTwo256, Digest as DigestT}; +use runtime_primitives::traits::{Hash as HashT, BlakeTwo256, Digest as DigestT, NumberFor, Block as BlockT}; use runtime_primitives::generic; use runtime_primitives::{ApplyError, ApplyOutcome, ApplyResult, transaction_validity::TransactionValidity}; use parity_codec::{KeyedVec, Encode}; @@ -70,6 +70,15 @@ pub fn initialise_block(header: &Header) { storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &0u32); } +fn execute_extrinsics_without_checks(extrinsics: Vec<::Extrinsic>) { + // execute transactions + extrinsics.into_iter().enumerate().for_each(|(i, e)| { + storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &(i as u32)); + execute_transaction_backend(&e).unwrap_or_else(|_| panic!("Invalid transaction")); + storage::unhashed::kill(well_known_keys::EXTRINSIC_INDEX); + }); +} + /// Actually execute all transitioning for `block`. pub fn polish_block(block: &mut Block) { let header = &mut block.header; @@ -111,12 +120,7 @@ pub fn execute_block(block: Block) { info_expect_equal_hash(&txs_root, &header.extrinsics_root); assert!(txs_root == header.extrinsics_root, "Transaction trie root must be valid."); - // execute transactions - block.extrinsics.iter().enumerate().for_each(|(i, e)| { - storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &(i as u32)); - execute_transaction_backend(e).unwrap_or_else(|_| panic!("Invalid transaction")); - storage::unhashed::kill(well_known_keys::EXTRINSIC_INDEX); - }); + execute_extrinsics_without_checks(block.extrinsics); // check storage root. let storage_root = storage_root().into(); @@ -134,6 +138,19 @@ pub fn execute_block(block: Block) { assert!(digest == header.digest, "Header digest items must match that calculated."); } +/// The block executor. +pub struct BlockExecutor; + +impl executive::ExecuteBlock for BlockExecutor { + fn execute_block(block: Block) { + execute_block(block); + } + + fn execute_extrinsics_without_checks(_: NumberFor, extrinsics: Vec<::Extrinsic>) { + execute_extrinsics_without_checks(extrinsics); + } +} + /// Execute a transaction outside of the block execution function. /// This doesn't attempt to validate anything regarding the block. pub fn validate_transaction(utx: Extrinsic) -> TransactionValidity { @@ -307,11 +324,6 @@ mod tests { ]) } - fn construct_signed_tx(tx: Transfer) -> Extrinsic { - let signature = AccountKeyring::from_public(&tx.from).unwrap().sign(&tx.encode()).into(); - Extrinsic::Transfer(tx, signature) - } - fn block_import_works(block_executor: F) where F: Fn(Block, &mut TestExternalities) { let h = Header { parent_hash: [69u8; 32].into(), @@ -356,12 +368,12 @@ mod tests { digest: Default::default(), }, extrinsics: vec![ - construct_signed_tx(Transfer { + Transfer { from: AccountKeyring::Alice.into(), to: AccountKeyring::Bob.into(), amount: 69, nonce: 0, - }) + }.into_signed_tx() ], }; @@ -377,18 +389,18 @@ mod tests { digest: Default::default(), }, extrinsics: vec![ - construct_signed_tx(Transfer { + Transfer { from: AccountKeyring::Bob.into(), to: AccountKeyring::Alice.into(), amount: 27, nonce: 0, - }), - construct_signed_tx(Transfer { + }.into_signed_tx(), + Transfer { from: AccountKeyring::Alice.into(), to: AccountKeyring::Charlie.into(), amount: 69, nonce: 1, - }), + }.into_signed_tx(), ], }; diff --git a/core/test-runtime/wasm/Cargo.lock b/core/test-runtime/wasm/Cargo.lock index a5b87b4436956..0746e5aa81f3e 100644 --- a/core/test-runtime/wasm/Cargo.lock +++ b/core/test-runtime/wasm/Cargo.lock @@ -61,7 +61,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bitmask" version = "0.5.0" -source = "git+https://github.com/paritytech/bitmask#c2d8d196e30b018d1385be8357fdca61b978facf" +source = "git+https://github.com/paritytech/bitmask#a84e147be602631617badd18b6b9af83391db4a9" [[package]] name = "blake2-rfc" @@ -378,7 +378,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -854,7 +854,7 @@ dependencies = [ "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -903,7 +903,7 @@ dependencies = [ "proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -960,7 +960,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1194,6 +1194,14 @@ name = "ryu" version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "safe-mix" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "schnorrkel" version = "0.0.0" @@ -1241,7 +1249,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1353,7 +1361,7 @@ dependencies = [ "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1406,6 +1414,19 @@ dependencies = [ "sr-std 0.1.0", ] +[[package]] +name = "srml-executive" +version = "0.1.0" +dependencies = [ + "parity-codec 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-io 0.1.0", + "sr-primitives 0.1.0", + "sr-std 0.1.0", + "srml-support 0.1.0", + "srml-system 0.1.0", +] + [[package]] name = "srml-metadata" version = "0.1.0" @@ -1444,7 +1465,7 @@ dependencies = [ "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", "sr-api-macros 0.1.0", "srml-support-procedural-tools 0.1.0", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1455,7 +1476,7 @@ dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", "srml-support-procedural-tools-derive 0.1.0", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1464,7 +1485,23 @@ version = "0.1.0" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "srml-system" +version = "0.1.0" +dependencies = [ + "hex-literal 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-io 0.1.0", + "sr-primitives 0.1.0", + "sr-std 0.1.0", + "srml-support 0.1.0", + "substrate-primitives 0.1.0", ] [[package]] @@ -1677,6 +1714,7 @@ dependencies = [ "sr-primitives 0.1.0", "sr-std 0.1.0", "sr-version 0.1.0", + "srml-executive 0.1.0", "srml-support 0.1.0", "substrate-client 0.1.0", "substrate-consensus-aura-primitives 0.1.0", @@ -1715,7 +1753,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "0.15.27" +version = "0.15.29" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1730,7 +1768,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2262,6 +2300,7 @@ dependencies = [ "checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" +"checksum safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7f7bf422d23a88c16d5090d455f182bc99c60af4df6a345c63428acf5129e347" "checksum schnorrkel 0.0.0 (git+https://github.com/w3f/schnorrkel)" = "" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" @@ -2285,7 +2324,7 @@ dependencies = [ "checksum substrate-bip39 0.2.0 (git+https://github.com/paritytech/substrate-bip39)" = "" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" "checksum subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "702662512f3ddeb74a64ce2fbbf3707ee1b6bb663d28bb054e0779bbc720d926" -"checksum syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)" = "525bd55255f03c816e5d7f615587bd13030c7103354fadb104993dcee6a788ec" +"checksum syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1825685f977249735d510a242a6727b46efe914bb67e38d30c071b1b72b1d5c2" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" diff --git a/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm b/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm index e844c0124e12a..bff5d3c6fc95a 100644 Binary files a/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm and b/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm differ diff --git a/node/runtime/src/lib.rs b/node/runtime/src/lib.rs index 55293d3e46ed2..ae24c263f7825 100644 --- a/node/runtime/src/lib.rs +++ b/node/runtime/src/lib.rs @@ -62,7 +62,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { impl_name: create_runtime_str!("substrate-node"), authoring_version: 10, spec_version: 35, - impl_version: 36, + impl_version: 37, apis: RUNTIME_API_VERSIONS, }; diff --git a/node/runtime/wasm/Cargo.lock b/node/runtime/wasm/Cargo.lock index 543020eed7a47..7c87f49874daf 100644 --- a/node/runtime/wasm/Cargo.lock +++ b/node/runtime/wasm/Cargo.lock @@ -61,7 +61,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bitmask" version = "0.5.0" -source = "git+https://github.com/paritytech/bitmask#c2d8d196e30b018d1385be8357fdca61b978facf" +source = "git+https://github.com/paritytech/bitmask#a84e147be602631617badd18b6b9af83391db4a9" [[package]] name = "blake2-rfc" @@ -117,7 +117,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bytes" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -378,7 +378,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -913,7 +913,7 @@ dependencies = [ "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -962,7 +962,7 @@ dependencies = [ "proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1019,7 +1019,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1318,7 +1318,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1430,7 +1430,7 @@ dependencies = [ "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1764,7 +1764,7 @@ dependencies = [ "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", "sr-api-macros 0.1.0", "srml-support-procedural-tools 0.1.0", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1775,7 +1775,7 @@ dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", "srml-support-procedural-tools-derive 0.1.0", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1784,7 +1784,7 @@ version = "0.1.0" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2075,7 +2075,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "0.15.27" +version = "0.15.29" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2090,7 +2090,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2144,7 +2144,7 @@ name = "tokio" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2167,7 +2167,7 @@ name = "tokio-codec" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2205,7 +2205,7 @@ name = "tokio-io" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2242,7 +2242,7 @@ name = "tokio-tcp" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2282,7 +2282,7 @@ name = "tokio-udp" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2296,7 +2296,7 @@ name = "tokio-uds" version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2455,7 +2455,7 @@ version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2493,7 +2493,7 @@ dependencies = [ "checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" -"checksum bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "40ade3d27603c2cb345eb0912aec461a6dec7e06a4ae48589904e808335c7afa" +"checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" "checksum cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)" = "d01c69d08ff207f231f07196e30f84c70f1c815b04f980f8b7b01ff01f05eb92" "checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" @@ -2647,7 +2647,7 @@ dependencies = [ "checksum substrate-bip39 0.2.0 (git+https://github.com/paritytech/substrate-bip39)" = "" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" "checksum subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "702662512f3ddeb74a64ce2fbbf3707ee1b6bb663d28bb054e0779bbc720d926" -"checksum syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)" = "525bd55255f03c816e5d7f615587bd13030c7103354fadb104993dcee6a788ec" +"checksum syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1825685f977249735d510a242a6727b46efe914bb67e38d30c071b1b72b1d5c2" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" diff --git a/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm b/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm index f18a1fd01dd5b..b8166f59e6e47 100644 Binary files a/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm and b/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm differ diff --git a/srml/executive/src/lib.rs b/srml/executive/src/lib.rs index d00c2693ffafb..b6cc498f79dac 100644 --- a/srml/executive/src/lib.rs +++ b/srml/executive/src/lib.rs @@ -18,12 +18,13 @@ #![cfg_attr(not(feature = "std"), no_std)] - use rstd::prelude::*; use rstd::marker::PhantomData; use rstd::result; -use primitives::traits::{self, Header, Zero, One, Checkable, Applyable, CheckEqual, OnFinalise, - OnInitialise, Hash, As, Digest}; +use primitives::traits::{ + self, Header, Zero, One, Checkable, Applyable, CheckEqual, OnFinalise, + OnInitialise, Hash, As, Digest, NumberFor, Block as BlockT +}; use srml_support::{Dispatchable, traits::ChargeBytesFee}; use parity_codec::{Codec, Encode}; use system::extrinsics_root; @@ -47,18 +48,43 @@ mod internal { } } -pub struct Executive< - System, - Block, - Context, - Payment, - AllModules, ->(PhantomData<(System, Block, Context, Payment, AllModules)>); +/// Something that can be used to execute a block. +pub trait ExecuteBlock { + /// Actually execute all transitioning for `block`. + fn execute_block(block: Block); + /// Execute all extrinsics like when executing a `block`, but with dropping intial and final checks. + fn execute_extrinsics_without_checks(block_number: NumberFor, extrinsics: Vec); +} + +pub struct Executive( + PhantomData<(System, Block, Context, Payment, AllModules)> +); impl< + System: system::Trait, + Block: traits::Block, Context: Default, + Payment: ChargeBytesFee, + AllModules: OnInitialise + OnFinalise, +> ExecuteBlock for Executive where + Block::Extrinsic: Checkable + Codec, + >::Checked: Applyable, + <>::Checked as Applyable>::Call: Dispatchable, + <<>::Checked as Applyable>::Call as Dispatchable>::Origin: From> +{ + fn execute_block(block: Block) { + Self::execute_block(block); + } + + fn execute_extrinsics_without_checks(block_number: NumberFor, extrinsics: Vec) { + Self::execute_extrinsics_without_checks(block_number, extrinsics); + } +} + +impl< System: system::Trait, Block: traits::Block, + Context: Default, Payment: ChargeBytesFee, AllModules: OnInitialise + OnFinalise, > Executive where @@ -69,8 +95,12 @@ impl< { /// Start the execution of a particular block. pub fn initialise_block(header: &System::Header) { - >::initialise(header.number(), header.parent_hash(), header.extrinsics_root()); - >::on_initialise(*header.number()); + Self::initialise_block_impl(header.number(), header.parent_hash(), header.extrinsics_root()); + } + + fn initialise_block_impl(block_number: &System::BlockNumber, parent_hash: &System::Hash, extrinsics_root: &System::Hash) { + >::initialise(block_number, parent_hash, extrinsics_root); + >::on_initialise(*block_number); } fn initial_checks(block: &Block) { @@ -96,18 +126,35 @@ impl< // any initial checks Self::initial_checks(&block); - // execute transactions + // execute extrinsics let (header, extrinsics) = block.deconstruct(); - extrinsics.into_iter().for_each(Self::apply_extrinsic_no_note); - - // post-transactional book-keeping. - >::note_finished_extrinsics(); - >::on_finalise(*header.number()); + Self::execute_extrinsics_with_book_keeping(extrinsics, *header.number()); // any final checks Self::final_checks(&header); } + /// Execute all extrinsics like when executing a `block`, but with dropping intial and final checks. + pub fn execute_extrinsics_without_checks(block_number: NumberFor, extrinsics: Vec) { + // Make the api happy, but maybe we should not set them at all. + let parent_hash = ::Hashing::hash(b"parent_hash"); + let extrinsics_root = ::Hashing::hash(b"extrinsics_root"); + + Self::initialise_block_impl(&block_number, &parent_hash, &extrinsics_root); + + // execute extrinsics + Self::execute_extrinsics_with_book_keeping(extrinsics, block_number); + } + + /// Execute given extrinsics and take care of post-extrinsics book-keeping + fn execute_extrinsics_with_book_keeping(extrinsics: Vec, block_number: NumberFor) { + extrinsics.into_iter().for_each(Self::apply_extrinsic_no_note); + + // post-extrinsics book-keeping. + >::note_finished_extrinsics(); + >::on_finalise(block_number); + } + /// Finalise the block - it is up the caller to ensure that all header fields are valid /// except state-root. pub fn finalise_block() -> System::Header { diff --git a/srml/support/src/storage/mod.rs b/srml/support/src/storage/mod.rs index dec8b2fec80a8..fde0762877874 100644 --- a/srml/support/src/storage/mod.rs +++ b/srml/support/src/storage/mod.rs @@ -38,7 +38,7 @@ impl<'a> Input for IncrementalInput<'a> { } } - /// Return the value of the item in storage under `key`, or `None` if there is no explicit entry. +/// Return the value of the item in storage under `key`, or `None` if there is no explicit entry. pub fn get(key: &[u8]) -> Option { let key = twox_128(key); runtime_io::read_storage(&key[..], &mut [0; 0][..], 0).map(|_| { diff --git a/srml/system/src/lib.rs b/srml/system/src/lib.rs index 384c4fb462b1e..c5397345a1e95 100644 --- a/srml/system/src/lib.rs +++ b/srml/system/src/lib.rs @@ -324,8 +324,7 @@ impl Module { // > stays to be inspected by the client. - ::new(number, extrinsics_root, storage_root, - parent_hash, digest) + ::new(number, extrinsics_root, storage_root, parent_hash, digest) } /// Deposits a log and ensures it matches the blocks log data.