diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index 3d04d5cc01547..c8b763a6b1936 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -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")); } diff --git a/client/executor/src/native_executor.rs b/client/executor/src/native_executor.rs index 3cdc34939b38d..f05b49a5246c7 100644 --- a/client/executor/src/native_executor.rs +++ b/client/executor/src/native_executor.rs @@ -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 }, @@ -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); + }, } })); @@ -403,13 +409,16 @@ impl RuntimeInstanceSpawn { .map(move |task_ext| Self::new(module, task_ext.clone())) } - fn register_on_externalities(module: Arc) { + /// Register new `RuntimeSpawnExt` on current externalities. + /// + /// This extensions will spawn instances from provided `module`. + pub fn register_on_externalities(module: Arc) { 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::( + if let Err(e) = ext.register_extension( RuntimeSpawnExt(Box::new(runtime_spawn)) ) { trace!( diff --git a/client/executor/wasmtime/src/instance_wrapper.rs b/client/executor/wasmtime/src/instance_wrapper.rs index c93063f7692be..14493266d9e43 100644 --- a/client/executor/wasmtime/src/instance_wrapper.rs +++ b/client/executor/wasmtime/src/instance_wrapper.rs @@ -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 { @@ -121,7 +125,7 @@ impl EntryPoint { Ok(Self { func, call_type: EntryPointType::Direct }) } _ => { - Err("Invalid signature") + Err("Invalid signature for direct entry point") } } } @@ -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") } } } diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index c3b10a8592e75..44b748942da56 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -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) -> u64 { let runtime_spawn = self.extension::() .expect("Cannot spawn without dynamic runtime dispatcher (RuntimeSpawnExt)"); @@ -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 { let runtime_spawn = self.extension::() .expect("Cannot spawn without dynamic runtime dispatcher (RuntimeSpawnExt)");