Skip to content

Commit

Permalink
use chopsticks to try runtime upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyWooo committed Dec 11, 2024
1 parent 21d10ff commit d661884
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 142 deletions.
10 changes: 5 additions & 5 deletions .github/runtime.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
"name": "rococo",
"package": "rococo-parachain-runtime",
"path": "runtime/rococo",
"uri": "wss://rpc.litentry-parachain.litentry.io:443"
"name": "paseo",
"package": "paseo-parachain-runtime",
"path": "runtime/paseo",
"uri": "wss://rpc.paseo-parachain.litentry.io:443"
},
{
"name": "litentry",
"package": "litentry-parachain-runtime",
"path": "runtime/litentry",
"uri": "wss://rpc.litentry-parachain.litentry.io:443"
}
}
]
15 changes: 5 additions & 10 deletions .github/workflows/check-runtime-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:

jobs:
check-condition:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
outputs:
skip_simulation: ${{ steps.check.outputs.skip_simulation }}
steps:
Expand All @@ -37,7 +37,7 @@ jobs:
echo "skip_simulation=$skip_simulation" | tee -a $GITHUB_OUTPUT
runtime-matrix:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
outputs:
runtime: ${{ steps.runtime.outputs.runtime }}
name: Parse runtime matrix
Expand All @@ -56,7 +56,7 @@ jobs:
echo "runtime=$TASKS" >> $GITHUB_OUTPUT
simulate-runtime-upgrade:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
needs:
- check-condition
- runtime-matrix
Expand All @@ -76,11 +76,6 @@ jobs:
- name: Enable corepack and pnpm
run: corepack enable && corepack enable pnpm

- name: Fork ${{ matrix.runtime.name }} and launch parachain
timeout-minutes: 20
run: |
./scripts/fork-parachain-and-launch.sh ${{ matrix.runtime.name }}
- name: Install subwasm ${{ env.SUBWASM_VERSION }}
run: |
wget https://github.com/chevdor/subwasm/releases/download/v${{ env.SUBWASM_VERSION }}/subwasm_linux_amd64_v${{ env.SUBWASM_VERSION }}.deb
Expand All @@ -92,7 +87,7 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
timeout-minutes: 10
run: |
./scripts/runtime-upgrade.sh ${{ matrix.runtime.name }}-parachain-runtime.compact.compressed.wasm ${{ env.RELEASE_TAG }}
./parachain/scripts/runtime-upgrade.sh ${{ matrix.runtime.name }} ${{ matrix.runtime.uri }} ${{ env.RELEASE_TAG }}
- name: Collect docker logs if test fails
continue-on-error: true
Expand All @@ -112,7 +107,7 @@ jobs:
retention-days: 3

try-runtime:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
needs:
- check-condition
- runtime-matrix
Expand Down
102 changes: 0 additions & 102 deletions parachain/scripts/fork-parachain-and-launch.sh

This file was deleted.

21 changes: 21 additions & 0 deletions parachain/scripts/litentry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
endpoint:
- wss://rpc.litentry-parachain.litentry.io:443
mock-signature-host: true
db: ./db.sqlite
runtime-log-level: 5

import-storage:
System:
Account:
-
-
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
- providers: 1
data:
free: 1000000000000000000000 # Litentry metadata 18 digit
Council:
Members:
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
TechnicalCommittee:
Members:
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
23 changes: 23 additions & 0 deletions parachain/scripts/paseo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
endpoint:
- wss://rpc.paseo-parachain.litentry.io:443
mock-signature-host: true
db: ./db.sqlite
runtime-log-level: 5

import-storage:
Sudo:
Key: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
System:
Account:
-
-
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
- providers: 1
data:
free: 1000000000000000000000 # paseo metadata 18 digit
Council:
Members:
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
TechnicalCommittee:
Members:
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
87 changes: 62 additions & 25 deletions parachain/scripts/runtime-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,99 @@ ROOTDIR=$(git rev-parse --show-toplevel)
# 2. do runtime upgrade using wasm from step 1
# 3. verify if the runtime upgrade is successful

output_wasm=/tmp/runtime.wasm
new_wasm=/tmp/runtime.wasm

function usage() {
echo
echo "Usage: $0 wasm-name [release-tag]"
echo "Usage: $0 <wasm-name> <endpoint> <release-tag> "
echo "e.g.:"
echo " $0 litentry wss://rpc.litentry-parachain.litentry.io v0.9.21-01"
}

[ $# -gt 2 ] && (usage; exit 1)
[ $# -ne 3 ] && (usage; exit 1)

function print_divider() {
echo "------------------------------------------------------------"
}

print_divider
# 1. download runtime wasm
echo "Download $1-parachain-runtime.compact.compressed.wasm from release tag $3 ..."
gh release download "$3" -p "$1-parachain-runtime.compact.compressed.wasm" -O "$new_wasm" || true

# 1. download or copy runtime wasm
if [ -z "$2" ]; then
echo "Copy local wasm $1 ..."
cp -f "$1" "$output_wasm"
if [ -f "$new_wasm" ] && [ -s "$new_wasm" ]; then
ls -l "$new_wasm"
else
echo "Download $1 from release tag $2 ..."
gh release download "$2" -p "$1" -O "$output_wasm" || true
fi

if [ -f "$output_wasm" ] && [ -s "$output_wasm" ]; then
ls -l "$output_wasm"
else
echo "Cannot find $output_wasm or it has 0 bytes, quit"
echo "Cannot find $new_wasm or it has 0 bytes, quit"
exit 0
fi

print_divider
# 2. Install tools
wget -q https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl -O websocat
chmod +x websocat
echo "Websocat version: $(./websocat --version)"

# 2. check if the released runtime version is greater than the on-chain runtime version,
# which should be now accessible via localhost:9944
onchain_version=$(curl -s -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "state_getRuntimeVersion", "params": [] }' http://localhost:9944 | jq .result.specVersion)
release_version=$(subwasm --json info "$output_wasm" | jq .core_version.specVersion)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
echo "nvm version: $(nvm --version)"

print_divider
# 3. check if the released runtime version is greater than the on-chain runtime version,
echo "Check runtime version ..."
release_version=$(subwasm --json info "$new_wasm" | jq .core_version.specVersion)

PAYLOAD='{"id":1, "jsonrpc":"2.0", "method": "state_getRuntimeVersion", "params": [] }'
RETRY_INTERVAL=5
MAX_RETRIES=10
i=0
while ((i<MAX_RETRIES)); do
echo "Attempt $i: Trying to fetch on-chain version from $2..."
response=$(echo "$PAYLOAD" | ./websocat "$2") || echo ""
onchain_version=$(echo "$response" | jq -r .result.specVersion 2>/dev/null)
if [[ -n "$onchain_version" && "$onchain_version" != "null" ]]; then
break
else
echo "Invalid or no response. Retrying in $RETRY_INTERVAL seconds..."
sleep $RETRY_INTERVAL
fi
i=$((i + 1))
done
if [ "$i" -ge $MAX_RETRIES ]; then
echo "Failed to fetch on-chain version after $MAX_RETRIES attempts."
exit 1
fi

echo "On-chain: $onchain_version"
echo "Release: $release_version"

if [ -n "$release_version" ] && \
[ -n "$onchain_version" ] && \
[ "$onchain_version" -ge "$release_version" ]; then
echo "Runtime version not increased, quit"
echo "Current On-chain runtime is up to date, quit"
exit 0
fi

# 4. do runtime upgrade and verify
print_divider

# 3. do runtime upgrade and verify
echo "Do runtime upgrade and verify ..."
cd "$ROOTDIR/parachain/ts-tests"
echo "NODE_ENV=ci" > .env
pnpm install && pnpm run test-runtime-upgrade 2>&1

nvm install 20
nvm use 20
npx @acala-network/[email protected] --config=$1.yml --allow-unresolved-imports=true --wasm-override $new_wasm

new_onchain_version=$(curl -s -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "state_getRuntimeVersion", "params": [] }' http://localhost:8000 | jq .result.specVersion)
if [ -n "$new_onchain_version" ] && \
[ "$new_onchain_version" -ne "$release_version" ]; then
echo "Runtime version NOT increased successfully, quit"
exit 0
fi

# cd "$ROOTDIR/parachain/ts-tests"
# echo "NODE_ENV=ci" > .env
# pnpm install && pnpm run test-runtime-upgrade 2>&1

print_divider

Expand Down

0 comments on commit d661884

Please sign in to comment.