From 78b81116c5845554b92bd1f2cd47bd2cb8b563e0 Mon Sep 17 00:00:00 2001
From: lklimek <842586+lklimek@users.noreply.github.com>
Date: Wed, 30 Mar 2022 12:30:42 +0200
Subject: [PATCH] refactor(ci): move bls CI code to a separate action and
 improve ARM build (#314)

* refactor(ci): move bls CI code to a separate action

* fix(ci): e2e testnet matrix is invalid

* chore(ci): whitespace fix
---
 .github/actions/bls/action.yml |  53 ++++++++++++++++
 .github/workflows/build.yml    |  60 +++++-------------
 .github/workflows/e2e.yml      | 112 ++++-----------------------------
 .github/workflows/lint.yml     |  55 ++--------------
 .github/workflows/tests.yml    |  41 +-----------
 Makefile                       |  15 +++--
 docs/introduction/install.md   |  41 +++++++-----
 7 files changed, 122 insertions(+), 255 deletions(-)
 create mode 100644 .github/actions/bls/action.yml

diff --git a/.github/actions/bls/action.yml b/.github/actions/bls/action.yml
new file mode 100644
index 0000000000..074bba050e
--- /dev/null
+++ b/.github/actions/bls/action.yml
@@ -0,0 +1,53 @@
+---
+name: BLS
+description: Build and install BLS library. Assumes the caller did actions/setup-go and actions-checkout.
+inputs:
+  arch:
+    description: "Target architecture, one of: amd64 arm"
+    default: amd64
+    required: false
+outputs:
+  bls_cache_key: 
+    description: Key used by BLS cache
+    value: ${{ runner.os }}-${{ inputs.arch }}-bls-${{ steps.bls-revision.outputs.hash }}
+runs:
+  using: composite
+  steps:
+    - uses: actions/setup-go@v2
+      with:
+        go-version: "1.17"
+    - uses: actions/checkout@v2
+      with:
+        submodules: true
+    - name: Get BLS library revision
+      id: bls-revision
+      run: |
+        echo "::set-output name=hash::$(git --git-dir=third_party/bls-signatures/src/.git rev-parse HEAD)"
+      shell: bash
+    - uses: actions/cache@v2
+      id: bls-cache
+      with:
+        path: ~/bls-cache
+        key: ${{ runner.os }}-${{ inputs.arch }}-bls-${{ steps.bls-revision.outputs.hash }}
+    - name: Build BLS library
+      run: make install-bls
+      if: steps.bls-cache.outputs.cache-hit != 'true'
+      shell: bash
+    - name: Save BLS library
+      run: |
+        mkdir -p ~/bls-cache/include
+        cp -vr /usr/local/include/chiabls ~/bls-cache/include
+        cp -vr /usr/local/include/relic* ~/bls-cache/include
+        cp -v /usr/local/lib/libchiabls.a ~/bls-cache/
+      if: steps.bls-cache.outputs.cache-hit != 'true'
+      shell: bash
+    - uses: actions/cache@v2.1.2
+      with:
+        path: ~/bls-cache
+        key: ${{ runner.os }}-${{ inputs.arch }}-bls-${{ steps.bls-revision.outputs.hash }}
+      if: steps.bls-cache.outputs.cache-hit != 'true'
+    - name: Install BLS library
+      run: |
+        sudo cp -vr ~/bls-cache/include/* /usr/local/include/
+        sudo cp -vr ~/bls-cache/libchiabls.a /usr/local/lib/
+      shell: bash
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index c039d90fb9..ca1e5656a9 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -12,42 +12,6 @@ on:
       - v0.*-dev
 
 jobs:
-  bls-signatures:
-    runs-on: ubuntu-latest
-    timeout-minutes: 5
-    steps:
-      - uses: actions/setup-go@v2
-        with:
-          go-version: "^1.17"
-      - uses: actions/checkout@v2
-        with:
-          submodules: true
-      - name: Get BLS library revision
-        id: bls-revision
-        run: |
-          echo "::set-output name=hash::$(git --git-dir=third_party/bls-signatures/src/.git rev-parse HEAD)"
-        shell: bash
-      - uses: actions/cache@v2
-        id: bls-cache
-        with:
-          path: ~/bls-cache
-          key: ${{ runner.os }}-bls-${{ steps.bls-revision.outputs.hash }}
-      - name: Build BLS library
-        run: make install-bls
-        if: steps.bls-cache.outputs.cache-hit != 'true'
-      - name: Save BLS library
-        run: |
-          mkdir -p ~/bls-cache/include
-          cp -vr /usr/local/include/chiabls ~/bls-cache/include
-          cp -vr /usr/local/include/relic* ~/bls-cache/include
-          cp -v /usr/local/lib/libchiabls.a ~/bls-cache/
-        if: steps.bls-cache.outputs.cache-hit != 'true'
-      - uses: actions/cache@v2.1.2
-        with:
-          path: ~/bls-cache
-          key: ${{ runner.os }}-bls-${{ steps.bls-revision.outputs.hash }}
-        if: steps.bls-cache.outputs.cache-hit != 'true'
-
   build:
     name: Build
     runs-on: ubuntu-latest
@@ -70,9 +34,19 @@ jobs:
             go.mod
             go.sum
             Makefile
+      - uses: ./.github/actions/bls
+        name: Install BLS library
+        if: "env.GIT_DIFF != ''"
+        with:
+          arch: ${{ matrix.goarch }}
+      - name: install-gcc
+        run: sudo apt-get update -qq && sudo apt-get install -qq --yes gcc-10-arm-linux-gnueabi g++-10-arm-linux-gnueabi
+        if: "matrix.goarch == 'arm'"        
       - name: install
-        run: GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} make build
+        run: |
+          GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} make build-binary
         if: "env.GIT_DIFF != ''"
+        shell: bash
 
   test_abci_cli:
     runs-on: ubuntu-latest
@@ -111,15 +85,9 @@ jobs:
             **/**.go
             go.mod
             go.sum
-
-      - uses: actions/cache@v2
-        with:
-          path: ~/bls-cache
-          key: ${{ runner.os }}-bls-${{ steps.bls-revision.outputs.hash }}
-      - name: Install BLS library
-        run: |
-          sudo cp -vr ~/bls-cache/include/* /usr/local/include/
-          sudo cp -vr ~/bls-cache/libchiabls.a /usr/local/lib/
+      - uses: ./.github/actions/bls
+        name: Install BLS library
+        if: "env.GIT_DIFF != ''"
       - name: install
         run: make install install_abci
         if: "env.GIT_DIFF != ''"
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
index 2e74bace1f..8fa8fa6184 100644
--- a/.github/workflows/e2e.yml
+++ b/.github/workflows/e2e.yml
@@ -10,45 +10,12 @@ on:
       - release/**
 
 jobs:
-  bls-signatures:
+  e2e-test:
     runs-on: ubuntu-latest
-    timeout-minutes: 5
-    steps:
-      - uses: actions/setup-go@v2
-        with:
-          go-version: "1.17"
-      - uses: actions/checkout@v2
-        with:
-          submodules: true
-      - name: Get BLS library revision
-        id: bls-revision
-        run: |
-          echo "::set-output name=hash::$(git --git-dir=third_party/bls-signatures/src/.git rev-parse HEAD)"
-        shell: bash
-      - uses: actions/cache@v2
-        id: bls-cache
-        with:
-          path: ~/bls-cache
-          key: ${{ runner.os }}-bls-${{ steps.bls-revision.outputs.hash }}
-      - name: Build BLS library
-        run: make install-bls
-        if: steps.bls-cache.outputs.cache-hit != 'true'
-      - name: Save BLS library
-        run: |
-          mkdir -p ~/bls-cache/include
-          cp -vr /usr/local/include/chiabls ~/bls-cache/include
-          cp -vr /usr/local/include/relic* ~/bls-cache/include
-          cp -v /usr/local/lib/libchiabls.a ~/bls-cache/
-        if: steps.bls-cache.outputs.cache-hit != 'true'
-      - uses: actions/cache@v2.1.2
-        with:
-          path: ~/bls-cache
-          key: ${{ runner.os }}-bls-${{ steps.bls-revision.outputs.hash }}
-        if: steps.bls-cache.outputs.cache-hit != 'true'
-
-  e2e-test-dashcore:
-    runs-on: ubuntu-latest
-    needs: bls-signatures
+    strategy:
+      fail-fast: true
+      matrix:
+        testnet: [ "dashcore", "rotate" ]
     timeout-minutes: 25
     env:
       FULLNODE_PUBKEY_KEEP: false
@@ -59,85 +26,30 @@ jobs:
       - uses: actions/checkout@v2.3.4
         with:
           submodules: true
-      - name: Get BLS library revision
-        id: bls-revision
-        run: |
-          echo "::set-output name=hash::$(git --git-dir=third_party/bls-signatures/src/.git rev-parse HEAD)"
-        shell: bash
       - uses: technote-space/get-diff-action@v5
         with:
           PATTERNS: |
             **/**.go
             go.mod
             go.sum
-      - uses: actions/cache@v2
-        with:
-          path: ~/bls-cache
-          key: ${{ runner.os }}-bls-${{ steps.bls-revision.outputs.hash }}
-      - name: Install BLS library
-        run: |
-          sudo cp -vr ~/bls-cache/include/* /usr/local/include/
-          sudo cp -vr ~/bls-cache/libchiabls.a /usr/local/lib/
-      - name: Build
-        working-directory: test/e2e
-        # Run two make jobs in parallel, since we can't run steps in parallel.
-        run: make -j2 docker runner tests
-        if: "env.GIT_DIFF != ''"
 
-      - name: Run CI dashcore testnet
-        working-directory: test/e2e
-        run: ./run-multiple.sh networks/dashcore.toml
+      - uses: ./.github/actions/bls
+        name: Install BLS library
         if: "env.GIT_DIFF != ''"
 
-      - name: Emit dashcore logs on failure
-        if: ${{ failure() }}
-        working-directory: test/e2e
-        run: ./build/runner -f networks/dashcore.toml logs
-
-  e2e-test-rotate:
-    runs-on: ubuntu-latest
-    needs: bls-signatures
-    timeout-minutes: 35
-    env:
-      FULLNODE_PUBKEY_KEEP: false
-    steps:
-      - uses: actions/setup-go@v2
-        with:
-          go-version: '1.17'
-      - uses: actions/checkout@v2.3.4
-        with:
-          submodules: true
-      - name: Get BLS library revision
-        id: bls-revision
-        run: |
-          echo "::set-output name=hash::$(git --git-dir=third_party/bls-signatures/src/.git rev-parse HEAD)"
-        shell: bash
-      - uses: technote-space/get-diff-action@v5.0.2
-        with:
-          PATTERNS: |
-            **/**.go
-            go.mod
-            go.sum
-      - uses: actions/cache@v2
-        with:
-          path: ~/bls-cache
-          key: ${{ runner.os }}-bls-${{ steps.bls-revision.outputs.hash }}
-      - name: Install BLS library
-        run: |
-          sudo cp -vr ~/bls-cache/include/* /usr/local/include/
-          sudo cp -vr ~/bls-cache/libchiabls.a /usr/local/lib/
       - name: Build
         working-directory: test/e2e
         # Run two make jobs in parallel, since we can't run steps in parallel.
         run: make -j2 docker runner tests
         if: "env.GIT_DIFF != ''"
 
-      - name: Run CI rotate testnet
+      - name: Run CI ${{ matrix.testnet }} testnet
         working-directory: test/e2e
-        run: ./run-multiple.sh networks/rotate.toml
+        run: ./run-multiple.sh networks/${{ matrix.testnet }}.toml
         if: "env.GIT_DIFF != ''"
 
-      - name: Emit rotate logs on failure
+      - name: Emit ${{ matrix.testnet }} logs on failure
         if: ${{ failure() }}
         working-directory: test/e2e
-        run: ./build/runner -f networks/rotate.toml logs
+        run: ./build/runner -f networks/${{ matrix.testnet }}.toml logs
+
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 8d89f1cbfa..99cec9e979 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -8,70 +8,25 @@ on:
     branches:
       - master
 jobs:
-  bls-signatures:
-    runs-on: ubuntu-latest
-    timeout-minutes: 5
-    steps:
-      - uses: actions/setup-go@v2
-        with:
-          go-version: "^1.15.5"
-      - uses: actions/checkout@v2
-        with:
-          submodules: true
-      - name: Get BLS library revision
-        id: bls-revision
-        run: |
-          echo "::set-output name=hash::$(git --git-dir=third_party/bls-signatures/src/.git rev-parse HEAD)"
-        shell: bash
-      - uses: actions/cache@v2
-        id: bls-cache
-        with:
-          path: ~/bls-cache
-          key: ${{ runner.os }}-bls-${{ steps.bls-revision.outputs.hash }}
-      - name: Build BLS library
-        run: make install-bls
-        if: steps.bls-cache.outputs.cache-hit != 'true'
-      - name: Save BLS library
-        run: |
-          mkdir -p ~/bls-cache/include
-          cp -vr /usr/local/include/chiabls ~/bls-cache/include
-          cp -vr /usr/local/include/relic* ~/bls-cache/include
-          cp -v /usr/local/lib/libchiabls.a ~/bls-cache/
-        if: steps.bls-cache.outputs.cache-hit != 'true'
-      - uses: actions/cache@v2.1.2
-        with:
-          path: ~/bls-cache
-          key: ${{ runner.os }}-bls-${{ steps.bls-revision.outputs.hash }}
-        if: steps.bls-cache.outputs.cache-hit != 'true'
-
   golangci:
     name: golangci-lint
     runs-on: ubuntu-latest
-    needs: bls-signatures
     timeout-minutes: 8
     steps:
       - uses: actions/checkout@v2.4.0
         with:
           submodules: true
-      - name: Get BLS library revision
-        id: bls-revision
-        run: |
-          echo "::set-output name=hash::$(git --git-dir=third_party/bls-signatures/src/.git rev-parse HEAD)"
-        shell: bash
       - uses: technote-space/get-diff-action@v5
         with:
           PATTERNS: |
             **/**.go
             go.mod
             go.sum
-      - uses: actions/cache@v2
-        with:
-          path: ~/bls-cache
-          key: ${{ runner.os }}-bls-${{ steps.bls-revision.outputs.hash }}
-      - name: Install BLS library
-        run: |
-          sudo cp -vr ~/bls-cache/include/* /usr/local/include/
-          sudo cp -vr ~/bls-cache/libchiabls.a /usr/local/lib/
+
+      - uses: ./.github/actions/bls
+        name: Install BLS library
+        if: "env.GIT_DIFF != ''"
+
       - uses: golangci/golangci-lint-action@v2.5.2
         with:
           # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 48f7d65a16..dbf676e780 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -9,44 +9,6 @@ on:
       - release/**
        - v0.*-dev
 jobs:
-  bls-signatures:
-    runs-on: ubuntu-latest
-    timeout-minutes: 5
-    steps:
-      - uses: actions/setup-go@v2
-        with:
-          go-version: "1.17"
-      - uses: actions/checkout@v2
-        with:
-          submodules: true
-      - name: Get BLS library revision
-        id: bls-revision
-        run: |
-          echo "::set-output name=hash::$(git --git-dir=third_party/bls-signatures/src/.git rev-parse HEAD)"
-        shell: bash
-      - uses: actions/cache@v2
-        id: bls-cache
-        with:
-          path: ~/bls-cache
-          key: ${{ runner.os }}-bls-${{ steps.bls-revision.outputs.hash }}
-      - name: Build BLS library
-        run: make install-bls
-        if: steps.bls-cache.outputs.cache-hit != 'true'
-      - name: Save BLS library
-        run: |
-          mkdir -p ~/bls-cache/include
-          cp -vr /usr/local/include/chiabls ~/bls-cache/include
-          cp -vr /usr/local/include/relic* ~/bls-cache/include
-          cp -v /usr/local/lib/libchiabls.a ~/bls-cache/
-        if: steps.bls-cache.outputs.cache-hit != 'true'
-      - uses: actions/cache@v2.1.2
-        with:
-          path: ~/bls-cache
-          key: ${{ runner.os }}-bls-${{ steps.bls-revision.outputs.hash }}
-        if: steps.bls-cache.outputs.cache-hit != 'true'
-
-  build:
-    name: Build
   tests:
     runs-on: ubuntu-latest
     strategy:
@@ -66,6 +28,9 @@ jobs:
             go.mod
             go.sum
             Makefile
+      - uses: ./.github/actions/bls
+        name: Install BLS library
+        if: "env.GIT_DIFF != ''"
       - name: Run Go Tests
         run: |
           make test-group-${{ matrix.part }} NUM_SPLIT=4
diff --git a/Makefile b/Makefile
index 17ee080583..6f3377c7d0 100644
--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,12 @@ BASE_BRANCH := v0.8-dev
 DOCKER_PROTO := docker run -v $(shell pwd):/workspace --workdir /workspace $(BUILD_IMAGE)
 CGO_ENABLED ?= 1
 
+# handle ARM builds
+ifeq (arm,$(GOARCH))
+	export CC = arm-linux-gnueabi-gcc-10
+	export CXX = arm-linux-gnueabi-g++-10
+endif
+
 # handle nostrip
 ifeq (,$(findstring nostrip,$(TENDERMINT_BUILD_OPTIONS)))
   BUILD_FLAGS += -trimpath
@@ -63,8 +69,9 @@ endif
 # allow users to pass additional flags via the conventional LDFLAGS variable
 LD_FLAGS += $(LDFLAGS)
 
-all: check build test install
-build: build-bls
+all: build install
+build: build-bls build-binary
+.PHONY: build
 install: install-bls
 
 .PHONY: all
@@ -87,9 +94,9 @@ install-bls: build-bls
 ###                                Build Tendermint                        ###
 ###############################################################################
 
-build:
+build-binary:
 	CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o $(OUTPUT) ./cmd/tenderdash/
-.PHONY: build
+.PHONY: build-binary
 
 install:
 	CGO_ENABLED=$(CGO_ENABLED) go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/tenderdash
diff --git a/docs/introduction/install.md b/docs/introduction/install.md
index b0e57cf39f..01b8464ae8 100644
--- a/docs/introduction/install.md
+++ b/docs/introduction/install.md
@@ -2,19 +2,11 @@
 order: 3
 ---
 
-# Install Tendermint
+# Install Tenderdash
 
 ## From Binary
 
-To download pre-built binaries, see the [releases page](https://github.com/tendermint/tendermint/releases).
-
-## Using Homebrew
-
-You can also install the Tendermint binary by simply using homebrew,
-
-```
-brew install tendermint
-```
+To download pre-built binaries, see the [releases page](https://github.com/dashevo/tenderdash/releases).
 
 ## From Source
 
@@ -29,8 +21,8 @@ echo export PATH=\"\$PATH:\$GOPATH/bin\" >> ~/.bash_profile
 Get the source code:
 
 ```sh
-git clone https://github.com/tendermint/tendermint.git
-cd tendermint
+git clone https://github.com/dashevo/tenderdash.git
+cd tenderdash
 ```
 
 Then run:
@@ -47,18 +39,33 @@ make build
 
 to put the binary in `./build`.
 
-_DISCLAIMER_ The binary of Tendermint is build/installed without the DWARF
-symbol table. If you would like to build/install Tendermint with the DWARF
+_DISCLAIMER_ The binary of Tenderdash is build/installed without the DWARF
+symbol table. If you would like to build/install Tenderdash with the DWARF
 symbol and debug information, remove `-s -w` from `BUILD_FLAGS` in the make
 file.
 
-The latest Tendermint is now installed. You can verify the installation by
+The latest Tenderdash is now installed. You can verify the installation by
 running:
 
 ```sh
 tendermint version
 ```
 
+
+### Cross-compilation
+
+To cross-compile for ARM platform, you need to install required compilers. On Ubuntu 20.04+:
+
+```bash
+sudo apt-get install gcc-10-arm-linux-gnueabi g++-10-arm-linux-gnueabi
+```
+
+To start the build process, execute:
+
+```bash
+GOOS=linux GOARCH=arm  make
+```
+
 ## Run
 
 To start a one-node blockchain with a simple in-process application:
@@ -70,7 +77,7 @@ tendermint start --proxy-app=kvstore
 
 ## Reinstall
 
-If you already have Tendermint installed, and you make updates, simply
+If you already have Tenderdash installed, and you make updates, simply
 
 ```sh
 make install
@@ -113,7 +120,7 @@ Set a database backend to `cleveldb`:
 db_backend = "cleveldb"
 ```
 
-To install Tendermint, run:
+To install Tenderdash, run:
 
 ```sh
 CGO_LDFLAGS="-lsnappy" make install TENDERMINT_BUILD_OPTIONS=cleveldb