From b9ad5d26bc4dcbf302718a79b308624b6d3ed640 Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Thu, 15 Aug 2024 15:56:21 +0800 Subject: [PATCH] fix unwrap crash (#803) * fix unwrap * fix * update version --- executor/package.json | 2 +- executor/src/lib.rs | 2 +- executor/src/task.rs | 19 ++++++++++--------- packages/chopsticks/package.json | 2 +- packages/chopsticks/src/server.ts | 2 +- packages/core/package.json | 2 +- packages/core/src/wasm-executor/index.ts | 1 + packages/db/package.json | 2 +- packages/testing/package.json | 2 +- packages/utils/package.json | 2 +- 10 files changed, 19 insertions(+), 17 deletions(-) diff --git a/executor/package.json b/executor/package.json index ac935c07..a59edbd1 100644 --- a/executor/package.json +++ b/executor/package.json @@ -1,7 +1,7 @@ { "name": "@acala-network/chopsticks-executor", "description": "Chopsticks executor", - "version": "0.13.2", + "version": "0.13.3", "license": "Apache-2.0", "type": "module", "repository": { diff --git a/executor/src/lib.rs b/executor/src/lib.rs index 6cbd183a..7988a783 100644 --- a/executor/src/lib.rs +++ b/executor/src/lib.rs @@ -103,7 +103,7 @@ pub async fn get_runtime_version(code: JsValue) -> Result { setup_console(None); let code = serde_wasm_bindgen::from_value::(code)?; - let runtime_version = task::runtime_version(code).await; + let runtime_version = task::runtime_version(code).await?; let result = serde_wasm_bindgen::to_value(&runtime_version)?; Ok(result) diff --git a/executor/src/task.rs b/executor/src/task.rs index 19318226..edc779f1 100644 --- a/executor/src/task.rs +++ b/executor/src/task.rs @@ -138,13 +138,16 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result, Option>> = Default::default(); let mut offchain_storage_changes: BTreeMap, Option>> = Default::default(); - let vm_proto = HostVmPrototype::new(Config { + let vm_proto = match HostVmPrototype::new(Config { module: &task.wasm, heap_pages: HeapPages::from(2048), exec_hint: smoldot::executor::vm::ExecHint::ValidateAndExecuteOnce, allow_unresolved_imports: task.allow_unresolved_imports, - }) - .unwrap(); + }) { + Ok(vm_proto) => vm_proto, + Err(e) => return Ok(TaskResponse::Error(e.to_string())), + }; + let mut ret: Result, String> = Ok(Vec::new()); let mut runtime_logs: Vec = vec![]; @@ -208,9 +211,7 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result { - req.resume_unknown() - } + RuntimeCall::ClosestDescendantMerkleValue(req) => req.resume_unknown(), RuntimeCall::NextKey(req) => { if req.branch_nodes() { @@ -415,18 +416,18 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result RuntimeVersion { +pub async fn runtime_version(wasm: HexString) -> Result { let vm_proto = HostVmPrototype::new(Config { module: &wasm, heap_pages: HeapPages::from(2048), exec_hint: smoldot::executor::vm::ExecHint::ValidateAndExecuteOnce, allow_unresolved_imports: true, }) - .unwrap(); + .map_err(|e| JsError::new(&e.to_string()))?; let core_version = vm_proto.runtime_version().decode(); - RuntimeVersion::new(core_version) + Ok(RuntimeVersion::new(core_version)) } pub fn calculate_state_root( diff --git a/packages/chopsticks/package.json b/packages/chopsticks/package.json index 5f264ac0..4c2dc6f4 100644 --- a/packages/chopsticks/package.json +++ b/packages/chopsticks/package.json @@ -1,6 +1,6 @@ { "name": "@acala-network/chopsticks", - "version": "0.13.2", + "version": "0.13.3", "author": "Acala Developers ", "license": "Apache-2.0", "bin": "./chopsticks.cjs", diff --git a/packages/chopsticks/src/server.ts b/packages/chopsticks/src/server.ts index 17159118..f57e49bc 100644 --- a/packages/chopsticks/src/server.ts +++ b/packages/chopsticks/src/server.ts @@ -224,7 +224,7 @@ export const createServer = async (handler: Handler, port: number) => { result: resp ?? null, } } catch (e) { - wsLogger.info('Error handling request: %o', (e as Error).stack) + wsLogger.error('Error handling request: %o', (e as Error).stack) return { id: req.id, jsonrpc: '2.0', diff --git a/packages/core/package.json b/packages/core/package.json index 6e339b98..91f8c51a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@acala-network/chopsticks-core", - "version": "0.13.2", + "version": "0.13.3", "author": "Acala Developers ", "license": "Apache-2.0", "type": "module", diff --git a/packages/core/src/wasm-executor/index.ts b/packages/core/src/wasm-executor/index.ts index 792c3671..e46034a1 100644 --- a/packages/core/src/wasm-executor/index.ts +++ b/packages/core/src/wasm-executor/index.ts @@ -129,6 +129,7 @@ export const runTask = async (task: TaskCall, callback: JsCallback = emptyTaskHa } const worker = await getWorker() logger.trace(truncate(task2), 'taskRun') + const response = await worker.remote.runTask(task2, Comlink.proxy(callback)) if ('Call' in response) { logger.trace(truncate(response.Call), 'taskResponse') diff --git a/packages/db/package.json b/packages/db/package.json index a6814cf9..dc16f35b 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -1,6 +1,6 @@ { "name": "@acala-network/chopsticks-db", - "version": "0.13.2", + "version": "0.13.3", "author": "Acala Developers ", "license": "Apache-2.0", "type": "module", diff --git a/packages/testing/package.json b/packages/testing/package.json index cfcecfde..c0d69e18 100644 --- a/packages/testing/package.json +++ b/packages/testing/package.json @@ -1,6 +1,6 @@ { "name": "@acala-network/chopsticks-testing", - "version": "0.13.2", + "version": "0.13.3", "author": "Acala Developers ", "license": "Apache-2.0", "type": "module", diff --git a/packages/utils/package.json b/packages/utils/package.json index 2ac915d2..aa2d1c86 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@acala-network/chopsticks-utils", - "version": "0.13.2", + "version": "0.13.3", "author": "Acala Developers ", "license": "Apache-2.0", "type": "module",