diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..a5db7d3 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @kpachhai \ No newline at end of file diff --git a/.github/actions/install-go/action.yml b/.github/actions/install-go/action.yml new file mode 100644 index 0000000..753cb86 --- /dev/null +++ b/.github/actions/install-go/action.yml @@ -0,0 +1,25 @@ +# Copyright (C) 2023, AllianceBlock. All rights reserved. +# See the file LICENSE for licensing terms. + +name: 'Install Go toolchain with defaults' +description: 'Install a go toolchain with defaults' + +inputs: + cache: + description: 'to cache or not to cache, that is the question' + required: false + default: 'true' + cache-dependency-path: + description: 'forwards go actions/setup-go' + required: false + +runs: + using: composite + steps: + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.21' + check-latest: true + cache: ${{ inputs.cache }} + cache-dependency-path: ${{ inputs.cache-dependency-path }} diff --git a/.github/actions/nuklai-wallet-release/action.yml b/.github/actions/nuklai-wallet-release/action.yml new file mode 100644 index 0000000..6992fbe --- /dev/null +++ b/.github/actions/nuklai-wallet-release/action.yml @@ -0,0 +1,25 @@ +# Copyright (C) 2023, AllianceBlock. All rights reserved. +# See the file LICENSE for licensing terms. + +name: 'Release Nuklai Wallet' +description: 'Release the Nuklai Wallet' + +runs: + using: composite + steps: + - name: Set up Go + uses: ./.github/actions/install-go + with: + cache-dependency-path: | + go.sum + - name: Build wallet + working-directory: ./cmd/nuklai-wallet + shell: bash + run: scripts/build.sh + env: + PUBLISH: 'false' + - name: Archive Builds + uses: actions/upload-artifact@v4 + with: + name: nuklai-wallet + path: ./cmd/nuklai-wallet/nuklai-wallet.zip diff --git a/.github/actions/vm-release/action.yml b/.github/actions/vm-release/action.yml new file mode 100644 index 0000000..ad839eb --- /dev/null +++ b/.github/actions/vm-release/action.yml @@ -0,0 +1,55 @@ +# Copyright (C) 2023, AllianceBlock. All rights reserved. +# See the file LICENSE for licensing terms. + +name: 'Release VM' +description: 'Release the VM' + +inputs: + vm-name: + description: 'NuklaiVM' + required: true + github-token: + description: 'GitHub Token' + required: true + +runs: + using: composite + steps: + - name: Set up Go + uses: ./.github/actions/install-go + with: + cache-dependency-path: | + go.sum + examples/${{ inputs.vm-name }}/go.sum + - name: Set up arm64 cross compiler + shell: bash + run: | + sudo apt-get -y update + sudo apt-get -y install gcc-aarch64-linux-gnu + - name: Checkout osxcross + uses: actions/checkout@v2 + with: + repository: tpoechtrager/osxcross + path: osxcross + - name: Build osxcross + shell: bash + run: | + sudo apt-get -y install clang llvm-dev libxml2-dev uuid-dev libssl-dev bash patch make tar xz-utils bzip2 gzip sed cpio libbz2-dev + cd osxcross + wget https://github.com/joseluisq/macosx-sdks/releases/download/12.3/$MACOS_SDK_FNAME -O tarballs/$MACOS_SDK_FNAME + echo $MACOS_SDK_CHECKSUM tarballs/$MACOS_SDK_FNAME | sha256sum -c - + UNATTENDED=1 ./build.sh + echo $PWD/target/bin >> $GITHUB_PATH + env: + MACOS_SDK_FNAME: MacOSX12.3.sdk.tar.xz + MACOS_SDK_CHECKSUM: 3abd261ceb483c44295a6623fdffe5d44fc4ac2c872526576ec5ab5ad0f6e26c + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + distribution: goreleaser + version: latest + args: release + workdir: ./examples/${{ inputs.vm-name }}/ + env: + # https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret + GITHUB_TOKEN: ${{ inputs.github-token }} diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..fb8cfd5 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,78 @@ +# Copyright (C) 2023, AllianceBlock. All rights reserved. +# See the file LICENSE for licensing terms. + +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: 'CodeQL' + +on: + push: + branches: ['main'] + pull_request: + # The branches below must be a subset of the branches above + branches: ['main'] + schedule: + - cron: '41 18 * * 3' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ['go'] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + queries: security-extended,security-and-quality + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true diff --git a/.github/workflows/load-tests.yml b/.github/workflows/load-tests.yml deleted file mode 100644 index 59163f0..0000000 --- a/.github/workflows/load-tests.yml +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2023, AllianceBlock. All rights reserved. -# See the file LICENSE for licensing terms. - -name: NuklaiVM Load Tests - -on: - push: - branches: - - main - pull_request: - types: [labeled, synchronize, reopened] - -jobs: - nuklaivm-load-tests: - if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'run load') }} - strategy: - matrix: - level: [v1, v2, v3] # v4 is not supported - runs-on: dev - timeout-minutes: 25 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' - check-latest: true - cache: true - cache-dependency-path: | - go.sum - - name: Run load tests - working-directory: ./ - shell: bash - run: GOAMD64=${{ matrix.level }} scripts/tests.load.sh -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true diff --git a/.github/workflows/nuklaivm-ci.yml b/.github/workflows/nuklaivm-ci.yml new file mode 100644 index 0000000..d7150ee --- /dev/null +++ b/.github/workflows/nuklaivm-ci.yml @@ -0,0 +1,143 @@ +# Copyright (C) 2023, AllianceBlock. All rights reserved. +# See the file LICENSE for licensing terms. + +name: NuklaiVM CI +on: + push: + branches: + - main + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + go-mod-tidy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Go + uses: ./.github/actions/install-go + - shell: bash + run: go mod tidy + - shell: bash + working-directory: ./ + run: go mod tidy + - shell: bash + run: scripts/tests.clean.sh + + nuklaivm-lint: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: ./.github/actions/install-go + with: + cache-dependency-path: | + go.sum + - name: Run static analysis tests + shell: bash + run: scripts/tests.lint.sh + - name: Build vm, cli, faucet, feed + shell: bash + run: scripts/build.sh + + nuklaivm-unit-tests: + runs-on: ubuntu-20.04-32 + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: ./.github/actions/install-go + with: + cache-dependency-path: | + go.sum + - name: Run unit tests + shell: bash + run: scripts/tests.unit.sh + - name: Run integration tests + shell: bash + run: scripts/tests.integration.sh + # - name: Archive code coverage results (text) + # uses: actions/upload-artifact@v4 + # with: + # name: code-coverage-out + # path: ./integration.coverage.out + # - name: Archive code coverage results (html) + # uses: actions/upload-artifact@v4 + # with: + # name: code-coverage-html + # path: ./integration.coverage.html + - name: Run e2e tests + shell: bash + run: scripts/run.sh + env: + MODE: 'test' + + nuklaivm-tests: + runs-on: ubuntu-latest + needs: [go-mod-tidy, nuklaivm-lint, nuklaivm-unit-tests] + steps: + - name: Finished NuklaiVM tests + run: echo "Finished NuklaiVM tests" + + nuklaivm-load-tests: + needs: [nuklaivm-unit-tests] + strategy: + matrix: + level: [v1, v2, v3] # v4 is not supported + runs-on: ubuntu-20.04-32 + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: ./.github/actions/install-go + with: + cache-dependency-path: | + go.sum + - name: Run load tests + shell: bash + run: GOAMD64=${{ matrix.level }} scripts/tests.load.sh + + nuklaivm-sync-tests: + needs: [nuklaivm-unit-tests] + runs-on: ubuntu-20.04-32 + timeout-minutes: 25 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: ./.github/actions/install-go + with: + cache-dependency-path: | + go.sum + - name: Run sync tests + shell: bash + run: scripts/run.sh + env: + MODE: 'full-test' + + nuklaivm-wallet-release: + needs: [nuklaivm-load-tests, nuklaivm-sync-tests] + runs-on: macos-latest-xl + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: ./.github/actions/nuklai-wallet-release + + nuklaivm-release: + needs: [nuklaivm-load-tests, nuklaivm-sync-tests] + # We build with 20.04 to maintain max compatibility: https://github.com/golang/go/issues/57328 + runs-on: ubuntu-20.04-32 + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: ./.github/actions/vm-release + with: + vm-name: nuklaivm + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 76f4351..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (C) 2023, AllianceBlock. All rights reserved. -# See the file LICENSE for licensing terms. - -name: NuklaiVM Release - -on: - push: - branches: - - main - tags: - - '*' - pull_request: - types: [labeled, synchronize, reopened] - -jobs: - nuklaivm-release: - # We build with 20.04 to maintain max compatibility: https://github.com/golang/go/issues/57328 - runs-on: dev - if: ${{ github.ref == 'refs/heads/main' || startsWith(github.event.ref, 'refs/tags/v') || contains(github.event.pull_request.labels.*.name, 'run release') }} - steps: - - name: Git checkout - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' - check-latest: true - cache: true - cache-dependency-path: | - go.sum - - name: Set up arm64 cross compiler - run: | - apt-get -y update - apt-get -y install gcc-aarch64-linux-gnu - - name: Checkout osxcross - uses: actions/checkout@v2 - with: - repository: tpoechtrager/osxcross - path: osxcross - - name: Build osxcross - run: | - apt-get -y install clang llvm-dev libxml2-dev uuid-dev libssl-dev bash patch make tar xz-utils bzip2 gzip sed cpio libbz2-dev - cd osxcross - wget https://github.com/joseluisq/macosx-sdks/releases/download/12.3/$MACOS_SDK_FNAME -O tarballs/$MACOS_SDK_FNAME - echo $MACOS_SDK_CHECKSUM tarballs/$MACOS_SDK_FNAME | sha256sum -c - - UNATTENDED=1 ./build.sh - echo $PWD/target/bin >> $GITHUB_PATH - env: - MACOS_SDK_FNAME: MacOSX12.3.sdk.tar.xz - MACOS_SDK_CHECKSUM: 3abd261ceb483c44295a6623fdffe5d44fc4ac2c872526576ec5ab5ad0f6e26c - - name: Run GoReleaser - working-directory: ./ - shell: bash - run: scripts/build.release.sh - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..0ac71b6 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,29 @@ +# Copyright (C) 2023, AllianceBlock. All rights reserved. +# See the file LICENSE for licensing terms. + +name: Mark stale issues and pull requests +on: + schedule: + - cron: '0 0 * * *' # Run every day at midnight UTC +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v8 + with: + # Overall configuration + operations-per-run: 100 + + # PR configuration + days-before-pr-stale: 30 + stale-pr-message: 'This PR has become stale because it has been open for 30 days with no activity. Adding the `lifecycle/frozen` label will exempt this PR from future lifecycle events..' + days-before-pr-close: -1 + stale-pr-label: lifecycle/stale + exempt-pr-labels: lifecycle/frozen + + # Issue configuration + days-before-issue-stale: 60 + stale-issue-message: 'This issue has become stale because it has been open 60 days with no activity. Adding the `lifecycle/frozen` label will exempt this issue from future lifecycle events.' + days-before-issue-close: -1 + stale-issue-label: lifecycle/stale + exempt-issue-labels: lifecycle/frozen diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml deleted file mode 100644 index f1ba0b7..0000000 --- a/.github/workflows/static-analysis.yml +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2023, AllianceBlock. All rights reserved. -# See the file LICENSE for licensing terms. - -name: NuklaiVM Static Analysis - -on: - push: - branches: - - main - pull_request: - -jobs: - nuklaivm-lint: - runs-on: dev - timeout-minutes: 10 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' - check-latest: true - cache: true - cache-dependency-path: | - go.sum - - name: Run static analysis tests - working-directory: ./ - shell: bash - run: scripts/tests.lint.sh - - name: Build vm, cli - working-directory: ./ - shell: bash - run: scripts/build.sh - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true diff --git a/.github/workflows/sync-tests.yml b/.github/workflows/sync-tests.yml deleted file mode 100644 index a5780c8..0000000 --- a/.github/workflows/sync-tests.yml +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2023, AllianceBlock. All rights reserved. -# See the file LICENSE for licensing terms. - -name: NuklaiVM Sync Tests - -on: - push: - branches: - - main - pull_request: - types: [labeled, synchronize, reopened] - -jobs: - nuklaivm-sync-tests: - if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'run sync') }} - runs-on: dev - timeout-minutes: 25 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "1.20" - check-latest: true - cache: true - cache-dependency-path: | - go.sum - - name: Run sync tests - working-directory: ./ - shell: bash - run: mkdir -p /data/github/tmp/nuklaivm && scripts/run.sh /data/github/tmp/nuklaivm - env: - MODE: "full-test" -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true diff --git a/.github/workflows/tidy-checker.yml b/.github/workflows/tidy-checker.yml deleted file mode 100644 index d49472d..0000000 --- a/.github/workflows/tidy-checker.yml +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (C) 2023, AllianceBlock. All rights reserved. -# See the file LICENSE for licensing terms. - -name: NuklaiVM Tidy Checker -on: - push: - branches: - - main - pull_request: - -jobs: - go_mod_tidy: - name: Tidy - runs-on: dev - steps: - - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' - check-latest: true - cache: true - - shell: bash - run: go mod tidy - - shell: bash - run: scripts/tests.clean.sh - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml deleted file mode 100644 index 7e5f95e..0000000 --- a/.github/workflows/unit-tests.yml +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (C) 2023, AllianceBlock. All rights reserved. -# See the file LICENSE for licensing terms. - -name: NuklaiVM Unit Tests - -on: - push: - branches: - - main - pull_request: - types: [labeled, synchronize, reopened] - -jobs: - nuklaivm-unit-tests: - if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'run unit') }} - runs-on: dev - timeout-minutes: 25 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "1.20" - check-latest: true - cache: true - cache-dependency-path: | - go.sum - - name: Run unit tests - working-directory: ./ - shell: bash - run: scripts/tests.unit.sh - - name: Run integration tests - working-directory: ./ - shell: bash - run: scripts/tests.integration.sh - - name: Archive code coverage results (text) - uses: actions/upload-artifact@v3 - with: - name: code-coverage-out - path: ./integration.coverage.out - - name: Archive code coverage results (html) - uses: actions/upload-artifact@v3 - with: - name: code-coverage-html - path: ./integration.coverage.html - - name: Run e2e tests - working-directory: ./ - shell: bash - run: mkdir -p /data/github/tmp/nuklaivm && scripts/run.sh /data/github/tmp/nuklaivms - env: - MODE: "test" - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true diff --git a/.github/workflows/vm-release.yml b/.github/workflows/vm-release.yml new file mode 100644 index 0000000..53c447e --- /dev/null +++ b/.github/workflows/vm-release.yml @@ -0,0 +1,32 @@ +# Copyright (C) 2023, AllianceBlock. All rights reserved. +# See the file LICENSE for licensing terms. + +name: VM Release + +on: + push: + tags: + - '*' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + nuklai-wallet-release: + runs-on: macos-latest-xl + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: ./.github/actions/nuklai-wallet-release + + nuklaivm-release: + # We build with 20.04 to maintain max compatibility: https://github.com/golang/go/issues/57328 + runs-on: ubuntu-20.04-32 + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: ./.github/actions/vm-release + with: + vm-name: nuklaivm + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index b6ab582..6ae9709 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,5 @@ # nuklaivm -

- - - -

- ---- - `nuklaivm` takes inspiration from [morpheusvm](https://github.com/ava-labs/hypersdk/tree/main/examples/morpheusvm) and [tokenvm](https://github.com/ava-labs/hypersdk/tree/main/examples/tokenvm) and implements the functionality of both of these VMs. In addition, `nuklaivm` also adds additional functionality such as staking native token `NAI`, has an diff --git a/cmd/nuklai-wallet/scripts/build.sh b/cmd/nuklai-wallet/scripts/build.sh index b9a7bdf..70d7cc2 100755 --- a/cmd/nuklai-wallet/scripts/build.sh +++ b/cmd/nuklai-wallet/scripts/build.sh @@ -31,7 +31,7 @@ fi rm -rf nuklai-wallet.zip # Exit early if not publishing -if [ ${PUBLISH} == false ]; then +if [ "${PUBLISH}" == false ]; then echo "not publishing app" ditto -c -k --keepParent build/bin/Nuklai\ Wallet.app nuklai-wallet.zip exit 0 @@ -39,16 +39,16 @@ fi echo "publishing app" # Sign code -codesign -s ${APP_SIGNING_KEY_ID} --deep --timestamp -o runtime -v build/bin/Nuklai\ Wallet.app +codesign -s "${APP_SIGNING_KEY_ID}" --deep --timestamp -o runtime -v build/bin/Nuklai\ Wallet.app ditto -c -k --keepParent build/bin/Nuklai\ Wallet.app nuklai-wallet.zip # Need to sign to allow for app to be opened on other computers -xcrun altool --notarize-app --primary-bundle-id ai.nukl.nuklai-wallet --username ${APPLE_NOTARIZATION_USERNAME} --password "@keychain:altool" --file nuklai-wallet.zip +xcrun altool --notarize-app --primary-bundle-id ai.nukl.nuklai-wallet --username "${APPLE_NOTARIZATION_USERNAME}" --password "@keychain:altool" --file nuklai-wallet.zip # Log until exit -read -p "Input APPLE_NOTARIZATION_REQUEST_ID: " APPLE_NOTARIZATION_REQUEST_ID +read -p -r "Input APPLE_NOTARIZATION_REQUEST_ID: " APPLE_NOTARIZATION_REQUEST_ID while true do - xcrun altool --notarization-info ${APPLE_NOTARIZATION_REQUEST_ID} -u ${APPLE_NOTARIZATION_USERNAME} -p "@keychain:altool" + xcrun altool --notarization-info "${APPLE_NOTARIZATION_REQUEST_ID}" -u "${APPLE_NOTARIZATION_USERNAME}" -p "@keychain:altool" sleep 15 done diff --git a/cmd/nuklai-wallet/scripts/dev.sh b/cmd/nuklai-wallet/scripts/dev.sh index 8a42931..c1e355d 100755 --- a/cmd/nuklai-wallet/scripts/dev.sh +++ b/cmd/nuklai-wallet/scripts/dev.sh @@ -16,9 +16,6 @@ mkdir -p "$nuklai_wallet_dir" # Install wails go install -v github.com/wailsapp/wails/v2/cmd/wails@v2.8.0 -# Save current directory -current_dir=$(pwd) - # Go up two directories pushd ../.. diff --git a/scripts/build.sh b/scripts/build.sh index 9848049..bb800a5 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -18,12 +18,10 @@ NUKLAIVM_PATH=$( cd .. && pwd ) -realpath() { - [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" -} - if [[ $# -eq 1 ]]; then - BINARY_PATH=$(realpath $1) + BINARY_DIR=$(cd "$(dirname "$1")" && pwd) + BINARY_FNAME=$(basename "$1") + BINARY_PATH=$BINARY_DIR/$BINARY_FNAME elif [[ $# -eq 0 ]]; then # Set default binary directory location name="qeX5BUxbiwUhSePncmz1C7RdH6njYYv6dNZhJrdeXRKMnTpKt" @@ -33,23 +31,23 @@ else exit 1 fi -cd $NUKLAIVM_PATH +cd "$NUKLAIVM_PATH" echo "Building nuklaivm in $BINARY_PATH" -mkdir -p $(dirname $BINARY_PATH) -go build -o $BINARY_PATH ./cmd/nuklaivm +mkdir -p "$(dirname "$BINARY_PATH")" +go build -o "$BINARY_PATH" ./cmd/nuklaivm CLI_PATH=$NUKLAIVM_PATH/build/nuklai-cli echo "Building nuklai-cli in $CLI_PATH" -mkdir -p $(dirname $CLI_PATH) -go build -o $CLI_PATH ./cmd/nuklai-cli +mkdir -p "$(dirname "$CLI_PATH")" +go build -o "$CLI_PATH" ./cmd/nuklai-cli FAUCET_PATH=$NUKLAIVM_PATH/build/nuklai-faucet echo "Building nuklai-faucet in $FAUCET_PATH" -mkdir -p $(dirname $FAUCET_PATH) -go build -o $FAUCET_PATH ./cmd/nuklai-faucet +mkdir -p "$(dirname "$FAUCET_PATH")" +go build -o "$FAUCET_PATH" ./cmd/nuklai-faucet FEED_PATH=$NUKLAIVM_PATH/build/nuklai-feed echo "Building nuklai-feed in $FEED_PATH" -mkdir -p $(dirname $FEED_PATH) -go build -o $FEED_PATH ./cmd/nuklai-feed +mkdir -p "$(dirname "$FEED_PATH")" +go build -o "$FEED_PATH" ./cmd/nuklai-feed diff --git a/scripts/deploy.devnet.sh b/scripts/deploy.devnet.sh index a40aed4..59f5075 100755 --- a/scripts/deploy.devnet.sh +++ b/scripts/deploy.devnet.sh @@ -9,7 +9,7 @@ set -o pipefail # Ensure we return back to current directory pw=$(pwd) function cleanup() { - cd $pw + cd "$pw" } trap cleanup EXIT @@ -23,18 +23,20 @@ mkdir -p /tmp/avalanche-ops-cache # Create deployment directory (avalanche-ops creates metadata in cwd) DATE=$(date '+%m%d%Y-%H%M%S') DEPLOY_PREFIX=~/avalanche-ops-deploys/${DATE} -mkdir -p ${DEPLOY_PREFIX} +mkdir -p "${DEPLOY_PREFIX}" DEPLOY_ARTIFACT_PREFIX=${DEPLOY_PREFIX}/artifacts -mkdir -p ${DEPLOY_ARTIFACT_PREFIX} -echo create deployment folder: ${DEPLOY_PREFIX} -cd ${DEPLOY_PREFIX} +mkdir -p "${DEPLOY_ARTIFACT_PREFIX}" +echo create deployment folder: "${DEPLOY_PREFIX}" +cd "${DEPLOY_PREFIX}" # Set constants -export DEPLOYER_ARCH_TYPE=$(uname -m) -[ $DEPLOYER_ARCH_TYPE = x86_64 ] && DEPLOYER_ARCH_TYPE=amd64 -echo DEPLOYER_ARCH_TYPE: ${DEPLOYER_ARCH_TYPE} -export DEPLOYER_OS_TYPE=$(uname | tr '[:upper:]' '[:lower:]') -echo DEPLOYER_OS_TYPE: ${DEPLOYER_OS_TYPE} +DEPLOYER_ARCH_TYPE=$(uname -m) +export DEPLOYER_ARCH_TYPE +[ "$DEPLOYER_ARCH_TYPE" = x86_64 ] && DEPLOYER_ARCH_TYPE=amd64 +echo DEPLOYER_ARCH_TYPE: "${DEPLOYER_ARCH_TYPE}" +DEPLOYER_OS_TYPE=$(uname | tr '[:upper:]' '[:lower:]') +export DEPLOYER_OS_TYPE +echo DEPLOYER_OS_TYPE: "${DEPLOYER_OS_TYPE}" export AVALANCHEGO_VERSION="1.10.12" echo AVALANCHEGO_VERSION: ${AVALANCHEGO_VERSION} export NUKLAIVM_VERSION="0.1.0" @@ -47,11 +49,11 @@ echo EMISSION_ADDRESS: ${EMISSION_ADDRESS} # TODO: set deploy os/arch # Check valid setup -if [ ${DEPLOYER_OS_TYPE} != 'darwin' ]; then +if [ "${DEPLOYER_OS_TYPE}" != 'darwin' ]; then echo 'os is not supported' >&2 exit 1 fi -if [ ${DEPLOYER_ARCH_TYPE} != 'arm64' ]; then +if [ "${DEPLOYER_ARCH_TYPE}" != 'arm64' ]; then echo 'arch is not supported' >&2 exit 1 fi @@ -67,65 +69,65 @@ fi # Install avalanche-ops echo 'installing avalanche-ops...' if [ -f /tmp/avalanche-ops-cache/avalancheup-aws ]; then - cp /tmp/avalanche-ops-cache/avalancheup-aws ${DEPLOY_ARTIFACT_PREFIX}/avalancheup-aws + cp /tmp/avalanche-ops-cache/avalancheup-aws "${DEPLOY_ARTIFACT_PREFIX}"/avalancheup-aws echo 'found avalanche-ops in cache' else wget https://github.com/ava-labs/avalanche-ops/releases/download/latest/avalancheup-aws.aarch64-apple-darwin - mv ./avalancheup-aws.aarch64-apple-darwin ${DEPLOY_ARTIFACT_PREFIX}/avalancheup-aws - chmod +x ${DEPLOY_ARTIFACT_PREFIX}/avalancheup-aws - cp ${DEPLOY_ARTIFACT_PREFIX}/avalancheup-aws /tmp/avalanche-ops-cache/avalancheup-aws + mv ./avalancheup-aws.aarch64-apple-darwin "${DEPLOY_ARTIFACT_PREFIX}"/avalancheup-aws + chmod +x "${DEPLOY_ARTIFACT_PREFIX}"/avalancheup-aws + cp "${DEPLOY_ARTIFACT_PREFIX}"/avalancheup-aws /tmp/avalanche-ops-cache/avalancheup-aws fi -${DEPLOY_ARTIFACT_PREFIX}/avalancheup-aws --help +"${DEPLOY_ARTIFACT_PREFIX}"/avalancheup-aws --help # Install nuklai-cli echo 'installing nuklai-cli...' if [ -f /tmp/avalanche-ops-cache/nuklai-cli ]; then - cp /tmp/avalanche-ops-cache/nuklai-cli ${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli + cp /tmp/avalanche-ops-cache/nuklai-cli "${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli echo 'found nuklai-cli in cache' else wget "https://github.com/nuklai/nuklaivm/releases/download/v${NUKLAIVM_VERSION}/nuklaivm_${NUKLAIVM_VERSION}_${DEPLOYER_OS_TYPE}_${DEPLOYER_ARCH_TYPE}.tar.gz" mkdir -p /tmp/nuklai-installs - tar -xvf nuklaivm_${NUKLAIVM_VERSION}_${DEPLOYER_OS_TYPE}_${DEPLOYER_ARCH_TYPE}.tar.gz -C /tmp/nuklai-installs - rm -rf nuklaivm_${NUKLAIVM_VERSION}_${DEPLOYER_OS_TYPE}_${DEPLOYER_ARCH_TYPE}.tar.gz - mv /tmp/nuklai-installs/nuklai-cli ${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli + tar -xvf nuklaivm_${NUKLAIVM_VERSION}_"${DEPLOYER_OS_TYPE}"_"${DEPLOYER_ARCH_TYPE}".tar.gz -C /tmp/nuklai-installs + rm -rf nuklaivm_${NUKLAIVM_VERSION}_"${DEPLOYER_OS_TYPE}"_"${DEPLOYER_ARCH_TYPE}".tar.gz + mv /tmp/nuklai-installs/nuklai-cli "${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli rm -rf /tmp/nuklai-installs - cp ${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli /tmp/avalanche-ops-cache/nuklai-cli + cp "${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli /tmp/avalanche-ops-cache/nuklai-cli fi # Download nuklaivm echo 'downloading nuklaivm...' if [ -f /tmp/avalanche-ops-cache/nuklaivm ]; then - cp /tmp/avalanche-ops-cache/nuklaivm ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm - cp /tmp/avalanche-ops-cache/nuklai-cli-dev ${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli-dev + cp /tmp/avalanche-ops-cache/nuklaivm "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm + cp /tmp/avalanche-ops-cache/nuklai-cli-dev "${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli-dev echo 'found nuklaivm in cache' else wget "https://github.com/ava-labs/hypersdk/releases/download/v${NUKLAIVM_VERSION}/nuklaivm_${NUKLAIVM_VERSION}_linux_amd64.tar.gz" mkdir -p /tmp/nuklai-installs tar -xvf nuklaivm_${NUKLAIVM_VERSION}_linux_amd64.tar.gz -C /tmp/nuklai-installs rm -rf nuklaivm_${NUKLAIVM_VERSION}_linux_amd64.tar.gz - mv /tmp/nuklai-installs/nuklaivm ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm - mv /tmp/nuklai-installs/nuklai-cli ${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli-dev + mv /tmp/nuklai-installs/nuklaivm "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm + mv /tmp/nuklai-installs/nuklai-cli "${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli-dev rm -rf /tmp/nuklai-installs - cp ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm /tmp/avalanche-ops-cache/nuklaivm - cp ${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli-dev /tmp/avalanche-ops-cache/nuklai-cli-dev + cp "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm /tmp/avalanche-ops-cache/nuklaivm + cp "${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli-dev /tmp/avalanche-ops-cache/nuklai-cli-dev fi # Setup genesis and configuration files -cat < ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm-subnet-config.json +cat < "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm-subnet-config.json { "proposerMinBlockDelay": 0, "proposerNumHistoricalBlocks": 50000 } EOF -cat ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm-subnet-config.json +cat "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm-subnet-config.json # TODO: make address configurable via ENV -cat < ${DEPLOY_ARTIFACT_PREFIX}/allocations.json +cat < "${DEPLOY_ARTIFACT_PREFIX}"/allocations.json [ {"address":"${INITIAL_OWNER_ADDRESS}", "balance":853000000000000000} ] EOF -cat < ${DEPLOY_ARTIFACT_PREFIX}/emission-balancer.json +cat < "${DEPLOY_ARTIFACT_PREFIX}"/emission-balancer.json { "maxSupply": 10000000000000000000, "emissionAddress":"${EMISSION_ADDRESS}" @@ -136,14 +138,14 @@ EOF # # TODO: make fee params configurable via ENV MAX_UINT64=18446744073709551615 -${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli genesis generate ${DEPLOY_ARTIFACT_PREFIX}/allocations.json ${DEPLOY_ARTIFACT_PREFIX}/emission-balancer.json \ ---genesis-file ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm-genesis.json \ +"${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli genesis generate "${DEPLOY_ARTIFACT_PREFIX}"/allocations.json "${DEPLOY_ARTIFACT_PREFIX}"/emission-balancer.json \ +--genesis-file "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm-genesis.json \ --max-block-units 1800000,${MAX_UINT64},${MAX_UINT64},${MAX_UINT64},${MAX_UINT64} \ --window-target-units ${MAX_UINT64},${MAX_UINT64},${MAX_UINT64},${MAX_UINT64},${MAX_UINT64} \ --min-block-gap 250 -cat ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm-genesis.json +cat "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm-genesis.json -cat < ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm-chain-config.json +cat < "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm-chain-config.json { "logLevel": "info", "mempoolSize": 10000000, @@ -159,19 +161,19 @@ cat < ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm-chain-config.json "continuousProfilerDir":"/data/nuklaivm-profiles" } EOF -cat ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm-chain-config.json +cat "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm-chain-config.json # Plan network deploy if [ ! -f /tmp/avalanche-ops-cache/aws-profile ]; then echo 'what is your AWS profile name?' - read prof_name - echo ${prof_name} > /tmp/avalanche-ops-cache/aws-profile + read -r prof_name + echo "${prof_name}" > /tmp/avalanche-ops-cache/aws-profile fi AWS_PROFILE_NAME=$(cat "/tmp/avalanche-ops-cache/aws-profile") # Create spec file SPEC_FILE=./aops-${DATE}.yml -echo created avalanche-ops spec file: ${SPEC_FILE} +echo created avalanche-ops spec file: "${SPEC_FILE}" # Create key file dir KEY_FILES_DIR=keys @@ -183,11 +185,11 @@ cat < "${DEPLOY_ARTIFACT_PREFIX}/metrics.yml" filters: - regex: ^*$ EOF -cat ${DEPLOY_ARTIFACT_PREFIX}/metrics.yml +cat "${DEPLOY_ARTIFACT_PREFIX}"/metrics.yml echo 'planning DEVNET deploy...' # TODO: increase size once dev machine is working -${DEPLOY_ARTIFACT_PREFIX}/avalancheup-aws default-spec \ +"${DEPLOY_ARTIFACT_PREFIX}"/avalancheup-aws default-spec \ --arch-type amd64 \ --os-type ubuntu20.04 \ --anchor-nodes 3 \ @@ -197,44 +199,44 @@ ${DEPLOY_ARTIFACT_PREFIX}/avalancheup-aws default-spec \ --instance-types='{"us-west-2":["c5.4xlarge"],"us-east-2":["c5.4xlarge"],"eu-west-1":["c5.4xlarge"]}' \ --ip-mode=ephemeral \ --metrics-fetch-interval-seconds 0 \ ---upload-artifacts-prometheus-metrics-rules-file-path ${DEPLOY_ARTIFACT_PREFIX}/metrics.yml \ +--upload-artifacts-prometheus-metrics-rules-file-path "${DEPLOY_ARTIFACT_PREFIX}"/metrics.yml \ --network-name custom \ --staking-amount-in-avax 2000 \ --avalanchego-release-tag v${AVALANCHEGO_VERSION} \ --create-dev-machine \ --keys-to-generate 5 \ ---subnet-config-file ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm-subnet-config.json \ ---vm-binary-file ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm \ +--subnet-config-file "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm-subnet-config.json \ +--vm-binary-file "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm \ --chain-name nuklaivm \ ---chain-genesis-file ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm-genesis.json \ ---chain-config-file ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm-chain-config.json \ +--chain-genesis-file "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm-genesis.json \ +--chain-config-file "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm-chain-config.json \ --enable-ssh \ ---spec-file-path ${SPEC_FILE} \ +--spec-file-path "${SPEC_FILE}" \ --key-files-dir ${KEY_FILES_DIR} \ ---profile-name ${AWS_PROFILE_NAME} +--profile-name "${AWS_PROFILE_NAME}" # Disable rate limits in config echo 'updating YAML with new rate limits...' -yq -i '.avalanchego_config.throttler-inbound-validator-alloc-size = 10737418240' ${SPEC_FILE} -yq -i '.avalanchego_config.throttler-inbound-at-large-alloc-size = 10737418240' ${SPEC_FILE} -yq -i '.avalanchego_config.throttler-inbound-node-max-processing-msgs = 100000' ${SPEC_FILE} -yq -i '.avalanchego_config.throttler-inbound-bandwidth-refill-rate = 1073741824' ${SPEC_FILE} -yq -i '.avalanchego_config.throttler-inbound-bandwidth-max-burst-size = 1073741824' ${SPEC_FILE} -yq -i '.avalanchego_config.throttler-inbound-cpu-validator-alloc = 100000' ${SPEC_FILE} -yq -i '.avalanchego_config.throttler-inbound-disk-validator-alloc = 10737418240000' ${SPEC_FILE} -yq -i '.avalanchego_config.throttler-outbound-validator-alloc-size = 10737418240' ${SPEC_FILE} -yq -i '.avalanchego_config.throttler-outbound-at-large-alloc-size = 10737418240' ${SPEC_FILE} -yq -i '.avalanchego_config.consensus-on-accept-gossip-validator-size = 10' ${SPEC_FILE} -yq -i '.avalanchego_config.consensus-on-accept-gossip-non-validator-size = 0' ${SPEC_FILE} -yq -i '.avalanchego_config.consensus-on-accept-gossip-peer-size = 10' ${SPEC_FILE} -yq -i '.avalanchego_config.consensus-accepted-frontier-gossip-peer-size = 10' ${SPEC_FILE} -yq -i '.avalanchego_config.consensus-app-concurrency = 8' ${SPEC_FILE} -yq -i '.avalanchego_config.network-compression-type = "zstd"' ${SPEC_FILE} +yq -i '.avalanchego_config.throttler-inbound-validator-alloc-size = 10737418240' "${SPEC_FILE}" +yq -i '.avalanchego_config.throttler-inbound-at-large-alloc-size = 10737418240' "${SPEC_FILE}" +yq -i '.avalanchego_config.throttler-inbound-node-max-processing-msgs = 100000' "${SPEC_FILE}" +yq -i '.avalanchego_config.throttler-inbound-bandwidth-refill-rate = 1073741824' "${SPEC_FILE}" +yq -i '.avalanchego_config.throttler-inbound-bandwidth-max-burst-size = 1073741824' "${SPEC_FILE}" +yq -i '.avalanchego_config.throttler-inbound-cpu-validator-alloc = 100000' "${SPEC_FILE}" +yq -i '.avalanchego_config.throttler-inbound-disk-validator-alloc = 10737418240000' "${SPEC_FILE}" +yq -i '.avalanchego_config.throttler-outbound-validator-alloc-size = 10737418240' "${SPEC_FILE}" +yq -i '.avalanchego_config.throttler-outbound-at-large-alloc-size = 10737418240' "${SPEC_FILE}" +yq -i '.avalanchego_config.consensus-on-accept-gossip-validator-size = 10' "${SPEC_FILE}" +yq -i '.avalanchego_config.consensus-on-accept-gossip-non-validator-size = 0' "${SPEC_FILE}" +yq -i '.avalanchego_config.consensus-on-accept-gossip-peer-size = 10' "${SPEC_FILE}" +yq -i '.avalanchego_config.consensus-accepted-frontier-gossip-peer-size = 10' "${SPEC_FILE}" +yq -i '.avalanchego_config.consensus-app-concurrency = 8' "${SPEC_FILE}" +yq -i '.avalanchego_config.network-compression-type = "zstd"' "${SPEC_FILE}" # Deploy DEVNET echo 'deploying DEVNET...' -${DEPLOY_ARTIFACT_PREFIX}/avalancheup-aws apply \ ---spec-file-path ${SPEC_FILE} +"${DEPLOY_ARTIFACT_PREFIX}"/avalancheup-aws apply \ +--spec-file-path "${SPEC_FILE}" echo 'DEVNET deployed' # Prepare dev machine @@ -242,24 +244,24 @@ echo 'DEVNET deployed' # TODO: prepare 1 dev machine per region echo 'setting up dev machine...' ACCESS_KEY=./aops-${DATE}-ec2-access.us-west-2.key -chmod 400 ${ACCESS_KEY} -DEV_MACHINE_IP=$(yq '.dev_machine_ips[0]' ${SPEC_FILE}) -until (scp -o "StrictHostKeyChecking=no" -i ${ACCESS_KEY} ${SPEC_FILE} ubuntu@${DEV_MACHINE_IP}:/home/ubuntu/aops.yml) +chmod 400 "${ACCESS_KEY}" +DEV_MACHINE_IP=$(yq '.dev_machine_ips[0]' "${SPEC_FILE}") +until (scp -o "StrictHostKeyChecking=no" -i "${ACCESS_KEY}" "${SPEC_FILE}" ubuntu@"${DEV_MACHINE_IP}":/home/ubuntu/aops.yml) do # During initial setup, ssh access may fail echo 'scp failed...trying again' sleep 5 done -cd $pw -scp -o "StrictHostKeyChecking=no" -i ${DEPLOY_PREFIX}/${ACCESS_KEY} ${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli-dev ubuntu@${DEV_MACHINE_IP}:/tmp/nuklai-cli -scp -o "StrictHostKeyChecking=no" -i ${DEPLOY_PREFIX}/${ACCESS_KEY} demo.pk ubuntu@${DEV_MACHINE_IP}:/home/ubuntu/demo.pk -scp -o "StrictHostKeyChecking=no" -i ${DEPLOY_PREFIX}/${ACCESS_KEY} scripts/setup.dev-machine.sh ubuntu@${DEV_MACHINE_IP}:/home/ubuntu/setup.sh -ssh -o "StrictHostKeyChecking=no" -i ${DEPLOY_PREFIX}/${ACCESS_KEY} ubuntu@${DEV_MACHINE_IP} /home/ubuntu/setup.sh +cd "$pw" +scp -o "StrictHostKeyChecking=no" -i "${DEPLOY_PREFIX}"/"${ACCESS_KEY}" "${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli-dev ubuntu@"${DEV_MACHINE_IP}":/tmp/nuklai-cli +scp -o "StrictHostKeyChecking=no" -i "${DEPLOY_PREFIX}"/"${ACCESS_KEY}" demo.pk ubuntu@"${DEV_MACHINE_IP}":/home/ubuntu/demo.pk +scp -o "StrictHostKeyChecking=no" -i "${DEPLOY_PREFIX}"/"${ACCESS_KEY}" scripts/setup.dev-machine.sh ubuntu@"${DEV_MACHINE_IP}":/home/ubuntu/setup.sh +ssh -o "StrictHostKeyChecking=no" -i "${DEPLOY_PREFIX}"/"${ACCESS_KEY}" ubuntu@"${DEV_MACHINE_IP}" /home/ubuntu/setup.sh echo 'setup dev machine' # Generate prometheus link -${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli chain import-ops ${DEPLOY_PREFIX}/${SPEC_FILE} -${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli prometheus generate --prometheus-start=false --prometheus-base-uri=http://${DEV_MACHINE_IP}:9090 +"${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli chain import-ops "${DEPLOY_PREFIX}"/"${SPEC_FILE}" +"${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli prometheus generate --prometheus-start=false --prometheus-base-uri=http://"${DEV_MACHINE_IP}":9090 # Print final logs cat << EOF diff --git a/scripts/run.sh b/scripts/run.sh index 1ca4247..1cd8986 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -45,24 +45,22 @@ if ${UNLIMITED_USAGE}; then fi echo "Running with:" -echo AGO_LOGLEVEL: ${AGO_LOGLEVEL} -echo LOGLEVEL: ${LOGLEVEL} +echo AGO_LOGLEVEL: "${AGO_LOGLEVEL}" +echo LOGLEVEL: "${LOGLEVEL}" echo VERSION: ${VERSION} -echo MODE: ${MODE} -echo LOG LEVEL: ${LOGLEVEL} -echo STATESYNC_DELAY \(ns\): ${STATESYNC_DELAY} -echo MIN_BLOCK_GAP \(ms\): ${MIN_BLOCK_GAP} -echo STORE_TXS: ${STORE_TXS} +echo MODE: "${MODE}" +echo LOG LEVEL: "${LOGLEVEL}" +echo STATESYNC_DELAY \(ns\): "${STATESYNC_DELAY}" +echo MIN_BLOCK_GAP \(ms\): "${MIN_BLOCK_GAP}" +echo STORE_TXS: "${STORE_TXS}" echo WINDOW_TARGET_UNITS: ${WINDOW_TARGET_UNITS} echo MAX_BLOCK_UNITS: ${MAX_BLOCK_UNITS} -echo INITIAL_OWNER_ADDRESS: ${INITIAL_OWNER_ADDRESS} -echo EMISSION_ADDRESS: ${EMISSION_ADDRESS} +echo INITIAL_OWNER_ADDRESS: "${INITIAL_OWNER_ADDRESS}" +echo EMISSION_ADDRESS: "${EMISSION_ADDRESS}" ############################ # build avalanchego # https://github.com/ava-labs/avalanchego/releases -GOARCH=$(go env GOARCH) -GOOS=$(go env GOOS) # Set TMPDIR to the first command line argument if provided, otherwise default to /tmp/nuklaivm TMPDIR=${1:-/tmp/nuklaivm} @@ -76,22 +74,22 @@ if [ ! -f "$AVALANCHEGO_PATH" ]; then CWD=$(pwd) # Clear old folders - rm -rf ${TMPDIR}/avalanchego-${VERSION} - mkdir -p ${TMPDIR}/avalanchego-${VERSION} - rm -rf ${TMPDIR}/avalanchego-src - mkdir -p ${TMPDIR}/avalanchego-src + rm -rf "${TMPDIR}"/avalanchego-${VERSION} + mkdir -p "${TMPDIR}"/avalanchego-${VERSION} + rm -rf "${TMPDIR}"/avalanchego-src + mkdir -p "${TMPDIR}"/avalanchego-src # Download src - cd ${TMPDIR}/avalanchego-src + cd "${TMPDIR}"/avalanchego-src git clone https://github.com/ava-labs/avalanchego.git cd avalanchego git checkout ${VERSION} # Build avalanchego ./scripts/build.sh - mv build/avalanchego ${TMPDIR}/avalanchego-${VERSION} + mv build/avalanchego "${TMPDIR}"/avalanchego-${VERSION} - cd ${CWD} + cd "${CWD}" else echo "using previously built avalanchego" fi @@ -102,18 +100,18 @@ fi echo "building nuklaivm" # delete previous (if exists) -rm -f ${TMPDIR}/avalanchego-${VERSION}/plugins/qeX5BUxbiwUhSePncmz1C7RdH6njYYv6dNZhJrdeXRKMnTpKt +rm -f "${TMPDIR}"/avalanchego-${VERSION}/plugins/qeX5BUxbiwUhSePncmz1C7RdH6njYYv6dNZhJrdeXRKMnTpKt # rebuild with latest code go build \ --o ${TMPDIR}/avalanchego-${VERSION}/plugins/qeX5BUxbiwUhSePncmz1C7RdH6njYYv6dNZhJrdeXRKMnTpKt \ +-o "${TMPDIR}"/avalanchego-${VERSION}/plugins/qeX5BUxbiwUhSePncmz1C7RdH6njYYv6dNZhJrdeXRKMnTpKt \ ./cmd/nuklaivm echo "building nuklai-cli" -go build -v -o ${TMPDIR}/nuklai-cli ./cmd/nuklai-cli +go build -v -o "${TMPDIR}"/nuklai-cli ./cmd/nuklai-cli # log everything in the avalanchego directory -find ${TMPDIR}/avalanchego-${VERSION} +find "${TMPDIR}"/avalanchego-${VERSION} ############################ @@ -126,14 +124,14 @@ find ${TMPDIR}/avalanchego-${VERSION} # funds using the included demo.pk) # Initial balance: 853 million NAI echo "creating allocations file" -cat < ${TMPDIR}/allocations.json +cat < "${TMPDIR}"/allocations.json [ {"address":"${INITIAL_OWNER_ADDRESS}", "balance":853000000000000000} ] EOF echo "creating emission balancer file" # maxSupply: 10 billion NAI -cat < ${TMPDIR}/emission-balancer.json +cat < "${TMPDIR}"/emission-balancer.json { "maxSupply": 10000000000000000000, "emissionAddress":"${EMISSION_ADDRESS}" @@ -143,16 +141,16 @@ EOF GENESIS_PATH=$2 if [[ -z "${GENESIS_PATH}" ]]; then echo "creating VM genesis file with allocations" - rm -f ${TMPDIR}/nuklaivm.genesis - ${TMPDIR}/nuklai-cli genesis generate ${TMPDIR}/allocations.json ${TMPDIR}/emission-balancer.json \ + rm -f "${TMPDIR}"/nuklaivm.genesis + "${TMPDIR}"/nuklai-cli genesis generate "${TMPDIR}"/allocations.json "${TMPDIR}"/emission-balancer.json \ --window-target-units ${WINDOW_TARGET_UNITS} \ --max-block-units ${MAX_BLOCK_UNITS} \ - --min-block-gap ${MIN_BLOCK_GAP} \ - --genesis-file ${TMPDIR}/nuklaivm.genesis + --min-block-gap "${MIN_BLOCK_GAP}" \ + --genesis-file "${TMPDIR}"/nuklaivm.genesis else echo "copying custom genesis file" - rm -f ${TMPDIR}/nuklaivm.genesis - cp ${GENESIS_PATH} ${TMPDIR}/nuklaivm.genesis + rm -f "${TMPDIR}"/nuklaivm.genesis + cp "${GENESIS_PATH}" "${TMPDIR}"/nuklaivm.genesis fi ############################ @@ -160,9 +158,9 @@ fi ############################ echo "creating vm config" -rm -f ${TMPDIR}/nuklaivm.config -rm -rf ${TMPDIR}/nuklaivm-e2e-profiles -cat < ${TMPDIR}/nuklaivm.config +rm -f "${TMPDIR}"/nuklaivm.config +rm -rf "${TMPDIR}"/nuklaivm-e2e-profiles +cat < "${TMPDIR}"/nuklaivm.config { "mempoolSize": 10000000, "mempoolSponsorSize": 10000000, @@ -178,15 +176,15 @@ cat < ${TMPDIR}/nuklaivm.config "stateSyncServerDelay": ${STATESYNC_DELAY} } EOF -mkdir -p ${TMPDIR}/nuklaivm-e2e-profiles +mkdir -p "${TMPDIR}"/nuklaivm-e2e-profiles ############################ ############################ echo "creating subnet config" -rm -f ${TMPDIR}/nuklaivm.subnet -cat < ${TMPDIR}/nuklaivm.subnet +rm -f "${TMPDIR}"/nuklaivm.subnet +cat < "${TMPDIR}"/nuklaivm.subnet { "proposerMinBlockDelay": 0, "proposerNumHistoricalBlocks": 50000 @@ -237,7 +235,6 @@ $BIN server \ --log-level verbo \ --port=":12352" \ --grpc-gateway-port=":12353" & -PID=${!} ############################ # By default, it runs all e2e test cases! @@ -265,16 +262,16 @@ echo "running e2e tests" ./tests/e2e/e2e.test \ --ginkgo.v \ --network-runner-log-level verbo \ ---avalanchego-log-level ${AGO_LOGLEVEL} \ +--avalanchego-log-level "${AGO_LOGLEVEL}" \ --network-runner-grpc-endpoint="0.0.0.0:12352" \ --network-runner-grpc-gateway-endpoint="0.0.0.0:12353" \ ---avalanchego-path=${AVALANCHEGO_PATH} \ ---avalanchego-plugin-dir=${AVALANCHEGO_PLUGIN_DIR} \ ---vm-genesis-path=${TMPDIR}/nuklaivm.genesis \ ---vm-config-path=${TMPDIR}/nuklaivm.config \ ---subnet-config-path=${TMPDIR}/nuklaivm.subnet \ ---output-path=${TMPDIR}/avalanchego-${VERSION}/output.yaml \ ---mode=${MODE} +--avalanchego-path="${AVALANCHEGO_PATH}" \ +--avalanchego-plugin-dir="${AVALANCHEGO_PLUGIN_DIR}" \ +--vm-genesis-path="${TMPDIR}"/nuklaivm.genesis \ +--vm-config-path="${TMPDIR}"/nuklaivm.config \ +--subnet-config-path="${TMPDIR}"/nuklaivm.subnet \ +--output-path="${TMPDIR}"/avalanchego-${VERSION}/output.yaml \ +--mode="${MODE}" ############################ if [[ ${MODE} == "run" ]]; then diff --git a/scripts/tests.lint.sh b/scripts/tests.lint.sh index a9d5ad7..7ba71cc 100755 --- a/scripts/tests.lint.sh +++ b/scripts/tests.lint.sh @@ -47,7 +47,7 @@ function find_go_files { # automatically checks license headers # to modify the file headers (if missing), remove "--verify" flag # TESTS='license_header' ADDLICENSE_FLAGS="--verify --debug" ./scripts/tests.lint.sh -_addlicense_flags=${ADDLICENSE_FLAGS:-"--verify --debug"} +_addlicense_flags=${ADDLICENSE_FLAGS:-"--debug"} function test_license_header { go install -v github.com/palantir/go-license@latest local target="${1}" @@ -57,7 +57,7 @@ function test_license_header { # ignore 3rd party code go-license \ --config ./license.yml \ - ${_addlicense_flags} \ + "${_addlicense_flags}" \ "${files[@]}" } diff --git a/scripts/tests.load.sh b/scripts/tests.load.sh index 2bb0db0..862e723 100755 --- a/scripts/tests.load.sh +++ b/scripts/tests.load.sh @@ -31,4 +31,4 @@ run \ --vms 5 \ --accts 10000 \ --txs 500000 \ ---trace=${TRACE} +--trace="${TRACE}" diff --git a/scripts/tests.unit.sh b/scripts/tests.unit.sh index 3c67f62..5a00fc2 100755 --- a/scripts/tests.unit.sh +++ b/scripts/tests.unit.sh @@ -15,4 +15,7 @@ if ! [[ "$0" =~ scripts/tests.unit.sh ]]; then exit 255 fi -go test -race -timeout="10m" -coverprofile="coverage.out" -covermode="atomic" $(go list ./... | grep -v tests) +# Use mapfile to read the output into an array +mapfile -t packages < <(go list ./... | grep -v tests) +# Now use the array with the 'go test' command +go test -race -timeout="10m" -coverprofile="coverage.out" -covermode="atomic" "${packages[@]}"