[big refactor] Remove crate aliasing. (#4395)

* Rename: Phase 1.

* Unify codec.

* Fixing: Phase 2

* Fixing: Phase 3.

* Fixing: Phase 4.

* Fixing: Phase 5.

* Fixing: Phase 6.

* Fixing: Phase 7.

* Fixing: Phase 8. Tests

* Fixing: Phase 9. Tests!!!

* Fixing: Phase 10. Moar tests!

* Finally done!

* More fixes.

* Rename primitives:: to sp_core::

* Apply renames in finality-grandpa.

* Fix benches.

* Fix benches 2.

* Revert node-template.

* Fix frame-system in our modules.
This commit is contained in:
Tomasz Drwięga
2019-12-16 13:36:49 +01:00
committed by Gavin Wood
parent f14d98a439
commit 8778ca7dc8
485 changed files with 4023 additions and 4005 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ use crate::error::{Error, Result};
use log::trace;
use std::convert::{TryFrom, TryInto};
use std::ops::Range;
use wasm_interface::{Pointer, WordSize};
use sp_wasm_interface::{Pointer, WordSize};
// The pointers need to be aligned to 8 bytes. This is because the
// maximum value type handled by wasm32 is u64.
@@ -18,12 +18,12 @@
use codec::Encode;
use std::{convert::TryFrom, str};
use primitives::{
use sp_core::{
blake2_128, blake2_256, twox_64, twox_128, twox_256, ed25519, sr25519, keccak_256, Blake2Hasher, Pair,
crypto::KeyTypeId, offchain,
};
use trie::{TrieConfiguration, trie_types::Layout};
use wasm_interface::{
use sp_trie::{TrieConfiguration, trie_types::Layout};
use sp_wasm_interface::{
Pointer, WordSize, WritePrimitive, ReadPrimitive, FunctionContext, Result as WResult,
};
+2 -2
View File
@@ -16,7 +16,7 @@
//! Rust executor possible errors.
use serializer;
use sp_serializer;
use wasmi;
#[cfg(feature = "wasmtime")]
use wasmtime_jit::{ActionError, SetupError};
@@ -28,7 +28,7 @@ pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, derive_more::Display, derive_more::From)]
pub enum Error {
/// Unserializable Data
InvalidData(serializer::Error),
InvalidData(sp_serializer::Error),
/// Trap occured during execution
Trap(wasmi::Trap),
/// Wasmi loading/instantiating error
@@ -18,15 +18,15 @@ mod sandbox;
use codec::{Encode, Decode};
use hex_literal::hex;
use primitives::{
use sp_core::{
Blake2Hasher, blake2_128, blake2_256, ed25519, sr25519, map, Pair,
offchain::{OffchainExt, testing},
traits::Externalities,
};
use runtime_test::WASM_BINARY;
use state_machine::TestExternalities as CoreTestExternalities;
use sc_runtime_test::WASM_BINARY;
use sp_state_machine::TestExternalities as CoreTestExternalities;
use test_case::test_case;
use trie::{TrieConfiguration, trie_types::Layout};
use sp_trie::{TrieConfiguration, trie_types::Layout};
use crate::WasmExecutionMethod;
@@ -128,7 +128,7 @@ fn storage_should_work(wasm_method: WasmExecutionMethod) {
assert_eq!(output, b"all ok!".to_vec().encode());
}
let expected = TestExternalities::new(primitives::storage::Storage {
let expected = TestExternalities::new(sp_core::storage::Storage {
top: map![
b"input".to_vec() => b"Hello world".to_vec(),
b"foo".to_vec() => b"bar".to_vec(),
@@ -165,7 +165,7 @@ fn clear_prefix_should_work(wasm_method: WasmExecutionMethod) {
assert_eq!(output, b"all ok!".to_vec().encode());
}
let expected = TestExternalities::new(primitives::storage::Storage {
let expected = TestExternalities::new(sp_core::storage::Storage {
top: map![
b"aaa".to_vec() => b"1".to_vec(),
b"aab".to_vec() => b"2".to_vec(),
@@ -443,7 +443,7 @@ fn ordered_trie_root_should_work(wasm_method: WasmExecutionMethod) {
#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
fn offchain_local_storage_should_work(wasm_method: WasmExecutionMethod) {
use primitives::offchain::OffchainStorage;
use sp_core::offchain::OffchainStorage;
let mut ext = TestExternalities::default();
let (offchain, state) = testing::TestOffchainExt::new();
@@ -18,7 +18,7 @@ use super::{TestExternalities, call_in_wasm};
use crate::WasmExecutionMethod;
use codec::Encode;
use runtime_test::WASM_BINARY;
use sc_runtime_test::WASM_BINARY;
use test_case::test_case;
use wabt;
+5 -5
View File
@@ -46,12 +46,12 @@ mod integration_tests;
pub mod error;
pub use wasmi;
pub use native_executor::{with_native_environment, NativeExecutor, NativeExecutionDispatch};
pub use runtime_version::{RuntimeVersion, NativeVersion};
pub use sp_version::{RuntimeVersion, NativeVersion};
pub use codec::Codec;
#[doc(hidden)]
pub use primitives::traits::Externalities;
pub use sp_core::traits::Externalities;
#[doc(hidden)]
pub use wasm_interface;
pub use sp_wasm_interface;
pub use wasm_runtime::WasmExecutionMethod;
/// Call the given `function` in the given wasm `code`.
@@ -64,7 +64,7 @@ pub use wasm_runtime::WasmExecutionMethod;
/// - `heap_pages`: The number of heap pages to allocate.
///
/// Returns the `Vec<u8>` that contains the return value of the function.
pub fn call_in_wasm<E: Externalities, HF: wasm_interface::HostFunctions>(
pub fn call_in_wasm<E: Externalities, HF: sp_wasm_interface::HostFunctions>(
function: &str,
call_data: &[u8],
execution_method: WasmExecutionMethod,
@@ -93,7 +93,7 @@ pub trait RuntimeInfo {
#[cfg(test)]
mod tests {
use super::*;
use runtime_test::WASM_BINARY;
use sc_runtime_test::WASM_BINARY;
use sp_io::TestExternalities;
#[test]
@@ -19,17 +19,17 @@ use crate::{
wasm_runtime::{RuntimesCache, WasmExecutionMethod, WasmRuntime},
};
use runtime_version::{NativeVersion, RuntimeVersion};
use sp_version::{NativeVersion, RuntimeVersion};
use codec::{Decode, Encode};
use primitives::{NativeOrEncoded, traits::{CodeExecutor, Externalities}};
use sp_core::{NativeOrEncoded, traits::{CodeExecutor, Externalities}};
use log::trace;
use std::{result, cell::RefCell, panic::{UnwindSafe, AssertUnwindSafe}};
use wasm_interface::{HostFunctions, Function};
use sp_wasm_interface::{HostFunctions, Function};
thread_local! {
static RUNTIMES_CACHE: RefCell<RuntimesCache> = RefCell::new(RuntimesCache::new());
@@ -43,7 +43,7 @@ pub(crate) fn safe_call<F, U>(f: F) -> Result<U>
{
// Substrate uses custom panic hook that terminates process on panic. Disable
// termination for the native call.
let _guard = panic_handler::AbortGuard::force_unwind();
let _guard = sp_panic_handler::AbortGuard::force_unwind();
std::panic::catch_unwind(f).map_err(|_| Error::Runtime)
}
@@ -53,7 +53,7 @@ pub(crate) fn safe_call<F, U>(f: F) -> Result<U>
pub fn with_native_environment<F, U>(ext: &mut dyn Externalities, f: F) -> Result<U>
where F: UnwindSafe + FnOnce() -> U
{
externalities::set_and_run_with_externalities(ext, move || safe_call(f))
sp_externalities::set_and_run_with_externalities(ext, move || safe_call(f))
}
/// Delegate for dispatching a CodeExecutor call.
@@ -267,8 +267,8 @@ impl<D: NativeExecutionDispatch> CodeExecutor for NativeExecutor<D> {
/// ```
/// sc_executor::native_executor_instance!(
/// pub MyExecutor,
/// test_runtime::api::dispatch,
/// test_runtime::native_version,
/// substrate_test_runtime::api::dispatch,
/// substrate_test_runtime::native_version,
/// );
/// ```
///
@@ -278,7 +278,7 @@ impl<D: NativeExecutionDispatch> CodeExecutor for NativeExecutor<D> {
/// executor aware of the host functions for these interfaces.
///
/// ```
/// # use runtime_interface::runtime_interface;
/// # use sp_runtime_interface::runtime_interface;
///
/// #[runtime_interface]
/// trait MyInterface {
@@ -289,8 +289,8 @@ impl<D: NativeExecutionDispatch> CodeExecutor for NativeExecutor<D> {
///
/// sc_executor::native_executor_instance!(
/// pub MyExecutor,
/// test_runtime::api::dispatch,
/// test_runtime::native_version,
/// substrate_test_runtime::api::dispatch,
/// substrate_test_runtime::native_version,
/// my_interface::HostFunctions,
/// );
/// ```
@@ -337,7 +337,7 @@ macro_rules! native_executor_instance {
#[cfg(test)]
mod tests {
use super::*;
use runtime_interface::runtime_interface;
use sp_runtime_interface::runtime_interface;
#[runtime_interface]
trait MyInterface {
@@ -348,8 +348,8 @@ mod tests {
native_executor_instance!(
pub MyExecutor,
test_runtime::api::dispatch,
test_runtime::native_version,
substrate_test_runtime::api::dispatch,
substrate_test_runtime::native_version,
(my_interface::HostFunctions, my_interface::HostFunctions),
);
+2 -2
View File
@@ -21,12 +21,12 @@
use crate::error::{Result, Error};
use std::{collections::HashMap, rc::Rc};
use codec::{Decode, Encode};
use primitives::sandbox as sandbox_primitives;
use sp_core::sandbox as sandbox_primitives;
use wasmi::{
Externals, ImportResolver, MemoryInstance, MemoryRef, Module, ModuleInstance,
ModuleRef, RuntimeArgs, RuntimeValue, Trap, TrapKind, memory_units::Pages,
};
use wasm_interface::{Pointer, WordSize};
use sp_wasm_interface::{Pointer, WordSize};
/// Index of a function inside the supervisor.
///
@@ -26,12 +26,12 @@ use log::{trace, warn};
use codec::Decode;
use primitives::{storage::well_known_keys, traits::Externalities};
use sp_core::{storage::well_known_keys, traits::Externalities};
use runtime_version::RuntimeVersion;
use sp_version::RuntimeVersion;
use std::{collections::hash_map::{Entry, HashMap}, panic::AssertUnwindSafe};
use wasm_interface::Function;
use sp_wasm_interface::Function;
/// The Substrate Wasm runtime.
pub trait WasmRuntime {
@@ -259,7 +259,7 @@ fn create_versioned_wasm_runtime<E: Externalities>(
#[cfg(test)]
mod tests {
use wasm_interface::HostFunctions;
use sp_wasm_interface::HostFunctions;
#[test]
fn host_functions_are_equal() {
+15 -15
View File
@@ -16,28 +16,28 @@
//! Utilities for defining the wasm host environment.
use wasm_interface::{Pointer, WordSize};
use sp_wasm_interface::{Pointer, WordSize};
/// Converts arguments into respective WASM types.
#[macro_export]
macro_rules! convert_args {
() => ([]);
( $( $t:ty ),* ) => ( [ $( <$t as $crate::wasm_interface::IntoValue>::VALUE_TYPE, )* ] );
( $( $t:ty ),* ) => ( [ $( <$t as $crate::sp_wasm_interface::IntoValue>::VALUE_TYPE, )* ] );
}
/// Generates a WASM signature for given list of parameters.
#[macro_export]
macro_rules! gen_signature {
( ( $( $params: ty ),* ) ) => (
$crate::wasm_interface::Signature {
$crate::sp_wasm_interface::Signature {
args: std::borrow::Cow::Borrowed(&convert_args!( $( $params ),* )[..]),
return_value: None,
}
);
( ( $( $params: ty ),* ) -> $returns:ty ) => (
$crate::wasm_interface::Signature {
$crate::sp_wasm_interface::Signature {
args: std::borrow::Cow::Borrowed(&convert_args!( $( $params ),* )[..]),
return_value: Some(<$returns as $crate::wasm_interface::IntoValue>::VALUE_TYPE),
return_value: Some(<$returns as $crate::sp_wasm_interface::IntoValue>::VALUE_TYPE),
}
);
}
@@ -63,18 +63,18 @@ macro_rules! gen_functions {
struct $name;
#[allow(unused)]
impl $crate::wasm_interface::Function for $name {
impl $crate::sp_wasm_interface::Function for $name {
fn name(&self) -> &str {
stringify!($name)
}
fn signature(&self) -> $crate::wasm_interface::Signature {
fn signature(&self) -> $crate::sp_wasm_interface::Signature {
gen_signature!( ( $( $params ),* ) $( -> $returns )? )
}
fn execute(
&self,
context: &mut dyn $crate::wasm_interface::FunctionContext,
args: &mut dyn Iterator<Item=$crate::wasm_interface::Value>,
) -> ::std::result::Result<Option<$crate::wasm_interface::Value>, String> {
context: &mut dyn $crate::sp_wasm_interface::FunctionContext,
args: &mut dyn Iterator<Item=$crate::sp_wasm_interface::Value>,
) -> ::std::result::Result<Option<$crate::sp_wasm_interface::Value>, String> {
let mut $context = context;
marshall! {
args,
@@ -83,7 +83,7 @@ macro_rules! gen_functions {
}
}
&$name as &dyn $crate::wasm_interface::Function
&$name as &dyn $crate::sp_wasm_interface::Function
},
}
$context,
@@ -103,7 +103,7 @@ macro_rules! unmarshall_args {
$(
let $names : $params =
$args_iter.next()
.and_then(|val| <$params as $crate::wasm_interface::TryFromValue>::try_from_value(val))
.and_then(|val| <$params as $crate::sp_wasm_interface::TryFromValue>::try_from_value(val))
.expect(
"`$args_iter` comes from an argument of Externals::execute_function;
args to an external call always matches the signature of the external;
@@ -140,7 +140,7 @@ macro_rules! marshall {
unmarshall_args!($body, $args_iter, $( $names : $params ),*)
});
let r = body()?;
return Ok(Some($crate::wasm_interface::IntoValue::into_value(r)))
return Ok(Some($crate::sp_wasm_interface::IntoValue::into_value(r)))
});
( $args_iter:ident, ( $( $names:ident : $params:ty ),* ) => $body:tt ) => ({
let body = $crate::wasm_utils::constrain_closure::<(), _>(|| {
@@ -162,9 +162,9 @@ macro_rules! impl_wasm_host_interface {
)*
}
) => (
impl $crate::wasm_interface::HostFunctions for $interface_name {
impl $crate::sp_wasm_interface::HostFunctions for $interface_name {
#[allow(non_camel_case_types)]
fn host_functions() -> Vec<&'static dyn $crate::wasm_interface::Function> {
fn host_functions() -> Vec<&'static dyn $crate::sp_wasm_interface::Function> {
gen_functions!(
$context,
$( $name( $( $names: $params ),* ) $( -> $returns )? { $( $body )* } )*
@@ -23,14 +23,14 @@ use wasmi::{
};
use crate::error::{Error, WasmError};
use codec::{Encode, Decode};
use primitives::{sandbox as sandbox_primitives, traits::Externalities};
use sp_core::{sandbox as sandbox_primitives, traits::Externalities};
use crate::sandbox;
use crate::allocator;
use crate::wasm_utils::interpret_runtime_api_result;
use crate::wasm_runtime::WasmRuntime;
use log::{error, trace};
use parity_wasm::elements::{deserialize_buffer, DataSegment, Instruction, Module as RawModule};
use wasm_interface::{
use sp_wasm_interface::{
FunctionContext, Pointer, WordSize, Sandbox, MemoryId, Result as WResult, Function,
};
@@ -273,7 +273,7 @@ impl<'a> wasmi::ModuleImportResolver for Resolver<'a> {
fn resolve_func(&self, name: &str, signature: &wasmi::Signature)
-> std::result::Result<wasmi::FuncRef, wasmi::Error>
{
let signature = wasm_interface::Signature::from(signature);
let signature = sp_wasm_interface::Signature::from(signature);
for (function_index, function) in self.0.iter().enumerate() {
if name == function.name() {
if signature == function.signature() {
@@ -364,7 +364,7 @@ fn call_in_wasm_module(
let offset = fec.allocate_memory(data.len() as u32)?;
fec.write_memory(offset, data)?;
let result = externalities::set_and_run_with_externalities(
let result = sp_externalities::set_and_run_with_externalities(
ext,
|| module_instance.invoke_export(
method,
@@ -25,12 +25,12 @@ use codec::{Decode, Encode};
use cranelift_codegen::ir;
use cranelift_codegen::isa::TargetFrontendConfig;
use log::trace;
use primitives::sandbox as sandbox_primitives;
use sp_core::sandbox as sandbox_primitives;
use std::{cmp, mem, ptr};
use wasmtime_environ::translate_signature;
use wasmtime_jit::{ActionError, Compiler};
use wasmtime_runtime::{Export, VMCallerCheckedAnyfunc, VMContext, wasmtime_call_trampoline};
use wasm_interface::{
use sp_wasm_interface::{
FunctionContext, MemoryId, Pointer, Result as WResult, Sandbox, Signature, Value, ValueType,
WordSize,
};
@@ -33,7 +33,7 @@ use std::cell::RefCell;
use std::collections::HashMap;
use std::convert::TryFrom;
use std::rc::Rc;
use wasm_interface::{Pointer, WordSize, Function};
use sp_wasm_interface::{Pointer, WordSize, Function};
use wasmtime_environ::{Module, translate_signature};
use wasmtime_jit::{
ActionOutcome, ActionError, CodeMemory, CompilationStrategy, CompiledModule, Compiler, Context,
@@ -175,7 +175,7 @@ fn call_method(
let args = [RuntimeValue::I32(u32::from(data_ptr) as i32), RuntimeValue::I32(data_len as i32)];
// Invoke the function in the runtime.
let outcome = externalities::set_and_run_with_externalities(ext, || {
let outcome = sp_externalities::set_and_run_with_externalities(ext, || {
context
.invoke(&mut instance, method, &args[..])
.map_err(Error::Wasmtime)
@@ -26,7 +26,7 @@ use cranelift_codegen::print_errors::pretty_error;
use wasmtime_jit::{CodeMemory, Compiler};
use wasmtime_environ::CompiledFunction;
use wasmtime_runtime::{VMContext, VMFunctionBody};
use wasm_interface::{Function, Value, ValueType};
use sp_wasm_interface::{Function, Value, ValueType};
use std::{cmp, panic::{self, AssertUnwindSafe}, ptr};
use crate::error::{Error, WasmError};
@@ -18,7 +18,7 @@ use crate::error::{Error, Result};
use cranelift_codegen::{ir, isa};
use std::ops::Range;
use wasm_interface::{Pointer, Signature, ValueType};
use sp_wasm_interface::{Pointer, Signature, ValueType};
/// Read data from a slice of memory into a destination buffer.
///