From 9ad0c6a705c99a84276541b378661292fa7b9f96 Mon Sep 17 00:00:00 2001 From: David Lehuby Date: Thu, 13 Jun 2024 09:52:15 +1000 Subject: [PATCH] PM-1764 - Add daily Seed Synchronisation Check --- .github/workflows/sync-check.yaml | 52 +++++++++++++++++++++++++++++++ scripts/mina-sync-monitor.sh | 27 ++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 .github/workflows/sync-check.yaml create mode 100755 scripts/mina-sync-monitor.sh diff --git a/.github/workflows/sync-check.yaml b/.github/workflows/sync-check.yaml new file mode 100644 index 0000000..ffe58a4 --- /dev/null +++ b/.github/workflows/sync-check.yaml @@ -0,0 +1,52 @@ +name: Daily Seed Synchronization Check +on: + workflow_dispatch: + schedule: + - cron: "0 0 * * 1,4" # At 00:00 on Monday, and Thursday +concurrency: + group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}" + cancel-in-progress: true +jobs: + parse-mainnet-seed-list: + runs-on: minafoundation-default-runners + outputs: + seeds: ${{ steps.parse-mainnet-seed-list.outputs.seeds }} + steps: + - name: 📥 Checkout + uses: actions/checkout@v4.1.1 + - name: Parse Mainnet Seed List + id: parse-mainnet-seed-list + run: | + echo "Parsing Mainnet Seed List" + seeds=$(cat networks/mainnet.txt | jq -R -s -c 'split("\n") | map(select(. != ""))') + echo "seeds=$seeds" >> $GITHUB_OUTPUT + test-peer: + needs: parse-mainnet-seed-list + runs-on: minafoundation-xlarge-runners + if: needs.parse-mainnet-seed-list.outputs.seeds != '[]' && needs.parse-mainnet-seed-list.outputs.seeds != '' + continue-on-error: true + strategy: + matrix: + seed: ${{ fromJson(needs.parse-mainnet-seed-list.outputs.seeds) }} + steps: + - name: 📥 Checkout + uses: actions/checkout@v4.1.1 + - name: Start Mina Daemon + run: | + docker run -d --restart always --name mina \ + --entrypoint="" \ + minaprotocol/mina-daemon:3.0.0-93e0279-bullseye-mainnet \ + mina daemon \ + --peer ${{ matrix.seed }} + - name: Wait for Daemon to Sync + id: wait-for-sync + run: ./scripts/mina-sync-monitor.sh + - name: Post to a Slack channel + id: slack + if: ${{ failure() }} + uses: slackapi/slack-github-action@v1.26.0 + with: + channel-id: "mf-alerts-info" + slack-message: "Failed to synchronize with Mina Daemon using seed peer:\n *_${{ matrix.seed }}_*" + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} diff --git a/scripts/mina-sync-monitor.sh b/scripts/mina-sync-monitor.sh new file mode 100755 index 0000000..0e4e8d8 --- /dev/null +++ b/scripts/mina-sync-monitor.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -e +max_attempts=24 +attempt=0 +sleep_duration=300 +status="Null" + +check_sync_status() { + status=$(docker exec mina mina client status --json | jq -r .sync_status || echo "Null") + echo "Current sync status: $status" +} + +# Loop to check sync status +while [ $attempt -lt $max_attempts ]; do + check_sync_status + if [ "$status" == "Synced" ]; then + echo "Mina client is synced." + exit 0 + fi + + attempt=$((attempt + 1)) + + echo "Mina daemon is not synced. Attempt $attempt/$max_attempts." + sleep $sleep_duration +done + +exit 1