-
Notifications
You must be signed in to change notification settings - Fork 17
Runtime upgrade simulation #1081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
5a1be21
update script
Kailai-Wang f884cbb
use relative path
Kailai-Wang d9c059c
update script
Kailai-Wang 274ed6f
Merge branch 'dev' into 378-GA-for-runtime-upgrade-simulation
Kailai-Wang 8d7d329
Merge branch 'dev' into 378-GA-for-runtime-upgrade-simulation
Kailai-Wang cde217c
improve arg handling
Kailai-Wang 9ca926a
fix trap
Kailai-Wang e26ad7d
simulmation runtime upgrade demo impl
91a3b2d
runtime-upgrade ts impl
5bccf7a
fix some syntax
1c0f1b2
fix makefile
b74c34d
optimized scripts && cli
6cad6b3
use master branch of fork-off-substrate
Kailai-Wang 094eb92
Merge branch 'dev' into 378-GA-for-runtime-upgrade-simulation
Kailai-Wang 1168afe
optimize ts code
e16dc4e
Merge branch '378-GA-for-runtime-upgrade-simulation' of https://githu…
336a8bd
fix description
c542e73
fix action sytanx
c34f4cd
fix cli syntax
9230598
fix cli syntax
1c203e0
fix cli syntax
ef008d5
fix cli syntax
f9ea020
fix cli syntax
86bb718
fix cli syntax
2553ceb
fix cli syntax
e763b4b
fix cli syntax
18d537e
optimize ts-code & cli
d562265
adjustment of script and GHA
Kailai-Wang d714d25
try to fix CI
Kailai-Wang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| name: Simulate runtime upgrade | ||
|
|
||
| on: | ||
| release: | ||
| types: [released] | ||
|
|
||
| workflow_dispatch: | ||
| inputs: | ||
| release_tag: | ||
| description: runtime.wasm release_tag | ||
| required: true | ||
|
|
||
| env: | ||
| RELEASE_TAG: ${{ github.event.inputs.release_tag || github.event.release.tag_name }} | ||
|
|
||
| jobs: | ||
| simulate-runtime-upgrade: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| chain: | ||
| # litmus is not supported, as sudo was removed | ||
| # TODO: add runtime upgrade via governance | ||
| - litentry | ||
| - rococo | ||
| steps: | ||
| - name: Checkout codes on ${{ github.ref }} | ||
| uses: actions/checkout@v3 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Fork ${{ matrix.chain }} and launch parachain | ||
| timeout-minutes: 10 | ||
| run: | | ||
| ./scripts/fork-parachain-and-launch.sh ${{ matrix.chain }} | ||
|
|
||
| - name: Test runtime upgrade | ||
| timeout-minutes: 10 | ||
| run: | | ||
| ./scripts/runtime-upgrade.sh https://github.com/litentry/litentry-parachain/releases/download/${{ env.RELEASE_TAG }}/${{ matrix.chain }}-parachain-runtime.compact.compressed.wasm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #!/bin/bash | ||
| # set -eo we don't allow any command failed in this script. | ||
| set -eo pipefail | ||
|
|
||
| ROOTDIR=$(git rev-parse --show-toplevel) | ||
|
|
||
| # the script is used to simulate runtime upgrade, see: | ||
| # https://github.com/litentry/litentry-parachain/issues/378 | ||
|
|
||
| # The latest state of the blockchain is scraped and used to bootstrap a chain locally via fork-off-substrate, | ||
| # see ./scripts/fork-parachain-and-launch.sh | ||
| # | ||
| # After that, this script: | ||
| # 1. get the runtime wasm | ||
| # 2. do runtime upgrade using wasm from step 1 | ||
| # 3. verify if the runtime upgrade is successful | ||
|
|
||
| output_wasm=/tmp/runtime.wasm | ||
|
|
||
| function usage() { | ||
| echo | ||
| echo "Usage: $0 wasm-path" | ||
| echo " wasm-path can be either local file path or https URL" | ||
| } | ||
|
|
||
| [ $# -ne 1 ] && (usage; exit 1) | ||
|
|
||
| function print_divider() { | ||
| echo "------------------------------------------------------------" | ||
| } | ||
|
|
||
| print_divider | ||
|
|
||
| # download runtime wasm | ||
| echo "Get runtime wasm from $1" | ||
| case "$1" in | ||
| https*) | ||
| wget -q "$1" -O "$output_wasm" ;; | ||
| *) | ||
| cp -f "$1" "$output_wasm" ;; | ||
| esac | ||
|
|
||
| echo "Done" | ||
|
|
||
| if [ -f "$output_wasm" ]; then | ||
| ls -l "$output_wasm" | ||
| else | ||
| echo "Cannot find $output_wasm, quit" | ||
| exit 1 | ||
| fi | ||
|
|
||
| print_divider | ||
|
|
||
| # 2. do runtime upgrade and verify | ||
| echo "Do runtime upgrade and verify ..." | ||
| cd "$ROOTDIR/ts-tests" | ||
| echo "NODE_ENV=ci" > .env | ||
| yarn && yarn test-runtime-upgrade 2>&1 | ||
|
|
||
| print_divider | ||
|
|
||
| echo "Done" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { blake2AsHex, cryptoWaitReady } from '@polkadot/util-crypto'; | ||
| import * as fs from 'fs'; | ||
| import { Keyring, ApiPromise, WsProvider } from '@polkadot/api'; | ||
| import { loadConfig, describeLitentry } from './utils'; | ||
| import '@polkadot/wasm-crypto/initOnlyAsm'; | ||
| import * as path from 'path'; | ||
| import { expect } from 'chai'; | ||
| import { step } from 'mocha-steps'; | ||
|
|
||
| async function getRuntimeVersion(api: ApiPromise) { | ||
| const runtime_version = await api.rpc.state.getRuntimeVersion(); | ||
| return +runtime_version['specVersion']; | ||
| } | ||
|
|
||
| async function runtimeUpgrade(api: ApiPromise, wasm: string) { | ||
| const keyring = new Keyring({ type: 'sr25519' }); | ||
| const alice = keyring.addFromUri('//Alice'); | ||
| const old_runtime_version = await getRuntimeVersion(api); | ||
| let currentBlock = (await api.rpc.chain.getHeader()).number.toNumber(); | ||
| console.log(`Start doing runtime upgrade, current block = ${currentBlock}`); | ||
|
|
||
| // authorize and enact the upgrade | ||
| let nonce = (await api.rpc.system.accountNextIndex(alice.address)).toNumber(); | ||
| await api.tx.sudo | ||
| .sudo(api.tx.parachainSystem.authorizeUpgrade(blake2AsHex(wasm))) | ||
| .signAndSend(alice, { nonce: -1 }); | ||
| console.log('Submitted authorizeUpgrade'); | ||
| await api.tx.parachainSystem.enactAuthorizedUpgrade(wasm).signAndSend(alice, { nonce: -1 }); | ||
| console.log('Submitted enactAuthorizedUpgrade'); | ||
|
|
||
| // wait for 10 blocks | ||
| console.log('Wait for new runtime ...'); | ||
| currentBlock = (await api.rpc.chain.getHeader()).number.toNumber(); | ||
| let timeoutBlock = currentBlock + 10; | ||
| let runtimeUpgraded = false; | ||
|
|
||
| return new Promise(async (resolve, reject) => { | ||
| const unsub = await api.rpc.chain.subscribeNewHeads(async (header) => { | ||
| console.log(`Polling .. block = ${header.number.toNumber()}`); | ||
| const runtime_version = await getRuntimeVersion(api); | ||
| if (!runtimeUpgraded) { | ||
| if (runtime_version > old_runtime_version) { | ||
| runtimeUpgraded = true; | ||
| console.log( | ||
| `Runtime upgrade OK, new runtime version = ${runtime_version}, waiting for 2 more blocks ...` | ||
| ); | ||
| timeoutBlock = header.number.toNumber() + 2; | ||
| } | ||
| } | ||
| if (header.number.toNumber() == timeoutBlock) { | ||
| unsub(); | ||
| if (!runtimeUpgraded) { | ||
| reject('Runtime upgrade failed with timeout'); | ||
| } else { | ||
| console.log('All good'); | ||
| resolve(runtime_version); | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| describeLitentry('Runtime upgrade test', ``, (context) => { | ||
| step('Running runtime ugprade test', async function () { | ||
| const wasmPath = path.resolve('/tmp/runtime.wasm'); | ||
| const wasm = fs.readFileSync(wasmPath).toString('hex'); | ||
| const runtimeVersion = await runtimeUpgrade(context.api, `0x${wasm}`); | ||
| console.log(`result: ${runtimeVersion}`); | ||
| expect(runtimeVersion === (await getRuntimeVersion(context.api))); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the whole return value here is a little bit hard to understand, it works fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/litentry/litentry-parachain/blob/d714d251661e8bb3c534ca6827c90c44fef44790/ts-tests/tests/runtime-upgrade.test.ts#L37-L61