Skip to content

Commit

Permalink
executor dual pkg (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci authored Nov 12, 2023
1 parent 9d05cd4 commit 1b1e86b
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 20 deletions.
2 changes: 1 addition & 1 deletion executor/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion executor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chopsticks-executor"
version = "0.9.2-4"
version = "0.9.2-5"
description = "Chopsticks executor"
repository = "https://github.com/AcalaNetwork/chopsticks"
license = "Apache-2.0"
Expand Down
35 changes: 25 additions & 10 deletions executor/package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
{
"name": "@acala-network/chopsticks-executor",
"description": "Chopsticks executor",
"version": "0.9.2-4",
"version": "0.9.2-5",
"license": "Apache-2.0",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/AcalaNetwork/chopsticks"
},
"scripts": {
"clean": "rm -rf browser node",
"build": "wasm-pack build --target web --out-dir browser; wasm-pack build --target nodejs --out-dir node; scripts/pack-wasm.cjs"
"clean": "rm -rf pkg dist",
"wasm": "yarn clean && wasm-pack build --target web --out-dir pkg && scripts/pack-wasm.cjs",
"build": "yarn wasm && yarn build:cjs && yarn build:esm",
"build:cjs": "swc ./pkg -C module.type=commonjs -d dist/cjs --copy-files && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
"build:esm": "swc ./pkg -C module.type=es6 -d dist/esm --copy-files && echo '{\"type\": \"module\"}' > dist/esm/package.json"
},
"dependencies": {
"@polkadot/util": "^12.5.1",
"@polkadot/wasm-util": "^7.2.2"
},
"devDependencies": {
"@swc/cli": "0.1.62",
"@swc/core": "^1.3.96",
"fflate": "^0.8.1"
},
"files": [
"browser/index.js",
"browser/chopsticks_executor.js",
"browser/chopsticks_executor_bg.wasm",
"node/chopsticks_*"
"dist/esm/**",
"dist/cjs/**",
"pkg/chopsticks_executor.d.ts"
],
"main": "node/chopsticks_executor.js",
"types": "node/chopsticks_executor.d.ts",
"browser": "browser/index.js"
"require": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./pkg/chopsticks_executor.d.ts",
"exports": {
".": {
"require": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"default": "./dist/esm/index.js",
"types": "./pkg/chopsticks_executor.d.ts"
},
"./package.json": "./package.json",
"./package.cjs.json": "./dist/cjs/package.json"
}
}
6 changes: 3 additions & 3 deletions executor/scripts/pack-wasm.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const path = require('node:path');
const { zlibSync } = require('fflate/node');
const { formatNumber } = require('@polkadot/util');

const data = fs.readFileSync(path.resolve(__dirname, `../browser/chopsticks_executor_bg.wasm`));
const data = fs.readFileSync(path.resolve(__dirname, `../pkg/chopsticks_executor_bg.wasm`));
const compressed = Buffer.from(zlibSync(data, { level: 9 }));
const base64 = compressed.toString('base64');

console.log(`*** Compressed WASM: in=${formatNumber(data.length)}, out=${formatNumber(compressed.length)}, opt=${(100 * compressed.length / data.length).toFixed(2)}%, base64=${formatNumber(base64.length)}`);

fs.writeFileSync(path.resolve(__dirname, `../browser/index.js`), `// Auto-generated file, do not edit by hand
fs.writeFileSync(path.resolve(__dirname, `../pkg/index.js`), `// Auto-generated file, do not edit by hand
const LEN_IN = ${compressed.length};
const LEN_OUT = ${data.length};
const BYTES = '${base64}';
Expand All @@ -28,4 +28,4 @@ export * from "./chopsticks_executor.js";

// replace wasm with empty file because it's not needed
// but we need to have it in the repo for the build to work
fs.writeFileSync(path.resolve(__dirname, `../browser/chopsticks_executor_bg.wasm`), '')
fs.writeFileSync(path.resolve(__dirname, `../pkg/chopsticks_executor_bg.wasm`), '')
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.9.2-4",
"version": "0.9.2-5",
"author": "Acala Developers <[email protected]>",
"license": "Apache-2.0",
"bin": "./chopsticks.cjs",
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.9.2-4",
"version": "0.9.2-5",
"author": "Acala Developers <[email protected]>",
"license": "Apache-2.0",
"type": "module",
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/wasm-executor/node-wasm-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@ import { parentPort } from 'node:worker_threads'
import nodeEndpoint from 'comlink/dist/umd/node-adapter.js'

const getRuntimeVersion = async (code) => {
await pkg.wasmReady
return pkg.get_runtime_version(code)
}

// trie_version: 0 for old trie, 1 for new trie
const calculateStateRoot = async (entries, trie_version) => {
await pkg.wasmReady
return pkg.calculate_state_root(entries, trie_version)
}

const decodeProof = async (trieRootHash, keys, nodes) => {
await pkg.wasmReady
return pkg.decode_proof(trieRootHash, keys, nodes)
}

const createProof = async (nodes, entries) => {
await pkg.wasmReady
return pkg.create_proof(nodes, entries)
}

const runTask = async (task, callback) => {
await pkg.wasmReady
return pkg.run_task(task, callback, process.env.RUST_LOG)
}

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.9.2-4",
"version": "0.9.2-5",
"author": "Acala Developers <[email protected]>",
"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.9.2-4",
"version": "0.9.2-5",
"author": "Acala Developers <[email protected]>",
"license": "Apache-2.0",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/web-test/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function App() {
const [extrinsic, setExtrinsic] = useState('')
const [dryRunResult, setDryRunResult] = useState('')
const [config, setConfig] = useState<SetupOptions>({
endpoint: 'wss://acala-rpc-0.aca-api.network',
endpoint: 'wss://acala-rpc.aca-api.network',
block: 4_000_000,
})
const [blocks, setBlocks] = useState<{ number: number; hash: HexString }[]>([])
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ __metadata:
dependencies:
"@polkadot/util": ^12.5.1
"@polkadot/wasm-util": ^7.2.2
"@swc/cli": 0.1.62
"@swc/core": ^1.3.96
fflate: ^0.8.1
languageName: unknown
linkType: soft
Expand Down

0 comments on commit 1b1e86b

Please sign in to comment.