From 3c73bb533135c6bbc78eb04becf3db1f53f23e32 Mon Sep 17 00:00:00 2001 From: Simon-Tl Date: Wed, 22 Nov 2023 16:10:37 +0800 Subject: [PATCH 1/6] ci: add axon sync test workflow --- .github/workflows/axon-sync-test.yml | 83 ++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .github/workflows/axon-sync-test.yml diff --git a/.github/workflows/axon-sync-test.yml b/.github/workflows/axon-sync-test.yml new file mode 100644 index 000000000..8bc8bcf8c --- /dev/null +++ b/.github/workflows/axon-sync-test.yml @@ -0,0 +1,83 @@ +name: Axon sync test + +on: + push: + pull_request: + merge_group: + workflow_dispatch: + +jobs: + # Start a single Axon node + Build_and_Archive_Axon: + strategy: + matrix: + # Supported GitHub-hosted runners and hardware resources + # see https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources + os: [ubuntu-22.04] + fail-fast: false + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - name: Cache of Cargo + uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo-build-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo-build + - name: Build Axon in the development profile + run: | + # check for AVX2 support by inspecting `/proc/cpuinfo` or running `lscpu` + # related issue: https://github.com/axonweb3/axon/issues/1387 + lscpu + # PORTABLE=1 USE_SSE=1 tell rocksdb to target AVX2 + PORTABLE=1 USE_SSE=1 cargo build + - name: Archive axon artifacts + uses: actions/upload-artifact@v3 + with: + name: axon-dir + path: | + target/ + Download_and_Start_Axon_Sync: + strategy: + matrix: + # Supported GitHub-hosted runners and hardware resources + # see https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources + os: [ubuntu-22.04] + fail-fast: false + name: Download axon binary + needs: Build_and_Archive_Axon + runs-on: ${{ matrix.os }} + steps: + - name: Download Axon Binary for Build_and_Archive_Axon + uses: actions/download-artifact@v3 + with: + name: axon-dir + - name: Start a single Axon node + env: + LOG_FILE: ${{ runner.temp }}/${{ matrix.os }}-single-axon-node.log + run: | + target/debug/axon --version | tee ${{ env.LOG_FILE }} + target/debug/axon init \ + --config devtools/chain/config.toml \ + --chain-spec devtools/chain/specs/single_node/chain-spec.toml \ + | tee -a ${{ env.LOG_FILE }} + target/debug/axon run \ + --config devtools/chain/config.toml \ + | tee -a ${{ env.LOG_FILE }} & + timeout-minutes: 1 + + - name: Archive logs + if: failure() + uses: actions/upload-artifact@v3 + with: + name: single-axon-node-logs + path: | + ${{ runner.temp }}/${{ matrix.os }}-single-axon-node.log + \ No newline at end of file From 123135fb24e9288bb8d9a5360af1ccf82b64a6c2 Mon Sep 17 00:00:00 2001 From: Simon-Tl Date: Wed, 22 Nov 2023 16:26:41 +0800 Subject: [PATCH 2/6] ci: set runs-on of the self-runner --- .github/workflows/axon-sync-test.yml | 63 ++++++++++++++-------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/.github/workflows/axon-sync-test.yml b/.github/workflows/axon-sync-test.yml index 8bc8bcf8c..26b48fdd4 100644 --- a/.github/workflows/axon-sync-test.yml +++ b/.github/workflows/axon-sync-test.yml @@ -1,13 +1,9 @@ name: Axon sync test on: - push: - pull_request: - merge_group: workflow_dispatch: jobs: - # Start a single Axon node Build_and_Archive_Axon: strategy: matrix: @@ -31,53 +27,56 @@ jobs: key: ${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo-build-${{ hashFiles('**/Cargo.lock') }} restore-keys: | ${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo-build - - name: Build Axon in the development profile + + - name: Build Axon run: | # check for AVX2 support by inspecting `/proc/cpuinfo` or running `lscpu` # related issue: https://github.com/axonweb3/axon/issues/1387 lscpu # PORTABLE=1 USE_SSE=1 tell rocksdb to target AVX2 PORTABLE=1 USE_SSE=1 cargo build + - name: Archive axon artifacts uses: actions/upload-artifact@v3 with: name: axon-dir path: | - target/ + target/debug/axon + devtools/chain/specs/single_node/chain-spec.toml + devtools/chain/default.db-options + devtools/chain/config.toml + devtools/chain/nodes/node_1* + retention-days: 7 + + Download_and_Start_Axon_Sync: - strategy: - matrix: - # Supported GitHub-hosted runners and hardware resources - # see https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources - os: [ubuntu-22.04] - fail-fast: false - name: Download axon binary + name: Download_and_Start_Axon_Sync needs: Build_and_Archive_Axon - runs-on: ${{ matrix.os }} + runs-on: layer2-runner + steps: - name: Download Axon Binary for Build_and_Archive_Axon uses: actions/download-artifact@v3 with: name: axon-dir - - name: Start a single Axon node + - name: Replacement configuration + run: | + sed -i 's@bls_privkey_file = "bls.key"@bls_privkey_file = "nodes/node_1_bls.key"@g' devtools/chain/config.toml + sed -i 's@net_privkey_file = "net.key"@net_privkey_file = "nodes/node_1_net.key"@g' devtools/chain/config.toml + sed -i 's@multi_address = "/ip4/127.0.0.1/tcp/8001/p2p/QmNk6bBwkLPuqnsrtxpp819XLZY3ymgjs3p1nKtxBVgqxj"@multi_address = "/dns4/axon1.axon-alphanet.svc.cluster.local/tcp/8001/p2p/QmNk6bBwkLPuqnsrtxpp819XLZY3ymgjs3p1nKtxBVgqxj"@' devtools/chain/config.toml + + - name: Start Axon Node env: - LOG_FILE: ${{ runner.temp }}/${{ matrix.os }}-single-axon-node.log + LOG_FILE: ${{ runner.temp }}/layer2-runner-axon-node.log run: | - target/debug/axon --version | tee ${{ env.LOG_FILE }} - target/debug/axon init \ - --config devtools/chain/config.toml \ - --chain-spec devtools/chain/specs/single_node/chain-spec.toml \ - | tee -a ${{ env.LOG_FILE }} - target/debug/axon run \ - --config devtools/chain/config.toml \ - | tee -a ${{ env.LOG_FILE }} & - timeout-minutes: 1 + chmod +x target/debug/axon + target/debug/axon --version + target/debug/axon init \ + --config devtools/chain/config.toml \ + --chain-spec devtools/chain/specs/single_node/chain-spec.toml + + target/debug/axon run \ + --config devtools/chain/config.toml + - - name: Archive logs - if: failure() - uses: actions/upload-artifact@v3 - with: - name: single-axon-node-logs - path: | - ${{ runner.temp }}/${{ matrix.os }}-single-axon-node.log \ No newline at end of file From b6f3ad4664d3d37deff7dbef5958d09b104ea05f Mon Sep 17 00:00:00 2001 From: Simon <96721494+Simon-Tl@users.noreply.github.com> Date: Wed, 29 Nov 2023 20:40:47 +0800 Subject: [PATCH 3/6] ci: add push as the trigger condition Co-authored-by: Flouse <1297478+Flouse@users.noreply.github.com> --- .github/workflows/axon-sync-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/axon-sync-test.yml b/.github/workflows/axon-sync-test.yml index 26b48fdd4..27c720222 100644 --- a/.github/workflows/axon-sync-test.yml +++ b/.github/workflows/axon-sync-test.yml @@ -2,6 +2,8 @@ name: Axon sync test on: workflow_dispatch: + # TODO: remove push event when this workflow is stable + push: jobs: Build_and_Archive_Axon: From a8471632a27885d2e91b6da7d5552d25fd6bad9c Mon Sep 17 00:00:00 2001 From: Simon-Tl Date: Wed, 29 Nov 2023 20:45:44 +0800 Subject: [PATCH 4/6] ci: add status monitoring and notification --- .github/workflows/axon-sync-test.yml | 88 +++++++++++++++++++++++++--- 1 file changed, 80 insertions(+), 8 deletions(-) diff --git a/.github/workflows/axon-sync-test.yml b/.github/workflows/axon-sync-test.yml index 27c720222..98e804963 100644 --- a/.github/workflows/axon-sync-test.yml +++ b/.github/workflows/axon-sync-test.yml @@ -2,8 +2,7 @@ name: Axon sync test on: workflow_dispatch: - # TODO: remove push event when this workflow is stable - push: + push: jobs: Build_and_Archive_Axon: @@ -48,13 +47,14 @@ jobs: devtools/chain/default.db-options devtools/chain/config.toml devtools/chain/nodes/node_1* + devtools/ci/scripts/helper.js retention-days: 7 Download_and_Start_Axon_Sync: name: Download_and_Start_Axon_Sync needs: Build_and_Archive_Axon - runs-on: layer2-runner + runs-on: layer2-runners steps: - name: Download Axon Binary for Build_and_Archive_Axon @@ -65,7 +65,7 @@ jobs: run: | sed -i 's@bls_privkey_file = "bls.key"@bls_privkey_file = "nodes/node_1_bls.key"@g' devtools/chain/config.toml sed -i 's@net_privkey_file = "net.key"@net_privkey_file = "nodes/node_1_net.key"@g' devtools/chain/config.toml - sed -i 's@multi_address = "/ip4/127.0.0.1/tcp/8001/p2p/QmNk6bBwkLPuqnsrtxpp819XLZY3ymgjs3p1nKtxBVgqxj"@multi_address = "/dns4/axon1.axon-alphanet.svc.cluster.local/tcp/8001/p2p/QmNk6bBwkLPuqnsrtxpp819XLZY3ymgjs3p1nKtxBVgqxj"@' devtools/chain/config.toml + sed -i 's@multi_address = "/ip4/127.0.0.1/tcp/8001/p2p/QmNk6bBwkLPuqnsrtxpp819XLZY3ymgjs3p1nKtxBVgqxj"@multi_address = "/dns4/axon1/tcp/8001/p2p/QmNk6bBwkLPuqnsrtxpp819XLZY3ymgjs3p1nKtxBVgqxj"@' devtools/chain/config.toml - name: Start Axon Node env: @@ -75,10 +75,82 @@ jobs: target/debug/axon --version target/debug/axon init \ --config devtools/chain/config.toml \ - --chain-spec devtools/chain/specs/single_node/chain-spec.toml + --chain-spec devtools/chain/specs/single_node/chain-spec.toml - target/debug/axon run \ - --config devtools/chain/config.toml + nohup target/debug/axon run \ + --config devtools/chain/config.toml & + - name: Wati for App to Start + run: sleep 10 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '14' + + - name: Install dependencies + run: | + npm install -g zx + + - name: Compare Block Heights + run: | + npx zx <<'EOF' + #!/usr/bin/env zx + import { getLatestBlockNum } from './devtools/ci/scripts/helper.js' + + async function main() { + let previousLocalHeight = null; + + while (true) { + const localhostHeight = await getLatestBlockNum('http://127.0.0.1:8000'); + const remoteHeight = await getLatestBlockNum('https://rpc-alphanet-axon.ckbapp.dev'); + console.log("localBlockNumber:" + localhostHeight, "remoteBlockNumber:"+ remoteHeight) + + if (localhostHeight === remoteHeight - 10) { + console.log("localBlockNumber:" + localhostHeight, "remoteBlockNumber:"+ remoteHeight, "localnode sync succeeded" ); + process.exit(0); + } else if (localhostHeight === previousLocalHeight) { + console.error("synchronization exception localBlockNumber:" + localhostHeight); + process.exit(1); + } + previousLocalHeight = localhostHeight; + await new Promise(resolve => setTimeout(resolve, 600000)); + } + } + main(); + EOF + + notice: + runs-on: ubuntu-latest + needs: Download_and_Start_Axon_Sync + if: success() || failure() + steps: + - name: send Axon-sync-test status + run: | + curl -H "Content-Type: application/json" \ + -X POST https://discord.com/api/webhooks/${{secrets.DISCORD_CHANNEL_ID}}/${{secrets.DISCORD_CHANNEL_TOKEN}} \ + --data ' + { + "content": "Axon-sync-test", + "embeds": [ + { + "title":"Contract Test Status", + "color": 5814789, + "fields": [ + { + "name": "Job name", + "value": "axon-sync-test\n" + }, + { "name": "Job statues", + "value": "${{needs.Download_and_Start_Axon_Sync.result}}\n" + }, + { + "name": "URL", + "value": "[Click and jump to Github workflow](https://github.com/Simon-Tl/axon/actions/workflows/axon-sync-test.yml)\n" + } + + ] + } + ] + }' - \ No newline at end of file From e06a1bdc1d9edd7f8f82e4b41d6b88716d088b7a Mon Sep 17 00:00:00 2001 From: Simon-Tl Date: Wed, 29 Nov 2023 20:48:19 +0800 Subject: [PATCH 5/6] ci: change the workflow url and notification title --- .github/workflows/axon-sync-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/axon-sync-test.yml b/.github/workflows/axon-sync-test.yml index 98e804963..bf1d65b67 100644 --- a/.github/workflows/axon-sync-test.yml +++ b/.github/workflows/axon-sync-test.yml @@ -134,7 +134,7 @@ jobs: "content": "Axon-sync-test", "embeds": [ { - "title":"Contract Test Status", + "title":"Axon sync test Status", "color": 5814789, "fields": [ { @@ -146,7 +146,7 @@ jobs: }, { "name": "URL", - "value": "[Click and jump to Github workflow](https://github.com/Simon-Tl/axon/actions/workflows/axon-sync-test.yml)\n" + "value": "[Click and jump to Github workflow](https://github.com/axonweb3/axon/actions/workflows/axon-sync-test.yml)\n" } ] From d76fa2322bfee21f02441e71bd0227fa3d600c0e Mon Sep 17 00:00:00 2001 From: Simon-Tl Date: Mon, 4 Dec 2023 13:53:23 +0800 Subject: [PATCH 6/6] ci:optimize logic, format code --- .github/workflows/axon-sync-test.yml | 67 +++++++++++++++------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/.github/workflows/axon-sync-test.yml b/.github/workflows/axon-sync-test.yml index bf1d65b67..44bdb5570 100644 --- a/.github/workflows/axon-sync-test.yml +++ b/.github/workflows/axon-sync-test.yml @@ -2,7 +2,7 @@ name: Axon sync test on: workflow_dispatch: - push: + push: jobs: Build_and_Archive_Axon: @@ -36,17 +36,20 @@ jobs: lscpu # PORTABLE=1 USE_SSE=1 tell rocksdb to target AVX2 PORTABLE=1 USE_SSE=1 cargo build - + - name: Generate Key + run: | + openssl rand -hex 32 |xxd -p -r > devtools/chain/net.key + cargo run --package axon-keypair --bin axon-keypair | jq '.keypairs[0].private_key' | xxd -p -r > devtools/chain/bls.key - name: Archive axon artifacts uses: actions/upload-artifact@v3 with: name: axon-dir path: | target/debug/axon - devtools/chain/specs/single_node/chain-spec.toml + devtools/chain/specs/multi_nodes/chain-spec.toml devtools/chain/default.db-options devtools/chain/config.toml - devtools/chain/nodes/node_1* + devtools/chain/*.key devtools/ci/scripts/helper.js retention-days: 7 @@ -55,6 +58,7 @@ jobs: name: Download_and_Start_Axon_Sync needs: Build_and_Archive_Axon runs-on: layer2-runners + timeout-minutes: 1800 steps: - name: Download Axon Binary for Build_and_Archive_Axon @@ -63,9 +67,9 @@ jobs: name: axon-dir - name: Replacement configuration run: | - sed -i 's@bls_privkey_file = "bls.key"@bls_privkey_file = "nodes/node_1_bls.key"@g' devtools/chain/config.toml - sed -i 's@net_privkey_file = "net.key"@net_privkey_file = "nodes/node_1_net.key"@g' devtools/chain/config.toml sed -i 's@multi_address = "/ip4/127.0.0.1/tcp/8001/p2p/QmNk6bBwkLPuqnsrtxpp819XLZY3ymgjs3p1nKtxBVgqxj"@multi_address = "/dns4/axon1/tcp/8001/p2p/QmNk6bBwkLPuqnsrtxpp819XLZY3ymgjs3p1nKtxBVgqxj"@' devtools/chain/config.toml + sed -i 's@hardforks = \[\]@hardforks = \["None"\]@g' devtools/chain/specs/multi_nodes/chain-spec.toml + - name: Start Axon Node env: @@ -75,50 +79,54 @@ jobs: target/debug/axon --version target/debug/axon init \ --config devtools/chain/config.toml \ - --chain-spec devtools/chain/specs/single_node/chain-spec.toml + --chain-spec devtools/chain/specs/multi_nodes/chain-spec.toml nohup target/debug/axon run \ --config devtools/chain/config.toml & - name: Wati for App to Start - run: sleep 10 + run: sleep 15 - name: Setup Node.js uses: actions/setup-node@v3 with: - node-version: '14' + node-version: '20' - - name: Install dependencies - run: | - npm install -g zx - - name: Compare Block Heights run: | npx zx <<'EOF' #!/usr/bin/env zx - import { getLatestBlockNum } from './devtools/ci/scripts/helper.js' + import { getLatestBlockNum } from './devtools/ci/scripts/helper.js'; async function main() { let previousLocalHeight = null; while (true) { - const localhostHeight = await getLatestBlockNum('http://127.0.0.1:8000'); - const remoteHeight = await getLatestBlockNum('https://rpc-alphanet-axon.ckbapp.dev'); - console.log("localBlockNumber:" + localhostHeight, "remoteBlockNumber:"+ remoteHeight) - - if (localhostHeight === remoteHeight - 10) { - console.log("localBlockNumber:" + localhostHeight, "remoteBlockNumber:"+ remoteHeight, "localnode sync succeeded" ); - process.exit(0); - } else if (localhostHeight === previousLocalHeight) { - console.error("synchronization exception localBlockNumber:" + localhostHeight); - process.exit(1); + const localHeight = await getLatestBlockNum('http://127.0.0.1:8000'); + const remoteHeight = await getLatestBlockNum('https://rpc-alphanet-axon.ckbapp.dev'); + + console.log(`localBlockNumber: ${localHeight}, remoteBlockNumber: ${remoteHeight}`); + + if (localHeight >= remoteHeight - 10 && localHeight <= remoteHeight) { + console.log(`localBlockNumber: ${localHeight}, remoteBlockNumber: ${remoteHeight}, localnode sync succeeded`); + return process.exit(0); + } + + if (localHeight === previousLocalHeight) { + console.error(`synchronization exception localBlockNumber: ${localHeight}`); + return process.exit(1); + } + + previousLocalHeight = localHeight; + await new Promise(resolve => setTimeout(resolve, 600000)); } - previousLocalHeight = localhostHeight; - await new Promise(resolve => setTimeout(resolve, 600000)); - } } + main(); EOF + timeout-minutes: 1800 + + notice: runs-on: ubuntu-latest @@ -134,7 +142,7 @@ jobs: "content": "Axon-sync-test", "embeds": [ { - "title":"Axon sync test Status", + "title":"Axon Sync test Status", "color": 5814789, "fields": [ { @@ -146,8 +154,7 @@ jobs: }, { "name": "URL", - "value": "[Click and jump to Github workflow](https://github.com/axonweb3/axon/actions/workflows/axon-sync-test.yml)\n" - } + "value": "[Click and jump to Github workflow](https://github.com/axonweb3/axon/actions/workflows/axon-sync-test.yml)\n" } ] }