Skip to content

Commit

Permalink
Fix parallel code execution in wasmtime (paritytech#6055)
Browse files Browse the repository at this point in the history
* Bump wasmtime version

* Proper test
  • Loading branch information
arkpar authored May 18, 2020
1 parent 05b7054 commit c17fce2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 27 additions & 13 deletions client/executor/src/integration_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,19 +626,33 @@ fn heap_is_reset_between_calls(wasm_method: WasmExecutionMethod) {
#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
fn parallel_execution(wasm_method: WasmExecutionMethod) {
let threads: Vec<_> = (0..8).map(|_| std::thread::spawn(move || {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
assert_eq!(
call_in_wasm(
"test_twox_128",
&[0],
wasm_method.clone(),
&mut ext,
).unwrap(),
hex!("99e9d85137db46ef4bbea33613baafd5").to_vec().encode(),
);
})).collect();
let executor = std::sync::Arc::new(crate::WasmExecutor::new(
wasm_method,
Some(1024),
HostFunctions::host_functions(),
8,
));
let code_hash = blake2_256(WASM_BINARY).to_vec();
let threads: Vec<_> = (0..8).map(|_|
{
let executor = executor.clone();
let code_hash = code_hash.clone();
std::thread::spawn(move || {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
assert_eq!(
executor.call_in_wasm(
&WASM_BINARY[..],
Some(code_hash.clone()),
"test_twox_128",
&[0],
&mut ext,
sp_core::traits::MissingHostFunctions::Allow,
).unwrap(),
hex!("99e9d85137db46ef4bbea33613baafd5").to_vec().encode(),
);
})
}).collect();

for t in threads.into_iter() {
t.join().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions client/executor/wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ sp-wasm-interface = { version = "2.0.0-dev", path = "../../../primitives/wasm-in
sp-runtime-interface = { version = "2.0.0-dev", path = "../../../primitives/runtime-interface" }
sp-core = { version = "2.0.0-dev", path = "../../../primitives/core" }
sp-allocator = { version = "2.0.0-dev", path = "../../../primitives/allocator" }
wasmtime = { package = "substrate-wasmtime", version = "0.16.0-threadsafe.2" }
wasmtime-runtime = { package = "substrate-wasmtime-runtime", version = "0.16.0-threadsafe.2" }
wasmtime = { package = "substrate-wasmtime", version = "0.16.0-threadsafe.3" }
wasmtime-runtime = { package = "substrate-wasmtime-runtime", version = "0.16.0-threadsafe.3" }
wasmtime-environ = "0.16"
cranelift-wasm = "0.63"
cranelift-codegen = "0.63"
Expand Down

0 comments on commit c17fce2

Please sign in to comment.