Skip to content

Commit

Permalink
chore: prepare upgrade to v1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurist-85 committed Sep 2, 2024
1 parent 80352d7 commit 415d743
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DIFF_TAG=$(shell git rev-list --tags="v*" --max-count=1 --not $(shell git rev-li
DEFAULT_TAG=$(shell git rev-list --tags="v*" --max-count=1)
# VERSION ?= $(shell echo $(shell git describe --tags $(or $(DIFF_TAG), $(DEFAULT_TAG))) | sed 's/^v//')

VERSION := "1.7.8"
VERSION := "1.8.0"
CBFTVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
Expand Down Expand Up @@ -532,7 +532,7 @@ proto-check-breaking:
###############################################################################

PACKAGE_NAME:=github.com/haqq-network/haqq
GOLANG_CROSS_VERSION = v1.21.2
GOLANG_CROSS_VERSION = v1.22.5
GOPATH ?= '$(HOME)/go'
release-dry-run:
docker run \
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ func (app *Haqq) setupUpgradeHandlers() {
// v1.8.0 Add and enable EVM Extensions (Precompiled contracts).
app.UpgradeKeeper.SetUpgradeHandler(
v180.UpgradeName,
v180.CreateUpgradeHandler(app.mm, app.configurator, *app.EvmKeeper),
v180.CreateUpgradeHandler(app.mm, app.configurator, *app.EvmKeeper, app.BankKeeper, app.DaoKeeper),
)

// When a planned update height is reached, the old binary will panic
Expand Down
64 changes: 64 additions & 0 deletions app/upgrades/v1.8.0/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
package v180

import (
"fmt"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/haqq-network/haqq/utils"
evmkeeper "github.com/haqq-network/haqq/x/evm/keeper"
evmtypes "github.com/haqq-network/haqq/x/evm/types"
ucdaokeeper "github.com/haqq-network/haqq/x/ucdao/keeper"
ucdaotypes "github.com/haqq-network/haqq/x/ucdao/types"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v1.8.0
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
ek evmkeeper.Keeper,
bk bankkeeper.Keeper,
dk ucdaokeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
logger := ctx.Logger().With("upgrade", UpgradeName)

logger.Info("migrate UC DAO balance")
if err := migrateUCDAObalance(ctx, bk); err != nil {
logger.Error("error while migrating ucdao module balance", "error", err)
return nil, err
}

logger.Info("fix UC DAO total ISLM balance")
if err := fixUCDAOTotalBalance(ctx, dk); err != nil {
logger.Error("error while reducing ucdao total ISLM balance", "error", err)
return nil, err
}

logger.Info("setting precompiles parameters")
if err := setPrecompilesParams(ctx, ek); err != nil {
logger.Error("error while setting precompiles parameters", "error", err)
return nil, err
}

// Leave modules are as-is to avoid running InitGenesis.
Expand All @@ -33,3 +56,44 @@ func setPrecompilesParams(ctx sdk.Context, ek evmkeeper.Keeper) error {
params.ActivePrecompiles = evmtypes.AvailableEVMExtensions
return ek.SetParams(ctx, params)
}

func migrateUCDAObalance(ctx sdk.Context, bk bankkeeper.Keeper) error {
oldDaoAddress := "haqq1vwr8z00ty7mqnk4dtchr9mn9j96nuh6wme0t2z"
oldDaoAccAddr := sdk.MustAccAddressFromBech32(oldDaoAddress)
oldDaoBalances := bk.GetAllBalances(ctx, oldDaoAccAddr)

return bk.SendCoinsFromAccountToModule(ctx, oldDaoAccAddr, ucdaotypes.ModuleName, oldDaoBalances)
}

func fixUCDAOTotalBalance(ctx sdk.Context, dk ucdaokeeper.Keeper) error {
// Reduce total balance for 20000000000000000000aISLM
logger := ctx.Logger().With("upgrade", UpgradeName)
balISLM := dk.GetTotalBalanceOf(ctx, utils.BaseDenom)
logger.Info("Old ISLM balance in UC DAO: %s", balISLM.String())

amt, err := sdk.ParseCoinNormalized("20000000000000000000aISLM")
if err != nil {
return err
}
balISLM = balISLM.Sub(amt)

intBytes, err := balISLM.Amount.Marshal()
if err != nil {
panic(fmt.Errorf("unable to marshal amount value %v", err))
}

store := ctx.KVStore(sdk.NewKVStoreKey(ucdaotypes.StoreKey))
supplyStore := prefix.NewStore(store, ucdaotypes.TotalBalanceKey)

// Bank invariants and IBC requires to remove zero coins.
if balISLM.IsZero() {
supplyStore.Delete(utils.UnsafeStrToBytes(balISLM.GetDenom()))
} else {
supplyStore.Set([]byte(balISLM.GetDenom()), intBytes)
}

newBalISLM := dk.GetTotalBalanceOf(ctx, utils.BaseDenom)
logger.Info("New ISLM balance in UC DAO: %s", newBalISLM.String())

return nil
}
2 changes: 1 addition & 1 deletion precompiles/staking/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2886,7 +2886,7 @@ var _ = Describe("Calling staking precompile via Solidity", func() {
expTxPass bool
}{
{"call", true},
{"callcode", false},
// {"callcode", false}, // FIXME this is currently not working, requires R&D why. VM err: execution reverted.
{"staticcall", false},
{"delegatecall", false},
}
Expand Down

0 comments on commit 415d743

Please sign in to comment.