From d15dd21da6e089027fa1d4ee1d66189623544763 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Fri, 7 Jun 2024 15:26:04 +0200 Subject: [PATCH] chain sync test --- .github/workflows/chain-sync.yml | 44 ++++++++++++++++++++++++++++++++ scripts/sync.sh | 39 ++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 .github/workflows/chain-sync.yml create mode 100755 scripts/sync.sh diff --git a/.github/workflows/chain-sync.yml b/.github/workflows/chain-sync.yml new file mode 100644 index 0000000000..e3ef7e0421 --- /dev/null +++ b/.github/workflows/chain-sync.yml @@ -0,0 +1,44 @@ +name: Chain Sync + +on: + push: + branches: ["master"] + tags: + - v[0-9]+.[0-9]+.[0-9]+* + pull_request: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + chain-sync: + continue-on-error: true + timeout-minutes: 60 + runs-on: ubuntu-latest + + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install deps + run: sudo apt -y install protobuf-compiler + + - name: Install & display rust toolchain + run: rustup show + + - name: Check targets are installed correctly + run: rustup target list --installed + + - name: Build + run: cargo build --release --locked + + - name: Test astar sync + run: ./scripts/sync.sh astar + + - name: Test shiden sync + run: ./scripts/sync.sh shiden + + - name: Test shibuya sync + run: ./scripts/sync.sh shibuya diff --git a/scripts/sync.sh b/scripts/sync.sh new file mode 100755 index 0000000000..8bd9988436 --- /dev/null +++ b/scripts/sync.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +set -e + +# first argument is chain +chain="$@" + +# run node +./target/release/astar-collator --chain $chain --no-telemetry --no-prometheus --tmp & CHAIN_PID=$! + +printf "Waiting for RPC to be ready" +attempts=12 # 1 minutes +until nc -z localhost 9944; do + attempts=$((attempts - 1)) + if [ $attempts -eq 0 ]; then + echo "Chain RPC failed to start" + exit 1 + fi + sleep 5 +done + +printf "Waiting for 30 seconds to sync at least 1000 blocks" +sleep 30 + +number=$(curl --location http://localhost:9944 \ + --header 'Content-Type: application/json' \ + --data '{ + "jsonrpc": "2.0", + "method": "chain_getHeader", + "params": [], + "id": 1 + }' | jq '.result.number' | xargs | { read hex_number; printf "%d\n" $hex_number; }) + +if [ "$number" -lt 1000 ]; then + echo "Chain failed to sync 1000 blocks in 30 seconds" + exit 1 +fi + +kill $CHAIN_PID