Skip to content
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

P-58 Use Chopsticks to fork live parachain chain #3221

Merged
merged 10 commits into from
Jan 7, 2025
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"
}
}
]
26 changes: 2 additions & 24 deletions .github/workflows/check-runtime-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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,24 +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 }}

- name: Collect docker logs if test fails
continue-on-error: true
uses: jwalton/gh-docker-logs@v2
if: failure()
with:
tail: all
dest: docker-logs

- name: Upload docker logs if test fails
uses: actions/upload-artifact@v4
if: failure()
with:
name: ${{ matrix.runtime.name }}-docker-logs
path: docker-logs
if-no-files-found: ignore
retention-days: 3
./parachain/scripts/runtime-upgrade.sh ${{ matrix.runtime.name }} ${{ matrix.runtime.uri }} ${{ env.RELEASE_TAG }}

try-runtime:
runs-on: ubuntu-22.04
Expand All @@ -128,7 +106,7 @@ jobs:
fetch-depth: 0

- name: Run ${{ matrix.runtime.name }} try-runtime check
uses: paritytech/try-runtime-gha@v0.2.0
uses: BillyWooo/try-runtime-gha@v0.3.0
with:
runtime-package: ${{ matrix.runtime.package }}
node-uri: ${{ matrix.runtime.uri }}
Expand Down
102 changes: 0 additions & 102 deletions parachain/scripts/fork-parachain-and-launch.sh

This file was deleted.

106 changes: 67 additions & 39 deletions parachain/scripts/runtime-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,103 @@
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
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 "------------------------------------------------------------"
}

# Download runtime wasm
print_divider
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

# Install tools
print_divider
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)"

# Check if the released runtime version is greater than the on-chain runtime version,
print_divider
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"
exit 0
echo "Current On-chain runtime is up to date, quit"
exit 1
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
echo "start chopsticks: $1"
npx @acala-network/[email protected] --endpoint=$2 --port=9944 --mock-signature-host=true --db=./new-db.sqlite --runtime-log-level=5 --allow-unresolved-imports=true --wasm-override $new_wasm &
PID=$!
echo "Chopsticks fork parachain PID: $PID"
sleep 30

echo "after chopsticks: $1"
new_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)
if [ -n "$new_onchain_version" ] && \
[ "$new_onchain_version" -ne "$release_version" ]; then
echo "On-chain new: $new_onchain_version"
echo "Runtime version NOT increased successfully, quit"
exit 1
fi

echo "Runtime upgrade succeed: $new_onchain_version"

print_divider
echo "Done"

echo "Done"
Loading