Skip to content

Commit

Permalink
Ci/cleanup upgrade handler (#594)
Browse files Browse the repository at this point in the history
* [Bug]: Fix calculate discount and add more tests (#570)

* add calculate discount test and bug fix

* get asset by denom

* ci: use post-upgrade-snapshot-generator (#571)

* ci: use post-upgrade-snapshot-generator

* ci: update delete snapshot CI to use post upgrade snapshot gen binary

* ci: clean up upgrade handler

* ci: use latest post upgrade snapshot gen version

* ci: update post upgrade snapshot gen version

* ci: cache snapshot

* ci: use latest version of snapshot gen

* ci: add develop and devnet

---------

Co-authored-by: Amit Yadav <amy29981@gmail.com>
  • Loading branch information
cosmic-vagabond and amityadav0 committed Jun 19, 2024
1 parent 9ced23f commit c156530
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 55 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/delete-branch-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ jobs:
steps:
- name: Retrieve post upgrade snapshot generator binary
run: |
DOWNLOAD_URL=https://github.com/elys-network/post-upgrade-snapshot-generator/releases/download/v0.1.0/post-upgrade-snapshot-generator-v0.1.0-linux-amd64
POST_UPGRADE_SNAPSHOT_GENERATOR_PATH=/tmp/post-upgrade-snapshot-generator-v0.1.0
POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION=v0.2.2
DOWNLOAD_URL=https://github.com/elys-network/post-upgrade-snapshot-generator/releases/download/${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}/post-upgrade-snapshot-generator-${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}-linux-amd64
POST_UPGRADE_SNAPSHOT_GENERATOR_PATH=/tmp/post-upgrade-snapshot-generator-${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}
curl -L $DOWNLOAD_URL -o $POST_UPGRADE_SNAPSHOT_GENERATOR_PATH && chmod +x $POST_UPGRADE_SNAPSHOT_GENERATOR_PATH
echo "POST_UPGRADE_SNAPSHOT_GENERATOR_PATH=$POST_UPGRADE_SNAPSHOT_GENERATOR_PATH" >> $GITHUB_ENV
Expand Down
71 changes: 53 additions & 18 deletions .github/workflows/software-upgrade-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
pull_request:
push:
branches:
- develop
- devnet
- main

jobs:
Expand Down Expand Up @@ -38,8 +40,9 @@ jobs:
- name: Retrieve post upgrade snapshot generator binary
run: |
DOWNLOAD_URL=https://github.com/elys-network/post-upgrade-snapshot-generator/releases/download/v0.1.0/post-upgrade-snapshot-generator-v0.1.0-linux-amd64
POST_UPGRADE_SNAPSHOT_GENERATOR_PATH=/tmp/post-upgrade-snapshot-generator-v0.1.0
POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION=v0.2.2
DOWNLOAD_URL=https://github.com/elys-network/post-upgrade-snapshot-generator/releases/download/${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}/post-upgrade-snapshot-generator-${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}-linux-amd64
POST_UPGRADE_SNAPSHOT_GENERATOR_PATH=/tmp/post-upgrade-snapshot-generator-${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}
curl -L $DOWNLOAD_URL -o $POST_UPGRADE_SNAPSHOT_GENERATOR_PATH && chmod +x $POST_UPGRADE_SNAPSHOT_GENERATOR_PATH
echo "POST_UPGRADE_SNAPSHOT_GENERATOR_PATH=$POST_UPGRADE_SNAPSHOT_GENERATOR_PATH" >> $GITHUB_ENV
Expand All @@ -52,6 +55,23 @@ jobs:
NEW_BINARY_PATH=./build/elysd
echo "NEW_BINARY_PATH=$NEW_BINARY_PATH" >> $GITHUB_ENV
- name: Check submit new proposal from cache exists
uses: elys-network/actions-cache-s3@eba1d2b54699fda7ee03d826049bc67dcf514887
id: cache-submit-new-proposal
with:
path: |
/home/runner/.elys
/home/runner/.elys2
key: ${{ runner.os }}-submit-new-proposal-${{ env.LATEST_TAG }}
lookup-only: true
aws-access-key-id: ${{ secrets.R2_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.R2_SECRET_KEY }}
aws-endpoint: ${{ secrets.R2_ENDPOINT }}
aws-s3-bucket: ${{ secrets.R2_BUCKET_NAME }}
aws-region: auto
aws-s3-bucket-endpoint: false
aws-s3-force-path-style: true

- name: Retrieve info.json and set snapshot path
run: |
DOWNLOAD_URL=https://snapshots-testnet.stake-town.com/elys/info.json
Expand All @@ -70,10 +90,11 @@ jobs:
# set snapshot file path
SNAPSHOT_FILE_PATH=/tmp/snapshot.tar.lz4
echo "SNAPSHOT_FILE_PATH=$SNAPSHOT_FILE_PATH" >> $GITHUB_ENV
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true'

- name: Cache Snapshot
- name: Check snapshot from cache exists
uses: elys-network/actions-cache-s3@eba1d2b54699fda7ee03d826049bc67dcf514887
id: cache-snapshot
id: cache-snapshot-exists
with:
path: |
${{ env.SNAPSHOT_FILE_PATH }}
Expand All @@ -86,32 +107,46 @@ jobs:
aws-region: auto
aws-s3-bucket-endpoint: false
aws-s3-force-path-style: true
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true'

- name: Download snapshot
run: |
curl -L $SNAPSHOT_DOWNLOAD_URL -o $SNAPSHOT_FILE_PATH
if: steps.cache-snapshot.outputs.cache-hit != 'true'
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true' && steps.cache-snapshot-exists.outputs.cache-hit != 'true'

- name: Check submit new proposal from cache exists
uses: elys-network/actions-cache-s3@eba1d2b54699fda7ee03d826049bc67dcf514887
id: cache-submit-new-proposal
- name: Save snapshot to cache
uses: elys-network/actions-cache-s3/save@eba1d2b54699fda7ee03d826049bc67dcf514887
with:
path: |
/home/runner/.elys
/home/runner/.elys2
key: ${{ runner.os }}-submit-new-proposal-${{ env.LATEST_TAG }}
lookup-only: true
${{ env.SNAPSHOT_FILE_PATH }}
key: ${{ runner.os }}-snapshot-${{ env.LATEST_TAG }}
aws-access-key-id: ${{ secrets.R2_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.R2_SECRET_KEY }}
aws-endpoint: ${{ secrets.R2_ENDPOINT }}
aws-s3-bucket: ${{ secrets.R2_BUCKET_NAME }}
aws-region: auto
aws-s3-bucket-endpoint: false
aws-s3-force-path-style: true
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true' && steps.cache-snapshot-exists.outputs.cache-hit != 'true'

- name: Restore snapshot from cache
uses: elys-network/actions-cache-s3/restore@eba1d2b54699fda7ee03d826049bc67dcf514887
with:
path: |
${{ env.SNAPSHOT_FILE_PATH }}
key: ${{ runner.os }}-snapshot-${{ env.LATEST_TAG }}
aws-access-key-id: ${{ secrets.R2_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.R2_SECRET_KEY }}
aws-endpoint: ${{ secrets.R2_ENDPOINT }}
aws-s3-bucket: ${{ secrets.R2_BUCKET_NAME }}
aws-region: auto
aws-s3-bucket-endpoint: false
aws-s3-force-path-style: true
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true' && steps.cache-snapshot-exists.outputs.cache-hit == 'true'

- name: Chain snapshot and export
run: |
${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} chain-snapshot-export \
GOMEMLIMIT=8GiB ${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} chain-snapshot-export \
${SNAPSHOT_FILE_PATH} \
${OLD_BINARY_PATH} \
--timeout-next-block 100000 \
Expand All @@ -120,30 +155,30 @@ jobs:

- name: Chain initialization
run: |
${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} chain-init \
GOMEMLIMIT=8GiB ${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} chain-init \
${OLD_BINARY_PATH} \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true'

- name: Create second validator
run: |
${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} create-second-validator \
GOMEMLIMIT=8GiB ${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} create-second-validator \
${OLD_BINARY_PATH} \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true'

- name: Prepare validator data
run: |
${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} prepare-validator-data \
GOMEMLIMIT=8GiB ${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} prepare-validator-data \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true'

- name: Submit new proposal
run: |
${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} submit-new-proposal \
GOMEMLIMIT=8GiB ${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} submit-new-proposal \
${OLD_BINARY_PATH} \
${NEW_BINARY_PATH} \
--timeout-next-block 100000 \
Expand Down Expand Up @@ -184,7 +219,7 @@ jobs:

- name: Upgrade to new binary
run: |
${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} upgrade-to-new-binary \
GOMEMLIMIT=8GiB ${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} upgrade-to-new-binary \
${NEW_BINARY_PATH} \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
pull_request:
push:
branches:
- develop
- devnet
- main

jobs:
Expand Down
37 changes: 2 additions & 35 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ package app
import (
"fmt"

"cosmossdk.io/math"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
m "github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
tiermoduletypes "github.com/elys-network/elys/x/tier/types"
)

func SetupHandlers(app *ElysApp) {
Expand All @@ -27,35 +22,6 @@ func setUpgradeHandler(app *ElysApp) {
func(ctx sdk.Context, plan upgradetypes.Plan, vm m.VersionMap) (m.VersionMap, error) {
app.Logger().Info("Running upgrade handler for " + version.Version)

if version.Version == "v0.32.0" || version.Version == "v999.999.999" {
// Since invariant is broken sending missing amount to bonded pool
sumOfValTokens := math.ZeroInt()
app.EstakingKeeper.IterateBondedValidatorsByPower(ctx, func(_ int64, validator stakingtypes.ValidatorI) bool {
sumOfValTokens = sumOfValTokens.Add(validator.GetTokens())
return false
})

totalBondedTokens := app.EstakingKeeper.TotalBondedTokens(ctx)
if totalBondedTokens.LT(sumOfValTokens) {
missingAmount := sumOfValTokens.Sub(totalBondedTokens)
missingCoins := sdk.Coins{sdk.NewCoin("uelys", missingAmount)}
err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, missingCoins)
if err != nil {
panic(err)
}
err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, stakingtypes.BondedPoolName, missingCoins)
if err != nil {
panic(err)
}
}

app.Logger().Info("Deleting proposals with ID <= 193")
store := ctx.KVStore(app.keys[govtypes.StoreKey])
for i := uint64(1); i <= 193; i++ {
store.Delete(govtypes.ProposalKey(i))
}
}

return app.mm.RunMigrations(ctx, app.configurator, vm)
},
)
Expand All @@ -71,7 +37,8 @@ func loadUpgradeStore(app *ElysApp) {

if shouldLoadUpgradeStore(app, upgradeInfo) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{tiermoduletypes.StoreKey},
// Added: []string{},
// Deleted: []string{},
}
fmt.Printf("Setting store loader with height %d and store upgrades: %+v\n", upgradeInfo.Height, storeUpgrades)

Expand Down

0 comments on commit c156530

Please sign in to comment.