From fcdf65654e57e0cf7aa426623343ddef42721616 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Tue, 24 Oct 2023 16:03:49 +0200 Subject: [PATCH 1/4] fix types and deps --- executor/package.json | 2 +- package.json | 2 + .../wasm-executor/browser-wasm-executor.mjs | 9 +--- packages/core/src/wasm-executor/index.ts | 19 ++++--- .../src/wasm-executor/node-wasm-executor.mjs | 9 +--- packages/web-test/package.json | 12 ++--- yarn.lock | 52 +++++++++++-------- 7 files changed, 50 insertions(+), 55 deletions(-) diff --git a/executor/package.json b/executor/package.json index a3bc3bb6..00209dcf 100644 --- a/executor/package.json +++ b/executor/package.json @@ -12,10 +12,10 @@ "build": "wasm-pack build --target web --out-dir browser; wasm-pack build --target nodejs --out-dir node; scripts/pack-wasm.cjs" }, "dependencies": { + "@polkadot/util": "^12.5.1", "@polkadot/wasm-util": "^7.2.2" }, "devDependencies": { - "@polkadot/util": "^12.4.1", "fflate": "^0.8.0" }, "files": [ diff --git a/package.json b/package.json index 5901bb48..38ddbeb9 100644 --- a/package.json +++ b/package.json @@ -50,10 +50,12 @@ "eslint-plugin-sort-imports-es6-autofix": "^0.6.0", "husky": "^8.0.3", "prettier": "^3.0.2", + "punycode": "^1.4.1", "typedoc": "^0.25.1", "typedoc-plugin-markdown": "^3.16.0", "typescript": "^5.1.6", "unplugin-swc": "^1.4.2", + "url": "^0.11.0", "vite-tsconfig-paths": "^4.2.0", "vitepress": "^1.0.0-rc.23", "vitest": "^0.34.6", diff --git a/packages/core/src/wasm-executor/browser-wasm-executor.mjs b/packages/core/src/wasm-executor/browser-wasm-executor.mjs index b20adf72..15141998 100644 --- a/packages/core/src/wasm-executor/browser-wasm-executor.mjs +++ b/packages/core/src/wasm-executor/browser-wasm-executor.mjs @@ -14,17 +14,12 @@ const calculateStateRoot = async (entries, trie_version) => { const decodeProof = async (trieRootHash, keys, nodes) => { await pkg.wasmReady - const decoded = await pkg.decode_proof(trieRootHash, keys, nodes) - return decoded.reduce((accum, [key, value]) => { - accum[key] = value - return accum - }, {}) + return pkg.decode_proof(trieRootHash, keys, nodes) } const createProof = async (nodes, entries) => { await pkg.wasmReady - const result = await pkg.create_proof(nodes, entries) - return { trieRootHash: result[0], nodes: result[1] } + return pkg.create_proof(nodes, entries) } const runTask = async (task, callback) => { diff --git a/packages/core/src/wasm-executor/index.ts b/packages/core/src/wasm-executor/index.ts index 29f800ce..8b478cff 100644 --- a/packages/core/src/wasm-executor/index.ts +++ b/packages/core/src/wasm-executor/index.ts @@ -27,18 +27,12 @@ export type RuntimeVersion = { export interface WasmExecutor { getRuntimeVersion: (code: HexString) => Promise calculateStateRoot: (entries: [HexString, HexString][], trie_version: number) => Promise - createProof: ( - nodes: HexString[], - entries: [HexString, HexString | null][], - ) => Promise<{ - trieRootHash: `0x${string}` - nodes: `0x${string}`[] - }> + createProof: (nodes: HexString[], entries: [HexString, HexString | null][]) => Promise<[HexString, HexString[]]> decodeProof: ( trieRootHash: HexString, keys: HexString[], nodes: HexString[], - ) => Promise> + ) => Promise<[[HexString, HexString | null]]> runTask: ( task: { wasm: HexString @@ -84,12 +78,17 @@ export const calculateStateRoot = async ( export const decodeProof = async (trieRootHash: HexString, keys: HexString[], nodes: HexString[]) => { const worker = await getWorker() - return worker.remote.decodeProof(trieRootHash, keys, nodes) + const result = await worker.remote.decodeProof(trieRootHash, keys, nodes) + return result.reduce((accum, [key, value]) => { + accum[key] = value + return accum + }, {}) } export const createProof = async (nodes: HexString[], entries: [HexString, HexString | null][]) => { const worker = await getWorker() - return worker.remote.createProof(nodes, entries) + const [trieRootHash, newNodes] = await worker.remote.createProof(nodes, entries) + return { trieRootHash, nodes: newNodes } } export const runTask = async ( diff --git a/packages/core/src/wasm-executor/node-wasm-executor.mjs b/packages/core/src/wasm-executor/node-wasm-executor.mjs index 0d368385..1db95675 100644 --- a/packages/core/src/wasm-executor/node-wasm-executor.mjs +++ b/packages/core/src/wasm-executor/node-wasm-executor.mjs @@ -13,16 +13,11 @@ const calculateStateRoot = async (entries, trie_version) => { } const decodeProof = async (trieRootHash, keys, nodes) => { - const decoded = await pkg.decode_proof(trieRootHash, keys, nodes) - return decoded.reduce((accum, [key, value]) => { - accum[key] = value - return accum - }, {}) + return pkg.decode_proof(trieRootHash, keys, nodes) } const createProof = async (nodes, entries) => { - const result = await pkg.create_proof(nodes, entries) - return { trieRootHash: result[0], nodes: result[1] } + return pkg.create_proof(nodes, entries) } const runTask = async (task, callback) => { diff --git a/packages/web-test/package.json b/packages/web-test/package.json index c3d3dcb1..5de6e5c7 100644 --- a/packages/web-test/package.json +++ b/packages/web-test/package.json @@ -7,27 +7,23 @@ "build": "npx vite build", "vite:serve": "npx vite --port 3000 --host", "vite:preview": "npx vite preview --port 3000", - "parcel:serve": "parcel serve index.html --port 3000", + "parcel:serve": "npx parcel serve index.html --port 3000", "test": "playwright test" }, - "dependencies": { + "devDependencies": { "@acala-network/chopsticks-core": "workspace:*", "@acala-network/chopsticks-db": "workspace:*", "@emotion/react": "^11.11.1", "@emotion/styled": "^11.11.0", "@mui/material": "^5.14.11", - "react": "^18.2.0", - "react-dom": "^18.2.0" - }, - "devDependencies": { "@playwright/test": "^1.37.1", "@types/react": "^18", "@types/react-dom": "^18", "@vitejs/plugin-react": "^4.1.0", "crypto-browserify": "^3.12.0", - "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-react-refresh": "^0.4.3", "path-browserify": "^1.0.1", + "react": "^18.2.0", + "react-dom": "^18.2.0", "stream-browserify": "^3.0.0", "typescript": "^5.1.6" } diff --git a/yarn.lock b/yarn.lock index 3bd59e3a..81049ddb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -62,7 +62,7 @@ __metadata: version: 0.0.0-use.local resolution: "@acala-network/chopsticks-executor@workspace:executor" dependencies: - "@polkadot/util": ^12.4.1 + "@polkadot/util": ^12.5.1 "@polkadot/wasm-util": ^7.2.2 fflate: ^0.8.0 languageName: unknown @@ -124,8 +124,6 @@ __metadata: "@types/react-dom": ^18 "@vitejs/plugin-react": ^4.1.0 crypto-browserify: ^3.12.0 - eslint-plugin-react-hooks: ^4.6.0 - eslint-plugin-react-refresh: ^0.4.3 path-browserify: ^1.0.1 react: ^18.2.0 react-dom: ^18.2.0 @@ -1815,7 +1813,7 @@ __metadata: languageName: node linkType: hard -"@polkadot/util@npm:12.5.1, @polkadot/util@npm:^12.4.1, @polkadot/util@npm:^12.5.1": +"@polkadot/util@npm:12.5.1, @polkadot/util@npm:^12.5.1": version: 12.5.1 resolution: "@polkadot/util@npm:12.5.1" dependencies: @@ -3637,10 +3635,12 @@ __metadata: eslint-plugin-sort-imports-es6-autofix: ^0.6.0 husky: ^8.0.3 prettier: ^3.0.2 + punycode: ^1.4.1 typedoc: ^0.25.1 typedoc-plugin-markdown: ^3.16.0 typescript: ^5.1.6 unplugin-swc: ^1.4.2 + url: ^0.11.0 vite-tsconfig-paths: ^4.2.0 vitepress: ^1.0.0-rc.23 vitest: ^0.34.6 @@ -4539,24 +4539,6 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-react-hooks@npm:^4.6.0": - version: 4.6.0 - resolution: "eslint-plugin-react-hooks@npm:4.6.0" - peerDependencies: - eslint: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 - checksum: 23001801f14c1d16bf0a837ca7970d9dd94e7b560384b41db378b49b6e32dc43d6e2790de1bd737a652a86f81a08d6a91f402525061b47719328f586a57e86c3 - languageName: node - linkType: hard - -"eslint-plugin-react-refresh@npm:^0.4.3": - version: 0.4.3 - resolution: "eslint-plugin-react-refresh@npm:0.4.3" - peerDependencies: - eslint: ">=7" - checksum: 0332c950bb46c3058fd06acb1dbdc3ea0af05238645f4c0f575e0e367440dc56afb928f855833d321b9e8109e08c63d5f476cc55d507f883a80c289bfcd509cb - languageName: node - linkType: hard - "eslint-plugin-sort-imports-es6-autofix@npm:^0.6.0": version: 0.6.0 resolution: "eslint-plugin-sort-imports-es6-autofix@npm:0.6.0" @@ -7033,6 +7015,13 @@ __metadata: languageName: node linkType: hard +"punycode@npm:^1.4.1": + version: 1.4.1 + resolution: "punycode@npm:1.4.1" + checksum: fa6e698cb53db45e4628559e557ddaf554103d2a96a1d62892c8f4032cd3bc8871796cae9eabc1bc700e2b6677611521ce5bb1d9a27700086039965d0cf34518 + languageName: node + linkType: hard + "punycode@npm:^2.1.0": version: 2.3.0 resolution: "punycode@npm:2.3.0" @@ -7040,6 +7029,15 @@ __metadata: languageName: node linkType: hard +"qs@npm:^6.11.2": + version: 6.11.2 + resolution: "qs@npm:6.11.2" + dependencies: + side-channel: ^1.0.4 + checksum: e812f3c590b2262548647d62f1637b6989cc56656dc960b893fe2098d96e1bd633f36576f4cd7564dfbff9db42e17775884db96d846bebe4f37420d073ecdc0b + languageName: node + linkType: hard + "queue-microtask@npm:^1.2.2": version: 1.2.3 resolution: "queue-microtask@npm:1.2.3" @@ -8461,6 +8459,16 @@ __metadata: languageName: node linkType: hard +"url@npm:^0.11.0": + version: 0.11.3 + resolution: "url@npm:0.11.3" + dependencies: + punycode: ^1.4.1 + qs: ^6.11.2 + checksum: f9e7886f46a16f96d2e42fbcc5d682c231c55ef5442c1ff66150c0f6556f6e3a97d094a84f51be15ec2432711d212eb60426659ce418f5fcadeaa3f601532c4e + languageName: node + linkType: hard + "util-deprecate@npm:^1.0.1": version: 1.0.2 resolution: "util-deprecate@npm:1.0.2" From b1c52a191197d2407471a7fbc80ef49f7ad9421e Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Tue, 24 Oct 2023 16:05:08 +0200 Subject: [PATCH 2/4] fix --- package.json | 2 -- yarn.lock | 28 ---------------------------- 2 files changed, 30 deletions(-) diff --git a/package.json b/package.json index 38ddbeb9..5901bb48 100644 --- a/package.json +++ b/package.json @@ -50,12 +50,10 @@ "eslint-plugin-sort-imports-es6-autofix": "^0.6.0", "husky": "^8.0.3", "prettier": "^3.0.2", - "punycode": "^1.4.1", "typedoc": "^0.25.1", "typedoc-plugin-markdown": "^3.16.0", "typescript": "^5.1.6", "unplugin-swc": "^1.4.2", - "url": "^0.11.0", "vite-tsconfig-paths": "^4.2.0", "vitepress": "^1.0.0-rc.23", "vitest": "^0.34.6", diff --git a/yarn.lock b/yarn.lock index 81049ddb..a67d2b6a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3635,12 +3635,10 @@ __metadata: eslint-plugin-sort-imports-es6-autofix: ^0.6.0 husky: ^8.0.3 prettier: ^3.0.2 - punycode: ^1.4.1 typedoc: ^0.25.1 typedoc-plugin-markdown: ^3.16.0 typescript: ^5.1.6 unplugin-swc: ^1.4.2 - url: ^0.11.0 vite-tsconfig-paths: ^4.2.0 vitepress: ^1.0.0-rc.23 vitest: ^0.34.6 @@ -7015,13 +7013,6 @@ __metadata: languageName: node linkType: hard -"punycode@npm:^1.4.1": - version: 1.4.1 - resolution: "punycode@npm:1.4.1" - checksum: fa6e698cb53db45e4628559e557ddaf554103d2a96a1d62892c8f4032cd3bc8871796cae9eabc1bc700e2b6677611521ce5bb1d9a27700086039965d0cf34518 - languageName: node - linkType: hard - "punycode@npm:^2.1.0": version: 2.3.0 resolution: "punycode@npm:2.3.0" @@ -7029,15 +7020,6 @@ __metadata: languageName: node linkType: hard -"qs@npm:^6.11.2": - version: 6.11.2 - resolution: "qs@npm:6.11.2" - dependencies: - side-channel: ^1.0.4 - checksum: e812f3c590b2262548647d62f1637b6989cc56656dc960b893fe2098d96e1bd633f36576f4cd7564dfbff9db42e17775884db96d846bebe4f37420d073ecdc0b - languageName: node - linkType: hard - "queue-microtask@npm:^1.2.2": version: 1.2.3 resolution: "queue-microtask@npm:1.2.3" @@ -8459,16 +8441,6 @@ __metadata: languageName: node linkType: hard -"url@npm:^0.11.0": - version: 0.11.3 - resolution: "url@npm:0.11.3" - dependencies: - punycode: ^1.4.1 - qs: ^6.11.2 - checksum: f9e7886f46a16f96d2e42fbcc5d682c231c55ef5442c1ff66150c0f6556f6e3a97d094a84f51be15ec2432711d212eb60426659ce418f5fcadeaa3f601532c4e - languageName: node - linkType: hard - "util-deprecate@npm:^1.0.1": version: 1.0.2 resolution: "util-deprecate@npm:1.0.2" From a235ee0f0270f6b6f74df5a3bba9322ee43bd242 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Tue, 24 Oct 2023 16:19:30 +0200 Subject: [PATCH 3/4] fix --- packages/db/package.json | 2 ++ yarn.lock | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/db/package.json b/packages/db/package.json index 538a5806..1ee6e6c2 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -10,6 +10,8 @@ }, "dependencies": { "@acala-network/chopsticks-core": "workspace:*", + "@polkadot/util": "^12.5.1", + "@polkadot/wasm-util": "^7.2.2", "localforage": "^1.10.0", "sql.js": "^1.8.0", "sqlite3": "^5.1.6", diff --git a/yarn.lock b/yarn.lock index a67d2b6a..e0c22b0c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -36,6 +36,8 @@ __metadata: resolution: "@acala-network/chopsticks-db@workspace:packages/db" dependencies: "@acala-network/chopsticks-core": "workspace:*" + "@polkadot/util": ^12.5.1 + "@polkadot/wasm-util": ^7.2.2 "@types/sql.js": ^1.4.4 fflate: ^0.8.0 localforage: ^1.10.0 From 568126c67f4bf1b3239a8854271580be247bfcb2 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Tue, 24 Oct 2023 16:22:14 +0200 Subject: [PATCH 4/4] fix import --- packages/db/src/db/entities.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/db/src/db/entities.ts b/packages/db/src/db/entities.ts index 26d81fe1..dec79762 100644 --- a/packages/db/src/db/entities.ts +++ b/packages/db/src/db/entities.ts @@ -1,4 +1,4 @@ -import { BlockEntry, KeyValueEntry } from '@acala-network/chopsticks-core/src/database' +import { BlockEntry, KeyValueEntry } from '@acala-network/chopsticks-core' import { EntitySchema } from 'typeorm' export const KeyValuePair = new EntitySchema({