@acala-network/chopsticks 0.12.1-1 → 0.12.1-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ # Try-Runtime CLI
2
+
3
+ 🚧 EXPERIMENTAL FEATURE 🚧
4
+
5
+ You can use Chopsticks to perform runtime migration checks. It doesn't support PoV measure yet, only weight check is support.
6
+
7
+ ```bash
8
+ # try-runtime print help
9
+ npx @acala-network/chopsticks try-runtime --help
10
+ ```
11
+
12
+ Basic example:
13
+
14
+ ```bash
15
+ npx @acala-network/chopsticks try-runtime \
16
+ --endpoint <wss://remote.endpoint> \
17
+ --runtime <wasm_runtime_path> \
18
+ --checks PreAndPost
19
+ ```
20
+
21
+ __NOTE__: You can also use `--config` to pass arguments
@@ -8,61 +8,93 @@ Object.defineProperty(exports, "cli", {
8
8
  return cli;
9
9
  }
10
10
  });
11
+ const _chopstickscore = require("@acala-network/chopsticks-core");
11
12
  const _nodefs = require("node:fs");
12
13
  const _zod = require("zod");
13
14
  const _index = require("../../schema/index.js");
14
- const _generatehtmldiff = require("../../utils/generate-html-diff.js");
15
- const _openhtml = require("../../utils/open-html.js");
15
+ const _override = require("../../utils/override.js");
16
16
  const _context = require("../../context.js");
17
17
  const schema = _zod.z.object({
18
18
  endpoint: _index.configSchema.shape.endpoint,
19
- port: _index.configSchema.shape.port,
20
- ['build-block-mode']: _index.configSchema.shape['build-block-mode'],
21
19
  block: _index.configSchema.shape.block,
22
20
  db: _index.configSchema.shape.db,
23
- ['runtime-log-level']: _index.configSchema.shape['runtime-log-level'],
24
- ['wasm-override']: _zod.z.string({
21
+ ['runtime-log-level']: _index.configSchema.shape['runtime-log-level'].default(5),
22
+ ['runtime']: _zod.z.string({
25
23
  description: 'Path to WASM built with feature `try-runtime` enabled'
26
24
  }),
25
+ 'import-storage': _index.configSchema.shape['import-storage'],
26
+ checks: _zod.z.enum([
27
+ 'None',
28
+ 'All',
29
+ 'PreAndPost',
30
+ 'TryState'
31
+ ]),
32
+ 'disable-spec-check': _zod.z.boolean({
33
+ description: 'Disable spec name/version check'
34
+ }).optional(),
27
35
  ['output-path']: _zod.z.string({
28
36
  description: 'File path to print output'
29
- }).optional(),
30
- html: _zod.z.boolean({
31
- description: 'Generate html with storage diff'
32
- }).optional(),
33
- open: _zod.z.boolean({
34
- description: 'Open generated html'
35
37
  }).optional()
36
38
  });
37
39
  const cli = (y)=>{
38
- y.command('try-runtime', 'Runs runtime upgrade', (yargs)=>yargs.options((0, _index.getYargsOptions)(schema.shape)), async (argv)=>{
39
- const context = await (0, _context.setupContext)(schema.parse(argv));
40
+ y.command('try-runtime', '🚧 EXPERIMENTAL: Check upgrade migrations 🚧', (yargs)=>yargs.options((0, _index.getYargsOptions)(schema.shape)), async (argv)=>{
41
+ console.log('🚧 EXPERIMENTAL FEATURE 🚧');
42
+ const config = schema.parse(argv);
43
+ if (!config.db) {
44
+ console.log('āš ļø Make sure to provide db, it will speed up the process');
45
+ }
46
+ const context = await (0, _context.setupContext)({
47
+ ...config,
48
+ port: 8000,
49
+ 'build-block-mode': _chopstickscore.BuildBlockMode.Manual
50
+ });
40
51
  const block = context.chain.head;
41
52
  const registry = await block.registry;
42
53
  registry.register({
43
54
  UpgradeCheckSelect: {
44
55
  _enum: {
45
- None: null
56
+ None: null,
57
+ All: null,
58
+ PreAndPost: null,
59
+ TryState: null
46
60
  }
47
61
  }
48
62
  });
49
- const select_none = registry.createType('UpgradeCheckSelect', 'None');
50
- const result = await block.call('TryRuntime_on_runtime_upgrade', [
63
+ const oldVersion = await block.runtimeVersion;
64
+ // set new runtime
65
+ await (0, _override.overrideWasm)(block.chain, config.runtime);
66
+ const newVersion = await block.runtimeVersion;
67
+ console.log('\n');
68
+ console.log(new Array(80).fill('-').join(''));
69
+ console.log(`\tCurrent runtime spec_name: ${oldVersion.specName}, spec_version: ${oldVersion.specVersion}`);
70
+ console.log(`\tNew runtime spec_name: ${newVersion.specName}, spec_version: ${newVersion.specVersion}`);
71
+ console.log(new Array(80).fill('-').join(''));
72
+ console.log('\n');
73
+ if (!config['disable-spec-check'] && oldVersion.specName !== newVersion.specName) {
74
+ console.log('āŒ Spec name does not match. Use --disable-spec-check to disable this check');
75
+ process.exit(1);
76
+ }
77
+ if (!config['disable-spec-check'] && oldVersion.specVersion >= newVersion.specVersion) {
78
+ console.log('āŒ Spec version must increase. Use --disable-spec-check to disable this check');
79
+ process.exit(1);
80
+ }
81
+ const select_none = registry.createType('UpgradeCheckSelect', config.checks);
82
+ const response = await block.call('TryRuntime_on_runtime_upgrade', [
51
83
  select_none.toHex()
52
84
  ]);
53
- if (argv.html) {
54
- const filePath = await (0, _generatehtmldiff.generateHtmlDiffPreviewFile)(block, result.storageDiff, block.hash);
55
- console.log(`Generated preview ${filePath}`);
56
- if (argv.open) {
57
- (0, _openhtml.openHtml)(filePath);
58
- }
59
- } else if (argv.outputPath) {
60
- (0, _nodefs.writeFileSync)(argv.outputPath, JSON.stringify(result, null, 2));
85
+ if (argv.outputPath) {
86
+ (0, _nodefs.writeFileSync)(argv.outputPath, JSON.stringify(response, null, 2));
61
87
  } else {
62
- console.dir(result, {
63
- depth: null,
64
- colors: false
65
- });
88
+ const [actual, max] = registry.createType('(Weight, Weight)', response.result);
89
+ const consumedWeight = actual.refTime.toBn();
90
+ const maxWeight = max.refTime.toBn();
91
+ console.log('\n🚧 EXPERIMENTAL FEATURE 🚧');
92
+ console.log('āš ļø PoV measure is not supported, consider using https://crates.io/crates/try-runtime-cli');
93
+ console.log(`\nConsumed weight: ${consumedWeight.toNumber()} of max: ${maxWeight.toNumber()} ( ${(consumedWeight.toNumber() / maxWeight.toNumber() * 100).toFixed(2)}% )`);
94
+ if (consumedWeight.gt(maxWeight)) {
95
+ console.log('āŒ Weight limit is exceeded āŒ');
96
+ process.exit(1);
97
+ }
66
98
  }
67
99
  process.exit(0);
68
100
  });
@@ -0,0 +1,21 @@
1
+ # Try-Runtime CLI
2
+
3
+ 🚧 EXPERIMENTAL FEATURE 🚧
4
+
5
+ You can use Chopsticks to perform runtime migration checks. It doesn't support PoV measure yet, only weight check is support.
6
+
7
+ ```bash
8
+ # try-runtime print help
9
+ npx @acala-network/chopsticks try-runtime --help
10
+ ```
11
+
12
+ Basic example:
13
+
14
+ ```bash
15
+ npx @acala-network/chopsticks try-runtime \
16
+ --endpoint <wss://remote.endpoint> \
17
+ --runtime <wasm_runtime_path> \
18
+ --checks PreAndPost
19
+ ```
20
+
21
+ __NOTE__: You can also use `--config` to pass arguments
@@ -1,58 +1,90 @@
1
+ import { BuildBlockMode } from '@acala-network/chopsticks-core';
1
2
  import { writeFileSync } from 'node:fs';
2
3
  import { z } from 'zod';
3
4
  import { configSchema, getYargsOptions } from '../../schema/index.js';
4
- import { generateHtmlDiffPreviewFile } from '../../utils/generate-html-diff.js';
5
- import { openHtml } from '../../utils/open-html.js';
5
+ import { overrideWasm } from '../../utils/override.js';
6
6
  import { setupContext } from '../../context.js';
7
7
  const schema = z.object({
8
8
  endpoint: configSchema.shape.endpoint,
9
- port: configSchema.shape.port,
10
- ['build-block-mode']: configSchema.shape['build-block-mode'],
11
9
  block: configSchema.shape.block,
12
10
  db: configSchema.shape.db,
13
- ['runtime-log-level']: configSchema.shape['runtime-log-level'],
14
- ['wasm-override']: z.string({
11
+ ['runtime-log-level']: configSchema.shape['runtime-log-level'].default(5),
12
+ ['runtime']: z.string({
15
13
  description: 'Path to WASM built with feature `try-runtime` enabled'
16
14
  }),
15
+ 'import-storage': configSchema.shape['import-storage'],
16
+ checks: z.enum([
17
+ 'None',
18
+ 'All',
19
+ 'PreAndPost',
20
+ 'TryState'
21
+ ]),
22
+ 'disable-spec-check': z.boolean({
23
+ description: 'Disable spec name/version check'
24
+ }).optional(),
17
25
  ['output-path']: z.string({
18
26
  description: 'File path to print output'
19
- }).optional(),
20
- html: z.boolean({
21
- description: 'Generate html with storage diff'
22
- }).optional(),
23
- open: z.boolean({
24
- description: 'Open generated html'
25
27
  }).optional()
26
28
  });
27
29
  export const cli = (y)=>{
28
- y.command('try-runtime', 'Runs runtime upgrade', (yargs)=>yargs.options(getYargsOptions(schema.shape)), async (argv)=>{
29
- const context = await setupContext(schema.parse(argv));
30
+ y.command('try-runtime', '🚧 EXPERIMENTAL: Check upgrade migrations 🚧', (yargs)=>yargs.options(getYargsOptions(schema.shape)), async (argv)=>{
31
+ console.log('🚧 EXPERIMENTAL FEATURE 🚧');
32
+ const config = schema.parse(argv);
33
+ if (!config.db) {
34
+ console.log('āš ļø Make sure to provide db, it will speed up the process');
35
+ }
36
+ const context = await setupContext({
37
+ ...config,
38
+ port: 8000,
39
+ 'build-block-mode': BuildBlockMode.Manual
40
+ });
30
41
  const block = context.chain.head;
31
42
  const registry = await block.registry;
32
43
  registry.register({
33
44
  UpgradeCheckSelect: {
34
45
  _enum: {
35
- None: null
46
+ None: null,
47
+ All: null,
48
+ PreAndPost: null,
49
+ TryState: null
36
50
  }
37
51
  }
38
52
  });
39
- const select_none = registry.createType('UpgradeCheckSelect', 'None');
40
- const result = await block.call('TryRuntime_on_runtime_upgrade', [
53
+ const oldVersion = await block.runtimeVersion;
54
+ // set new runtime
55
+ await overrideWasm(block.chain, config.runtime);
56
+ const newVersion = await block.runtimeVersion;
57
+ console.log('\n');
58
+ console.log(new Array(80).fill('-').join(''));
59
+ console.log(`\tCurrent runtime spec_name: ${oldVersion.specName}, spec_version: ${oldVersion.specVersion}`);
60
+ console.log(`\tNew runtime spec_name: ${newVersion.specName}, spec_version: ${newVersion.specVersion}`);
61
+ console.log(new Array(80).fill('-').join(''));
62
+ console.log('\n');
63
+ if (!config['disable-spec-check'] && oldVersion.specName !== newVersion.specName) {
64
+ console.log('āŒ Spec name does not match. Use --disable-spec-check to disable this check');
65
+ process.exit(1);
66
+ }
67
+ if (!config['disable-spec-check'] && oldVersion.specVersion >= newVersion.specVersion) {
68
+ console.log('āŒ Spec version must increase. Use --disable-spec-check to disable this check');
69
+ process.exit(1);
70
+ }
71
+ const select_none = registry.createType('UpgradeCheckSelect', config.checks);
72
+ const response = await block.call('TryRuntime_on_runtime_upgrade', [
41
73
  select_none.toHex()
42
74
  ]);
43
- if (argv.html) {
44
- const filePath = await generateHtmlDiffPreviewFile(block, result.storageDiff, block.hash);
45
- console.log(`Generated preview ${filePath}`);
46
- if (argv.open) {
47
- openHtml(filePath);
48
- }
49
- } else if (argv.outputPath) {
50
- writeFileSync(argv.outputPath, JSON.stringify(result, null, 2));
75
+ if (argv.outputPath) {
76
+ writeFileSync(argv.outputPath, JSON.stringify(response, null, 2));
51
77
  } else {
52
- console.dir(result, {
53
- depth: null,
54
- colors: false
55
- });
78
+ const [actual, max] = registry.createType('(Weight, Weight)', response.result);
79
+ const consumedWeight = actual.refTime.toBn();
80
+ const maxWeight = max.refTime.toBn();
81
+ console.log('\n🚧 EXPERIMENTAL FEATURE 🚧');
82
+ console.log('āš ļø PoV measure is not supported, consider using https://crates.io/crates/try-runtime-cli');
83
+ console.log(`\nConsumed weight: ${consumedWeight.toNumber()} of max: ${maxWeight.toNumber()} ( ${(consumedWeight.toNumber() / maxWeight.toNumber() * 100).toFixed(2)}% )`);
84
+ if (consumedWeight.gt(maxWeight)) {
85
+ console.log('āŒ Weight limit is exceeded āŒ');
86
+ process.exit(1);
87
+ }
56
88
  }
57
89
  process.exit(0);
58
90
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks",
3
- "version": "0.12.1-1",
3
+ "version": "0.12.1-2",
4
4
  "author": "Acala Developers <hello@acala.network>",
5
5
  "license": "Apache-2.0",
6
6
  "bin": "./chopsticks.cjs",
@@ -14,8 +14,8 @@
14
14
  "depcheck": "npx depcheck --ignore-patterns='*.test.ts'"
15
15
  },
16
16
  "dependencies": {
17
- "@acala-network/chopsticks-core": "0.12.1-1",
18
- "@acala-network/chopsticks-db": "0.12.1-1",
17
+ "@acala-network/chopsticks-core": "0.12.1-2",
18
+ "@acala-network/chopsticks-db": "0.12.1-2",
19
19
  "@pnpm/npm-conf": "^2.2.2",
20
20
  "@polkadot/api": "^10.11.2",
21
21
  "@polkadot/api-augment": "^10.11.2",