Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e10bddd
WIP
cecton Jan 6, 2020
86b6bc5
WIP
cecton Jan 6, 2020
2e61dca
WIP
cecton Jan 6, 2020
ce243f4
WIP
cecton Jan 7, 2020
e19948e
WIP
cecton Jan 7, 2020
cdd65ee
WIP
cecton Jan 7, 2020
935f976
Update client/executor/src/integration_tests/mod.rs
cecton Jan 7, 2020
9ec344c
Update client/executor/src/integration_tests/mod.rs
cecton Jan 7, 2020
5f86a84
WIP
cecton Jan 7, 2020
335038b
WIP
cecton Jan 7, 2020
2333994
WIP
cecton Jan 7, 2020
0ef2746
WIP
cecton Jan 7, 2020
1374979
Use resolver approach
pepyakin Jan 6, 2020
79f4a2a
wasmtime
cecton Jan 7, 2020
997bb60
Revert "wasmtime"
cecton Jan 8, 2020
f7109d1
Revert "Use resolver approach"
cecton Jan 8, 2020
c2f0e0d
WIP
cecton Jan 8, 2020
797bfb6
WIP
cecton Jan 8, 2020
d889cf7
WIP
cecton Jan 8, 2020
cfd9b3b
WIP
cecton Jan 8, 2020
b4b42d9
WIP
cecton Jan 8, 2020
c67be22
Merge remote-tracking branch 'origin/master' into cecton-issue-4456
cecton Jan 8, 2020
0e926a8
Update client/executor/wasmi/src/lib.rs
cecton Jan 8, 2020
4c80f58
WIP
cecton Jan 8, 2020
36d8be2
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
6786bf8
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
623787f
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
000116e
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
131b7d4
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
0b67996
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
2cb0469
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
a5633f3
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
cd81107
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
cc1a4a8
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
7289892
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
77fcaa5
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
3785028
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
e78e4aa
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
63dc3ce
Update client/executor/wasmi/src/lib.rs
cecton Jan 9, 2020
04a3db6
WIP
cecton Jan 9, 2020
cc844f5
Apply suggestions from code review
bkchr Jan 9, 2020
199a60e
WIP
cecton Jan 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions client/executor/runtime-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,23 @@ use sp_runtime::{print, traits::{BlakeTwo256, Hash}};
#[cfg(not(feature = "std"))]
use sp_core::{ed25519, sr25519};

extern "C" {
#[allow(dead_code)]
fn missing_external();

#[allow(dead_code)]
fn yet_another_missing_external();
}

sp_core::wasm_export_functions! {
fn test_calling_missing_external() {
unsafe { missing_external() }
}

fn test_calling_yet_another_missing_external() {
unsafe { yet_another_missing_external() }
}

fn test_data_in(input: Vec<u8>) -> Vec<u8> {
print("set_storage");
storage::set(b"input", &input);
Expand Down
84 changes: 83 additions & 1 deletion client/executor/src/integration_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,49 @@ use crate::WasmExecutionMethod;

pub type TestExternalities = CoreTestExternalities<Blake2Hasher, u64>;

#[cfg(feature = "wasmtime")]
mod wasmtime_missing_externals {
use sp_wasm_interface::{Function, FunctionContext, HostFunctions, Result, Signature, Value};

pub struct WasmtimeHostFunctions;

impl HostFunctions for WasmtimeHostFunctions {
fn host_functions() -> Vec<&'static dyn Function> {
vec![MISSING_EXTERNAL_FUNCTION, YET_ANOTHER_MISSING_EXTERNAL_FUNCTION]
}
}

struct MissingExternalFunction(&'static str);

impl Function for MissingExternalFunction {
fn name(&self) -> &str { self.0 }

fn signature(&self) -> Signature {
Signature::new(vec![], None)
}

fn execute(
&self,
_context: &mut dyn FunctionContext,
_args: &mut dyn Iterator<Item = Value>,
) -> Result<Option<Value>> {
panic!("should not be called");
}
}

static MISSING_EXTERNAL_FUNCTION: &'static MissingExternalFunction =
&MissingExternalFunction("missing_external");
static YET_ANOTHER_MISSING_EXTERNAL_FUNCTION: &'static MissingExternalFunction =
&MissingExternalFunction("yet_another_missing_external");
}

#[cfg(feature = "wasmtime")]
type HostFunctions =
(wasmtime_missing_externals::WasmtimeHostFunctions, sp_io::SubstrateHostFunctions);

#[cfg(not(feature = "wasmtime"))]
type HostFunctions = sp_io::SubstrateHostFunctions;

fn call_in_wasm<E: Externalities>(
function: &str,
call_data: &[u8],
Expand All @@ -40,13 +83,14 @@ fn call_in_wasm<E: Externalities>(
code: &[u8],
heap_pages: u64,
) -> crate::error::Result<Vec<u8>> {
crate::call_in_wasm::<E, sp_io::SubstrateHostFunctions>(
crate::call_in_wasm::<E, HostFunctions>(
Comment thread
bkchr marked this conversation as resolved.
function,
call_data,
execution_method,
ext,
code,
heap_pages,
true,
)
}

Expand All @@ -68,6 +112,44 @@ fn returning_should_work(wasm_method: WasmExecutionMethod) {
assert_eq!(output, vec![0u8; 0]);
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
#[should_panic(expected = "function missing_external does not exist")]
#[cfg(not(feature = "wasmtime"))]
fn call_not_existing_function(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
let test_code = WASM_BINARY;

call_in_wasm(
"test_calling_missing_external",
&[],
wasm_method,
&mut ext,
&test_code[..],
8,
).unwrap();
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
#[should_panic(expected = "function yet_another_missing_external does not exist")]
#[cfg(not(feature = "wasmtime"))]
fn call_yet_another_not_existing_function(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
let test_code = WASM_BINARY;

call_in_wasm(
"test_calling_yet_another_missing_external",
&[],
wasm_method,
&mut ext,
&test_code[..],
8,
).unwrap();
}

#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
fn panicking_should_work(wasm_method: WasmExecutionMethod) {
Expand Down
3 changes: 3 additions & 0 deletions client/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ pub fn call_in_wasm<E: Externalities, HF: sp_wasm_interface::HostFunctions>(
ext: &mut E,
code: &[u8],
heap_pages: u64,
allow_missing_imports: bool,
) -> error::Result<Vec<u8>> {
let mut instance = wasm_runtime::create_wasm_runtime_with_code(
execution_method,
heap_pages,
code,
HF::host_functions(),
allow_missing_imports,
)?;
instance.call(ext, function, call_data)
}
Expand Down Expand Up @@ -103,6 +105,7 @@ mod tests {
&mut ext,
&WASM_BINARY,
8,
true,
).unwrap();
assert_eq!(res, vec![0u8; 0]);
}
Expand Down
5 changes: 3 additions & 2 deletions client/executor/src/wasm_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ pub fn create_wasm_runtime_with_code(
heap_pages: u64,
code: &[u8],
host_functions: Vec<&'static dyn Function>,
allow_missing_imports: bool,
) -> Result<Box<dyn WasmRuntime>, WasmError> {
match wasm_method {
WasmExecutionMethod::Interpreted =>
sc_executor_wasmi::create_instance(code, heap_pages, host_functions)
sc_executor_wasmi::create_instance(code, heap_pages, host_functions, allow_missing_imports)
.map(|runtime| -> Box<dyn WasmRuntime> { Box::new(runtime) }),
#[cfg(feature = "wasmtime")]
WasmExecutionMethod::Compiled =>
Expand All @@ -212,7 +213,7 @@ fn create_versioned_wasm_runtime<E: Externalities>(
let code = ext
.original_storage(well_known_keys::CODE)
.ok_or(WasmError::CodeNotFound)?;
let mut runtime = create_wasm_runtime_with_code(wasm_method, heap_pages, &code, host_functions)?;
let mut runtime = create_wasm_runtime_with_code(wasm_method, heap_pages, &code, host_functions, false)?;

// Call to determine runtime version.
let version_result = {
Expand Down
Loading