From ce37d909d6fa4b282b800ebb17b78df70497c76c Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Thu, 2 Jan 2025 23:55:24 +0100 Subject: [PATCH 1/3] =?UTF-8?q?ci:=20split=20testnet=20and=20release=20CI?= =?UTF-8?q?=E2=80=AFworkflows=20(#1094)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Revert "fixing version upgrades (#1090)" This reverts commit 2fc6e9a87e0fa135d53914af5b448e3d12505bef. * chore: minor * ci: split release and deploy to testnet * fix: introduce upgrade version * test: fix tests * ci: use upgrade version * ci: update localnet version --- .github/workflows/create-release.yml | 27 +++++++ .github/workflows/mainnet-deploy-2h.yml | 10 ++- .github/workflows/mainnet-deploy-48h.yml | 9 ++- ...ftware-upgrade-and-create-new-snapshot.yml | 2 +- .github/workflows/testnet-deploy-2h.yml | 75 +++++++++++++++++++ ...tnet-deploy.yml => testnet-deploy-48h.yml} | 30 +++----- app/setup_handlers.go | 39 +++++++--- readme.md | 2 +- .../client/cli/query_denom_liquidity_test.go | 5 +- 9 files changed, 159 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/create-release.yml create mode 100644 .github/workflows/testnet-deploy-2h.yml rename .github/workflows/{create-release-and-testnet-deploy.yml => testnet-deploy-48h.yml} (84%) diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 000000000..1493c292d --- /dev/null +++ b/.github/workflows/create-release.yml @@ -0,0 +1,27 @@ +name: Create release + +on: + push: + tags: + - v* + +permissions: + contents: write + +jobs: + release: + name: Create release + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event.inputs.release_tag }} + + - name: Make release + run: | + sudo rm -rf dist + make release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/mainnet-deploy-2h.yml b/.github/workflows/mainnet-deploy-2h.yml index 3a9b3a67e..b89078664 100644 --- a/.github/workflows/mainnet-deploy-2h.yml +++ b/.github/workflows/mainnet-deploy-2h.yml @@ -44,13 +44,19 @@ jobs: # query and upgrade height height=$(${ELYSD} status --node $NODE | extract_and_calc_upgrade_height) + # generate upgrade version + upgrade_version=$(echo ${ELYS_VERSION} | cut -d'.' -f1) + echo "current version: ${ELYS_VERSION}" + echo "upgrade_version: $upgrade_version" + + # create proposal # create proposal txhash=$( ${ELYSD} software-upgrade-tx \ - ${ELYS_VERSION} \ + $upgrade_version \ $height \ 5000000000uelys \ - "Elys Network ${ELYS_VERSION} released. Focuses on enhancements and codebase improvements." \ + "Elys Network ${upgrade_version} released. Focuses on enhancements and codebase improvements." \ "{\"binaries\":{\"linux/amd64\":\"https://github.com/elys-network/elys/releases/download/${ELYS_VERSION}/elysd-${ELYS_VERSION}-linux-amd64.tar.gz?checksum=$checksum\"}}" \ true \ --from=proposer \ diff --git a/.github/workflows/mainnet-deploy-48h.yml b/.github/workflows/mainnet-deploy-48h.yml index c09f8b338..1a9f9a73c 100644 --- a/.github/workflows/mainnet-deploy-48h.yml +++ b/.github/workflows/mainnet-deploy-48h.yml @@ -44,13 +44,18 @@ jobs: # query and upgrade height height=$(${ELYSD} status --node $NODE | extract_and_calc_upgrade_height) + # generate upgrade version + upgrade_version=$(echo ${ELYS_VERSION} | cut -d'.' -f1) + echo "current version: ${ELYS_VERSION}" + echo "upgrade_version: $upgrade_version" + # create proposal txhash=$( ${ELYSD} software-upgrade-tx \ - ${ELYS_VERSION} \ + $upgrade_version \ $height \ 1000000000uelys \ - "Elys Network ${ELYS_VERSION} released. Focuses on enhancements and codebase improvements." \ + "Elys Network ${upgrade_version} released. Focuses on enhancements and codebase improvements." \ "{\"binaries\":{\"linux/amd64\":\"https://github.com/elys-network/elys/releases/download/${ELYS_VERSION}/elysd-${ELYS_VERSION}-linux-amd64.tar.gz?checksum=$checksum\"}}" \ false \ --from=proposer \ diff --git a/.github/workflows/test-software-upgrade-and-create-new-snapshot.yml b/.github/workflows/test-software-upgrade-and-create-new-snapshot.yml index c9e5b7039..9dee3973d 100644 --- a/.github/workflows/test-software-upgrade-and-create-new-snapshot.yml +++ b/.github/workflows/test-software-upgrade-and-create-new-snapshot.yml @@ -87,7 +87,7 @@ jobs: - name: Build new binary run: | # create new git tag - git tag -f v999.999.999 + git tag -f v999999.999999.999999 # build new elys binary make build NEW_BINARY_PATH=./build/elysd diff --git a/.github/workflows/testnet-deploy-2h.yml b/.github/workflows/testnet-deploy-2h.yml new file mode 100644 index 000000000..307aeec8f --- /dev/null +++ b/.github/workflows/testnet-deploy-2h.yml @@ -0,0 +1,75 @@ +name: TestNet deploy in 2 hours + +on: + workflow_dispatch: + +permissions: + contents: write + +jobs: + release: + name: Deploy to TestNet in 2 hours + runs-on: ubuntu-latest + steps: + - name: Create software upgrade proposal + run: | + # Get latest release version using GitHub API + ELYS_VERSION=$(curl -s https://api.github.com/repos/elys-network/elys/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') + echo "Latest elys version: $ELYS_VERSION" + + # Download latest binary + DOWNLOAD_BINARY_URL=https://github.com/elys-network/elys/releases/download/${ELYS_VERSION}/elysd-${ELYS_VERSION}-linux-amd64 + DOWNLOAD_SHA256_URL=https://github.com/elys-network/elys/releases/download/${ELYS_VERSION}/sha256sum.txt + ELYSD=/tmp/elysd-${ELYS_VERSION} + SHA256SUM=/tmp/sha256sum.txt + curl -L $DOWNLOAD_BINARY_URL -o $ELYSD && chmod +x $ELYSD + curl -L $DOWNLOAD_SHA256_URL -o $SHA256SUM + + # helper functions + extract_txhash() { awk -F 'txhash: ' '/txhash:/{print $2; exit}'; } + extract_proposal_id() { awk -F 'key: proposal_id|value: ' '/key: proposal_id/ { getline; gsub(/"/, "", $2); print $2; exit }'; } + extract_and_calc_upgrade_height() { awk -F'"latest_block_height":"' '{ split($2,a,"\""); print a[1]+2600; exit }'; } + extract_checksum() { awk "/elysd-${ELYS_VERSION}-linux-amd64.tar.gz/ {print \$1; exit}"; } + + # environment variables + NODE=https://rpc.testnet.elys.network:443 + OPTIONS="--node $NODE --chain-id elysicstestnet-1 --keyring-backend=test -b=sync --fees=20000uelys --gas=300000 -y" + + # import proposers key + ${ELYSD} keys import-hex proposer1 ${{ secrets.TESTNET_PROPOSER_PRIVATE_KEY_1 }} --keyring-backend=test + ${ELYSD} keys import-hex proposer2 ${{ secrets.TESTNET_PROPOSER_PRIVATE_KEY_2 }} --keyring-backend=test + ${ELYSD} keys import-hex proposer3 ${{ secrets.TESTNET_PROPOSER_PRIVATE_KEY_3 }} --keyring-backend=test + ${ELYSD} keys import-hex proposer4 ${{ secrets.TESTNET_PROPOSER_PRIVATE_KEY_4 }} --keyring-backend=test + + # get checksum + checksum=$(cat $SHA256SUM | extract_checksum) + + # query and upgrade height + height=$(${ELYSD} status --node $NODE | extract_and_calc_upgrade_height) + + # generate upgrade version + upgrade_version=$(echo ${ELYS_VERSION} | cut -d'.' -f1) + echo "current version: ${ELYS_VERSION}" + echo "upgrade_version: $upgrade_version" + + # create proposal + txhash=$( + ${ELYSD} software-upgrade-tx \ + $upgrade_version \ + $height \ + 10000000uelys \ + "Elys Network ${upgrade_version} released. Focuses on enhancements and codebase improvements." \ + "{\"binaries\":{\"linux/amd64\":\"https://github.com/elys-network/elys/releases/download/${ELYS_VERSION}/elysd-${ELYS_VERSION}-linux-amd64.tar.gz?checksum=$checksum\"}}" \ + true \ + --from=proposer1 \ + $OPTIONS | extract_txhash + ) + sleep 10 + proposalid=$(${ELYSD} q tx $txhash --node $NODE | extract_proposal_id) + + # vote on proposal + ${ELYSD} tx gov vote $proposalid yes --from=proposer1 $OPTIONS + ${ELYSD} tx gov vote $proposalid yes --from=proposer2 $OPTIONS + ${ELYSD} tx gov vote $proposalid yes --from=proposer3 $OPTIONS + ${ELYSD} tx gov vote $proposalid yes --from=proposer4 $OPTIONS + sleep 10 diff --git a/.github/workflows/create-release-and-testnet-deploy.yml b/.github/workflows/testnet-deploy-48h.yml similarity index 84% rename from .github/workflows/create-release-and-testnet-deploy.yml rename to .github/workflows/testnet-deploy-48h.yml index d35c81750..4d57fa214 100644 --- a/.github/workflows/create-release-and-testnet-deploy.yml +++ b/.github/workflows/testnet-deploy-48h.yml @@ -1,31 +1,16 @@ -name: Create release and TestNet deploy +name: TestNet deploy in 48 hours on: - push: - tags: - - v* + workflow_dispatch: permissions: contents: write jobs: release: - name: Create release and TestNet deploy + name: Deploy to TestNet in 48 hours runs-on: ubuntu-latest steps: - - name: Check out repository code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ref: ${{ github.event.inputs.release_tag }} - - - name: Make release - run: | - sudo rm -rf dist - make release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Create software upgrade proposal run: | # Get latest release version using GitHub API @@ -62,13 +47,18 @@ jobs: # query and upgrade height height=$(${ELYSD} status --node $NODE | extract_and_calc_upgrade_height) + # generate upgrade version + upgrade_version=$(echo ${ELYS_VERSION} | cut -d'.' -f1) + echo "current version: ${ELYS_VERSION}" + echo "upgrade_version: $upgrade_version" + # create proposal txhash=$( ${ELYSD} software-upgrade-tx \ - $ELYS_VERSION \ + $upgrade_version \ $height \ 10000000uelys \ - "Elys Network $ELYS_VERSION released. Focuses on enhancements and codebase improvements." \ + "Elys Network ${upgrade_version} released. Focuses on enhancements and codebase improvements." \ "{\"binaries\":{\"linux/amd64\":\"https://github.com/elys-network/elys/releases/download/${ELYS_VERSION}/elysd-${ELYS_VERSION}-linux-amd64.tar.gz?checksum=$checksum\"}}" \ false \ --from=proposer1 \ diff --git a/app/setup_handlers.go b/app/setup_handlers.go index 585d564ab..939b548b2 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -3,6 +3,7 @@ package app import ( "context" "fmt" + "strings" storetypes "cosmossdk.io/store/types" upgradetypes "cosmossdk.io/x/upgrade/types" @@ -14,30 +15,41 @@ import ( ) const ( - LocalNetVersion = "v999.999.999" + LocalNetVersion = "v999999" NewMaxBytes = 5 * 1024 * 1024 // 5MB ) // make sure to update these when you upgrade the version -var UpgradeName = "v1.6" -var RunPreMigrations = true +var NextVersion = "vNEXT" -func (app *ElysApp) setUpgradeHandler() { - if version.Version == LocalNetVersion { - UpgradeName = LocalNetVersion +// generate upgrade version from the current version (v999999.999999.999999 => v999999) +func generateUpgradeVersion(currentVersion string) string { + // if current version empty then override it with localnet version + if currentVersion == "v" { + currentVersion = "v999999.999999.999999" + } + parts := strings.Split(currentVersion, ".") + if len(parts) != 3 { + panic(fmt.Sprintf("Invalid version format: %s. Expected format: vX.Y.Z", currentVersion)) } + majorVersion := strings.TrimPrefix(parts[0], "v") + return fmt.Sprintf("v%s", majorVersion) +} +func (app *ElysApp) setUpgradeHandler() { + upgradeVersion := generateUpgradeVersion(version.Version) + app.Logger().Info("Current version", "version", version.Version) + app.Logger().Info("Upgrade version", "version", upgradeVersion) app.UpgradeKeeper.SetUpgradeHandler( - UpgradeName, + upgradeVersion, func(goCtx context.Context, plan upgradetypes.Plan, vm m.VersionMap) (m.VersionMap, error) { ctx := sdk.UnwrapSDKContext(goCtx) - app.Logger().Info("Running upgrade handler for " + UpgradeName) - - if RunPreMigrations { + app.Logger().Info("Running upgrade handler for " + upgradeVersion) - // Set RunPreMigrations to false if not needed in mainnet + if upgradeVersion == NextVersion || upgradeVersion == LocalNetVersion { // Add any logic here to run when the chain is upgraded to the new version + } return app.mm.RunMigrations(ctx, app.configurator, vm) @@ -77,5 +89,8 @@ func (app *ElysApp) setUpgradeStore() { func shouldLoadUpgradeStore(app *ElysApp, upgradeInfo upgradetypes.Plan) bool { currentHeight := app.LastBlockHeight() app.Logger().Debug(fmt.Sprintf("Current block height: %d, Upgrade height: %d\n", currentHeight, upgradeInfo.Height)) - return !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) + upgradeVersion := generateUpgradeVersion(version.Version) + app.Logger().Debug("Current version", "version", version.Version) + app.Logger().Debug("Upgrade version", "version", upgradeVersion) + return upgradeInfo.Name == upgradeVersion && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) } diff --git a/readme.md b/readme.md index d955a422c..52b5fbee2 100644 --- a/readme.md +++ b/readme.md @@ -36,7 +36,7 @@ This guide provides instructions on how to spin up a new localnet using the Elys Navigate into the cloned repository and build the binary using: ```bash - git tag -f v999.999.999 && make install + git tag -f v999999.999999.999999 && make install ``` This command will install the `elysd` daemon. diff --git a/x/amm/client/cli/query_denom_liquidity_test.go b/x/amm/client/cli/query_denom_liquidity_test.go index 5138a8481..e3feea442 100644 --- a/x/amm/client/cli/query_denom_liquidity_test.go +++ b/x/amm/client/cli/query_denom_liquidity_test.go @@ -1,12 +1,13 @@ package cli_test import ( - "cosmossdk.io/math" "fmt" - assetprofilemoduletypes "github.com/elys-network/elys/x/assetprofile/types" "strconv" "testing" + "cosmossdk.io/math" + assetprofilemoduletypes "github.com/elys-network/elys/x/assetprofile/types" + tmcli "github.com/cometbft/cometbft/libs/cli" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" From 9c045d54ab42b0c2eb4fb909ec83b42c742d6f21 Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Fri, 3 Jan 2025 13:49:07 +0100 Subject: [PATCH 2/3] ci: use highstakes snapshots (#1095) --- ...ftware-upgrade-and-create-new-snapshot.yml | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test-software-upgrade-and-create-new-snapshot.yml b/.github/workflows/test-software-upgrade-and-create-new-snapshot.yml index 9dee3973d..b1236c3d6 100644 --- a/.github/workflows/test-software-upgrade-and-create-new-snapshot.yml +++ b/.github/workflows/test-software-upgrade-and-create-new-snapshot.yml @@ -110,20 +110,24 @@ jobs: aws-s3-bucket-endpoint: false aws-s3-force-path-style: true - - name: Retrieve info.json and set snapshot path + - name: Retrieve snapshot info and set snapshot path run: | - # set info.json download url, use mainnet info.json for main branch otherwise use testnet info.json + # use mainnet for main branch otherwise use testnet snapshot data if [ "${{ github.ref }}" = "refs/heads/main" ]; then - INFO_DOWNLOAD_URL=https://snapshots.elys.network/info-mainnet.json + url="https://tools.highstakes.ch/snapshots/elys-mainnet" else - INFO_DOWNLOAD_URL=https://snapshots.elys.network/info-testnet.json + url="https://tools.highstakes.ch/snapshots/elys" fi - curl -L $INFO_DOWNLOAD_URL -o /tmp/info.json - echo "Info.json downloaded to check snapshot version." - # retrieve blockHeight field value from info.json - SNAPSHOT_BLOCK_HEIGHT=$(cat /tmp/info.json | awk -F'"' '/"blockHeight":/{print $4}') + html_content=$(curl -s "$url") + + SNAPSHOT_DOWNLOAD_URL=$(echo "$html_content" | grep -oP '(?<=)' | tail -n 1) + + echo "SNAPSHOT_DOWNLOAD_URL=$SNAPSHOT_DOWNLOAD_URL" >> $GITHUB_ENV echo "SNAPSHOT_BLOCK_HEIGHT=$SNAPSHOT_BLOCK_HEIGHT" >> $GITHUB_ENV + + echo "Snapshot download URL: $SNAPSHOT_DOWNLOAD_URL" echo "Snapshot block height: $SNAPSHOT_BLOCK_HEIGHT" if [ "${{ github.ref }}" = "refs/heads/main" ]; then @@ -144,17 +148,12 @@ jobs: exit 1 fi - # set snapshot download url, use mainnet snapshot for main branch otherwise use testnet snapshot + # set snapshot file path, use mainnet snapshot for main branch otherwise use testnet snapshot if [ "${{ github.ref }}" = "refs/heads/main" ]; then - SNAPSHOT_DOWNLOAD_URL=https://snapshots.elys.network/snapshot-mainnet.tar.lz4 - # set snapshot file path SNAPSHOT_FILE_PATH=/tmp/snapshot-mainnet.tar.lz4 else - SNAPSHOT_DOWNLOAD_URL=https://snapshots.elys.network/snapshot-testnet.tar.lz4 - # set snapshot file path SNAPSHOT_FILE_PATH=/tmp/snapshot-testnet.tar.lz4 fi - echo "SNAPSHOT_DOWNLOAD_URL=$SNAPSHOT_DOWNLOAD_URL" >> $GITHUB_ENV echo "SNAPSHOT_FILE_PATH=$SNAPSHOT_FILE_PATH" >> $GITHUB_ENV if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true' From c3cba9644174f4e407c1ff6ee253b4638c7f94e7 Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Fri, 3 Jan 2025 14:10:50 +0100 Subject: [PATCH 3/3] ci: fix snapshot file path (#1096) --- .../test-software-upgrade-and-create-new-snapshot.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-software-upgrade-and-create-new-snapshot.yml b/.github/workflows/test-software-upgrade-and-create-new-snapshot.yml index b1236c3d6..7bbbf3c17 100644 --- a/.github/workflows/test-software-upgrade-and-create-new-snapshot.yml +++ b/.github/workflows/test-software-upgrade-and-create-new-snapshot.yml @@ -150,9 +150,9 @@ jobs: # set snapshot file path, use mainnet snapshot for main branch otherwise use testnet snapshot if [ "${{ github.ref }}" = "refs/heads/main" ]; then - SNAPSHOT_FILE_PATH=/tmp/snapshot-mainnet.tar.lz4 + SNAPSHOT_FILE_PATH=/tmp/snapshot-mainnet.tar.gz else - SNAPSHOT_FILE_PATH=/tmp/snapshot-testnet.tar.lz4 + SNAPSHOT_FILE_PATH=/tmp/snapshot-testnet.tar.gz fi echo "SNAPSHOT_FILE_PATH=$SNAPSHOT_FILE_PATH" >> $GITHUB_ENV