Skip to content

Commit

Permalink
fix unwrap crash (#803)
Browse files Browse the repository at this point in the history
* fix unwrap

* fix

* update version
  • Loading branch information
qiweiii committed Aug 15, 2024
1 parent 8391fc8 commit b9ad5d2
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion executor/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub async fn get_runtime_version(code: JsValue) -> Result<JsValue, JsError> {
setup_console(None);

let code = serde_wasm_bindgen::from_value::<HexString>(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)
Expand Down
19 changes: 10 additions & 9 deletions executor/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,16 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result<TaskRespo
let mut storage_changes: BTreeMap<Vec<u8>, Option<Vec<u8>>> = Default::default();
let mut offchain_storage_changes: BTreeMap<Vec<u8>, Option<Vec<u8>>> = 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<Vec<u8>, String> = Ok(Vec::new());
let mut runtime_logs: Vec<LogInfo> = vec![];

Expand Down Expand Up @@ -208,9 +211,7 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result<TaskRespo
}
}

RuntimeCall::ClosestDescendantMerkleValue(req) => {
req.resume_unknown()
}
RuntimeCall::ClosestDescendantMerkleValue(req) => req.resume_unknown(),

RuntimeCall::NextKey(req) => {
if req.branch_nodes() {
Expand Down Expand Up @@ -415,18 +416,18 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result<TaskRespo
}))
}

pub async fn runtime_version(wasm: HexString) -> RuntimeVersion {
pub async fn runtime_version(wasm: HexString) -> Result<RuntimeVersion, JsError> {
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(
Expand Down
2 changes: 1 addition & 1 deletion packages/chopsticks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acala-network/chopsticks",
"version": "0.13.2",
"version": "0.13.3",
"author": "Acala Developers <hello@acala.network>",
"license": "Apache-2.0",
"bin": "./chopsticks.cjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/chopsticks/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acala-network/chopsticks-core",
"version": "0.13.2",
"version": "0.13.3",
"author": "Acala Developers <hello@acala.network>",
"license": "Apache-2.0",
"type": "module",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/wasm-executor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acala-network/chopsticks-db",
"version": "0.13.2",
"version": "0.13.3",
"author": "Acala Developers <hello@acala.network>",
"license": "Apache-2.0",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acala-network/chopsticks-testing",
"version": "0.13.2",
"version": "0.13.3",
"author": "Acala Developers <hello@acala.network>",
"license": "Apache-2.0",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acala-network/chopsticks-utils",
"version": "0.13.2",
"version": "0.13.3",
"author": "Acala Developers <hello@acala.network>",
"license": "Apache-2.0",
"type": "module",
Expand Down

0 comments on commit b9ad5d2

Please sign in to comment.