diff --git a/executor/src/task.rs b/executor/src/task.rs index d76ca5ad..19318226 100644 --- a/executor/src/task.rs +++ b/executor/src/task.rs @@ -208,8 +208,8 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result { - unreachable!() + RuntimeCall::ClosestDescendantMerkleValue(req) => { + req.resume_unknown() } RuntimeCall::NextKey(req) => { diff --git a/packages/chopsticks/package.json b/packages/chopsticks/package.json index e4872d60..5bfd493f 100644 --- a/packages/chopsticks/package.json +++ b/packages/chopsticks/package.json @@ -72,4 +72,4 @@ "default": "./dist/esm/utils/*.js" } } -} \ No newline at end of file +} diff --git a/packages/chopsticks/src/plugins/try-runtime/index.ts b/packages/chopsticks/src/plugins/try-runtime/index.ts index 5f1acc80..4d1ac5b8 100644 --- a/packages/chopsticks/src/plugins/try-runtime/index.ts +++ b/packages/chopsticks/src/plugins/try-runtime/index.ts @@ -1,69 +1,98 @@ +import { BuildBlockMode } from '@acala-network/chopsticks-core' import { writeFileSync } from 'node:fs' import { z } from 'zod' import type { Argv } from 'yargs' import { configSchema, getYargsOptions } from '../../schema/index.js' -import { generateHtmlDiffPreviewFile } from '../../utils/generate-html-diff.js' -import { openHtml } from '../../utils/open-html.js' +import { overrideWasm } from '../../utils/override.js' import { setupContext } from '../../context.js' const schema = z.object({ endpoint: configSchema.shape.endpoint, - port: configSchema.shape.port, - ['build-block-mode']: configSchema.shape['build-block-mode'], block: configSchema.shape.block, db: configSchema.shape.db, ['runtime-log-level']: configSchema.shape['runtime-log-level'], - ['wasm-override']: z.string({ + ['runtime']: z.string({ description: 'Path to WASM built with feature `try-runtime` enabled', }), + 'import-storage': configSchema.shape['import-storage'], + checks: z.enum(['None', 'All', 'PreAndPost', 'TryState']), + 'disable-spec-check': z.boolean({ description: 'Disable spec name/version check' }).optional(), ['output-path']: z .string({ description: 'File path to print output', }) .optional(), - html: z - .boolean({ - description: 'Generate html with storage diff', - }) - .optional(), - open: z - .boolean({ - description: 'Open generated html', - }) - .optional(), }) export const cli = (y: Argv) => { y.command( 'try-runtime', - 'Runs runtime upgrade', + 'šŸš§ EXPERIMENTAL: Check upgrade migrations šŸš§', (yargs) => yargs.options(getYargsOptions(schema.shape)), async (argv) => { - const context = await setupContext(schema.parse(argv)) + console.log('šŸš§ EXPERIMENTAL FEATURE šŸš§') + + const config = schema.parse(argv) + if (!config.db) { + console.log('āš ļø Make sure to provide db, it will speed up the process') + } + const context = await setupContext({ ...config, port: 8000, 'build-block-mode': BuildBlockMode.Manual }) const block = context.chain.head const registry = await block.registry registry.register({ UpgradeCheckSelect: { _enum: { None: null, + All: null, + PreAndPost: null, + TryState: null, }, }, }) - const select_none = registry.createType('UpgradeCheckSelect', 'None') - const result = await block.call('TryRuntime_on_runtime_upgrade', [select_none.toHex()]) + const oldVersion = await block.runtimeVersion + // set new runtime + await overrideWasm(block.chain, config.runtime) + const newVersion = await block.runtimeVersion + console.log('\n') + console.log(new Array(80).fill('-').join('')) + console.log(`\tCurrent runtime spec_name: ${oldVersion.specName}, spec_version: ${oldVersion.specVersion}`) + console.log(`\tNew runtime spec_name: ${newVersion.specName}, spec_version: ${newVersion.specVersion}`) + console.log(new Array(80).fill('-').join('')) + console.log('\n') - if (argv.html) { - const filePath = await generateHtmlDiffPreviewFile(block, result.storageDiff, block.hash) - console.log(`Generated preview ${filePath}`) - if (argv.open) { - openHtml(filePath) - } - } else if (argv.outputPath) { - writeFileSync(argv.outputPath, JSON.stringify(result, null, 2)) + if (!config['disable-spec-check'] && oldVersion.specName !== newVersion.specName) { + console.log('āŒ Spec name does not match. Use --disable-spec-check to disable this check') + process.exit(1) + } + + if (!config['disable-spec-check'] && oldVersion.specVersion >= newVersion.specVersion) { + console.log('āŒ Spec version must increase. Use --disable-spec-check to disable this check') + process.exit(1) + } + + const select_none = registry.createType('UpgradeCheckSelect', config.checks) + const response = await block.call('TryRuntime_on_runtime_upgrade', [select_none.toHex()]) + + if (argv.outputPath) { + writeFileSync(argv.outputPath, JSON.stringify(response, null, 2)) } else { - console.dir(result, { depth: null, colors: false }) + const [actual, max] = registry.createType('(Weight, Weight)', response.result) + const consumedWeight = actual.refTime.toBn() + const maxWeight = max.refTime.toBn() + + console.log('\nšŸš§ EXPERIMENTAL FEATURE šŸš§') + console.log('āš ļø PoV measure is not supported, consider using https://crates.io/crates/try-runtime-cli') + + console.log( + `\nConsumed weight: ${consumedWeight.toNumber()} of max: ${maxWeight.toNumber()} ( ${((consumedWeight.toNumber() / maxWeight.toNumber()) * 100).toFixed(2)}% )`, + ) + + if (consumedWeight.gt(maxWeight)) { + console.log('āŒ Weight limit is exceeded āŒ') + process.exit(1) + } } process.exit(0) diff --git a/packages/core/package.json b/packages/core/package.json index 32b93dd6..58a6b30a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -57,4 +57,4 @@ "./dist/cjs/wasm-executor/node-worker.js": "./dist/cjs/wasm-executor/browser-worker.js", "./dist/esm/wasm-executor/node-worker.js": "./dist/esm/wasm-executor/browser-worker.js" } -} \ No newline at end of file +} diff --git a/packages/db/package.json b/packages/db/package.json index e94fb70c..be4062a1 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -40,4 +40,4 @@ "default": "./dist/esm/*.js" } } -} \ No newline at end of file +} diff --git a/packages/testing/package.json b/packages/testing/package.json index 29515bed..daf08985 100644 --- a/packages/testing/package.json +++ b/packages/testing/package.json @@ -39,4 +39,4 @@ "default": "./dist/esm/*.js" } } -} \ No newline at end of file +} diff --git a/packages/utils/package.json b/packages/utils/package.json index 35a3f88b..ce74c0ad 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -38,4 +38,4 @@ "default": "./dist/esm/*.js" } } -} \ No newline at end of file +}