Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
address more issues
Browse files Browse the repository at this point in the history
  • Loading branch information
NikVolf committed Oct 19, 2020
1 parent 5b10f4b commit b9b9772
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion client/executor/src/integration_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,5 +766,5 @@ fn panic_in_spawned_instance_panics_on_joining_its_result(wasm_method: WasmExecu
).unwrap_err();

dbg!(&error_result);
assert!(format!("{}", error_result).contains("Spawned task panicked"));
assert!(format!("{}", error_result).contains("Spawned task"));
}
23 changes: 16 additions & 7 deletions client/executor/src/native_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ impl sp_io::RuntimeSpawn for RuntimeInstanceSpawn {
// pool of instances should be used.
//
// https://github.com/paritytech/substrate/issues/7354
let instance = module.new_instance().expect("Failed to create new instance");
let instance = module.new_instance()
.expect("Failed to create new instance from module");

instance.call(
InvokeMethod::TableWithWrapper { dispatcher_ref, func },
Expand All @@ -364,10 +365,15 @@ impl sp_io::RuntimeSpawn for RuntimeInstanceSpawn {
}
);

// If execution is panicked, the `join` in the original runtime code will panic as well,
// since the sender is dropped without sending anything.
if let Ok(output) = result {
let _ = sender.send(output);
match result {
Ok(output) => {
let _ = sender.send(output);
},
Err(error) => {
// If execution is panicked, the `join` in the original runtime code will panic as well,
// since the sender is dropped without sending anything.
log::error!("Call error in spawned task: {:?}", error);
},
}
}));

Expand Down Expand Up @@ -403,13 +409,16 @@ impl RuntimeInstanceSpawn {
.map(move |task_ext| Self::new(module, task_ext.clone()))
}

fn register_on_externalities(module: Arc<dyn WasmModule>) {
/// Register new `RuntimeSpawnExt` on current externalities.
///
/// This extensions will spawn instances from provided `module`.
pub fn register_on_externalities(module: Arc<dyn WasmModule>) {
sp_externalities::with_externalities(
move |mut ext| {
if let Some(runtime_spawn) =
Self::with_externalities_and_module(module.clone(), ext)
{
if let Err(e) = ext.register_extension::<RuntimeSpawnExt>(
if let Err(e) = ext.register_extension(
RuntimeSpawnExt(Box::new(runtime_spawn))
) {
trace!(
Expand Down
10 changes: 7 additions & 3 deletions client/executor/wasmtime/src/instance_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ impl EntryPoint {
wasmtime::Val::I32(data_len),
])
},
}).map(|results| results[0].unwrap_i64() as u64)
})
.map(|results|
// the signature is checked to have i64 return type
results[0].unwrap_i64() as u64
)
}

pub fn direct(func: wasmtime::Func) -> std::result::Result<Self, &'static str> {
Expand All @@ -121,7 +125,7 @@ impl EntryPoint {
Ok(Self { func, call_type: EntryPointType::Direct })
}
_ => {
Err("Invalid signature")
Err("Invalid signature for direct entry point")
}
}
}
Expand All @@ -135,7 +139,7 @@ impl EntryPoint {
Ok(Self { func: dispatcher, call_type: EntryPointType::Wrapped(func) })
},
_ => {
Err("Invalid signature")
Err("Invalid signature for wrapped entry point")
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions primitives/io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,7 @@ trait RuntimeTasks {
/// Wasm host function for spawning task.
///
/// This should not be used directly. Use `sp_io::tasks::spawn` instead.
#[cfg_attr(feature = "std", allow(dead_code))]
fn spawn(&mut self, dispatcher_ref: u32, entry: u32, payload: Vec<u8>) -> u64 {
let runtime_spawn = self.extension::<RuntimeSpawnExt>()
.expect("Cannot spawn without dynamic runtime dispatcher (RuntimeSpawnExt)");
Expand All @@ -1282,6 +1283,7 @@ trait RuntimeTasks {
/// Wasm host function for joining a task.
///
/// This should not be used directly. Use `join` of `sp_io::tasks::spawn` result instead.
#[cfg_attr(feature = "std", allow(dead_code))]
fn join(&mut self, handle: u64) -> Vec<u8> {
let runtime_spawn = self.extension::<RuntimeSpawnExt>()
.expect("Cannot spawn without dynamic runtime dispatcher (RuntimeSpawnExt)");
Expand Down

0 comments on commit b9b9772

Please sign in to comment.