mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 16:25:21 +00:00
Add upgrade handler for Kava v0.26.0 (#1827)
* Add upgrade handler for Kava v0.26.0 * Update tests e2e to run upgrade tests
This commit is contained in:
parent
5914f1db85
commit
ad387e6a42
123
app/upgrades.go
123
app/upgrades.go
@ -1,3 +1,124 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
func (app App) RegisterUpgradeHandlers() {}
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
|
||||||
|
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
|
||||||
|
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||||
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
|
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||||
|
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||||
|
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||||
|
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
|
||||||
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
|
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
||||||
|
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
|
||||||
|
ibctmmigrations "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint/migrations"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
UpgradeName_Mainnet = "v0.26.0"
|
||||||
|
UpgradeName_Testnet = "v0.26.0-alpha.0"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RegisterUpgradeHandlers registers the upgrade handlers for the app.
|
||||||
|
func (app App) RegisterUpgradeHandlers() {
|
||||||
|
app.upgradeKeeper.SetUpgradeHandler(
|
||||||
|
UpgradeName_Mainnet,
|
||||||
|
upgradeHandler(app, UpgradeName_Mainnet),
|
||||||
|
)
|
||||||
|
app.upgradeKeeper.SetUpgradeHandler(
|
||||||
|
UpgradeName_Testnet,
|
||||||
|
upgradeHandler(app, UpgradeName_Testnet),
|
||||||
|
)
|
||||||
|
|
||||||
|
upgradeInfo, err := app.upgradeKeeper.ReadUpgradeInfoFromDisk()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
doUpgrade := upgradeInfo.Name == UpgradeName_Mainnet ||
|
||||||
|
upgradeInfo.Name == UpgradeName_Testnet
|
||||||
|
|
||||||
|
if doUpgrade && !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
|
||||||
|
storeUpgrades := storetypes.StoreUpgrades{
|
||||||
|
Added: []string{
|
||||||
|
crisistypes.ModuleName,
|
||||||
|
consensustypes.ModuleName,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// configure store loader that checks if version == upgradeHeight and applies store upgrades
|
||||||
|
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// upgradeHandler returns an UpgradeHandler for the given upgrade parameters.
|
||||||
|
func upgradeHandler(
|
||||||
|
app App,
|
||||||
|
name string,
|
||||||
|
) upgradetypes.UpgradeHandler {
|
||||||
|
return func(
|
||||||
|
ctx sdk.Context,
|
||||||
|
plan upgradetypes.Plan,
|
||||||
|
fromVM module.VersionMap,
|
||||||
|
) (module.VersionMap, error) {
|
||||||
|
app.Logger().Info(fmt.Sprintf("running %s upgrade handler", name))
|
||||||
|
|
||||||
|
baseAppLegacySS := app.paramsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
|
||||||
|
|
||||||
|
// Set param key table for params module migration
|
||||||
|
for _, subspace := range app.paramsKeeper.GetSubspaces() {
|
||||||
|
subspace := subspace
|
||||||
|
var keyTable paramstypes.KeyTable
|
||||||
|
switch subspace.Name() {
|
||||||
|
// sdk
|
||||||
|
case authtypes.ModuleName:
|
||||||
|
keyTable = authtypes.ParamKeyTable() //nolint:staticcheck
|
||||||
|
case banktypes.ModuleName:
|
||||||
|
keyTable = banktypes.ParamKeyTable() //nolint:staticcheck,nolintlint
|
||||||
|
case stakingtypes.ModuleName:
|
||||||
|
keyTable = stakingtypes.ParamKeyTable()
|
||||||
|
case minttypes.ModuleName:
|
||||||
|
keyTable = minttypes.ParamKeyTable() //nolint:staticcheck
|
||||||
|
case distrtypes.ModuleName:
|
||||||
|
keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck,nolintlint
|
||||||
|
case slashingtypes.ModuleName:
|
||||||
|
keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck
|
||||||
|
case govtypes.ModuleName:
|
||||||
|
keyTable = govv1.ParamKeyTable() //nolint:staticcheck
|
||||||
|
case crisistypes.ModuleName:
|
||||||
|
keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck
|
||||||
|
|
||||||
|
// ibc
|
||||||
|
case ibctransfertypes.ModuleName:
|
||||||
|
keyTable = ibctransfertypes.ParamKeyTable() //nolint:staticcheck
|
||||||
|
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !subspace.HasKeyTable() {
|
||||||
|
subspace.WithKeyTable(keyTable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// optional migration: prune expired tendermint consensus states to save storage space
|
||||||
|
// see https://github.com/cosmos/ibc-go/blob/v7.2.0/docs/migrations/v6-to-v7.md#chains
|
||||||
|
if _, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, app.appCodec, app.ibcKeeper.ClientKeeper); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate tendermint consensus parameters from x/params module to a
|
||||||
|
// dedicated x/consensus module.
|
||||||
|
baseapp.MigrateParams(ctx, baseAppLegacySS, &app.consensusParamsKeeper)
|
||||||
|
|
||||||
|
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -8,7 +8,7 @@ E2E_RUN_KVTOOL_NETWORKS=true
|
|||||||
|
|
||||||
# E2E_KVTOOL_KAVA_CONFIG_TEMPLATE is the kvtool template used to start the chain. See the `kava.configTemplate` flag in kvtool.
|
# E2E_KVTOOL_KAVA_CONFIG_TEMPLATE is the kvtool template used to start the chain. See the `kava.configTemplate` flag in kvtool.
|
||||||
# Note that the config tempalte must support overriding the docker image tag via the KAVA_TAG variable.
|
# Note that the config tempalte must support overriding the docker image tag via the KAVA_TAG variable.
|
||||||
E2E_KVTOOL_KAVA_CONFIG_TEMPLATE="v0.26"
|
E2E_KVTOOL_KAVA_CONFIG_TEMPLATE="v0.25"
|
||||||
|
|
||||||
# E2E_INCLUDE_IBC_TESTS when true will start a 2nd chain & open an IBC channel. It will enable all IBC tests.
|
# E2E_INCLUDE_IBC_TESTS when true will start a 2nd chain & open an IBC channel. It will enable all IBC tests.
|
||||||
E2E_INCLUDE_IBC_TESTS=true
|
E2E_INCLUDE_IBC_TESTS=true
|
||||||
@ -19,14 +19,14 @@ E2E_SKIP_SHUTDOWN=false
|
|||||||
|
|
||||||
# The following variables should be defined to run an upgrade.
|
# The following variables should be defined to run an upgrade.
|
||||||
# E2E_INCLUDE_AUTOMATED_UPGRADE when true enables the automated upgrade & corresponding tests in the suite.
|
# E2E_INCLUDE_AUTOMATED_UPGRADE when true enables the automated upgrade & corresponding tests in the suite.
|
||||||
E2E_INCLUDE_AUTOMATED_UPGRADE=false
|
E2E_INCLUDE_AUTOMATED_UPGRADE=true
|
||||||
# E2E_KAVA_UPGRADE_NAME is the name of the upgrade that must be in the current local image.
|
# E2E_KAVA_UPGRADE_NAME is the name of the upgrade that must be in the current local image.
|
||||||
E2E_KAVA_UPGRADE_NAME=
|
E2E_KAVA_UPGRADE_NAME=v0.26.0
|
||||||
# E2E_KAVA_UPGRADE_HEIGHT is the height at which the upgrade will be applied.
|
# E2E_KAVA_UPGRADE_HEIGHT is the height at which the upgrade will be applied.
|
||||||
# If IBC tests are enabled this should be >30. Otherwise, this should be >10.
|
# If IBC tests are enabled this should be >30. Otherwise, this should be >10.
|
||||||
E2E_KAVA_UPGRADE_HEIGHT=
|
E2E_KAVA_UPGRADE_HEIGHT=35
|
||||||
# E2E_KAVA_UPGRADE_BASE_IMAGE_TAG is the tag of the docker image the chain should upgrade from.
|
# E2E_KAVA_UPGRADE_BASE_IMAGE_TAG is the tag of the docker image the chain should upgrade from.
|
||||||
E2E_KAVA_UPGRADE_BASE_IMAGE_TAG=
|
E2E_KAVA_UPGRADE_BASE_IMAGE_TAG=v0.25.1-goleveldb
|
||||||
|
|
||||||
# E2E_KAVA_ERC20_ADDRESS is the address of a pre-deployed ERC20 token with the following properties:
|
# E2E_KAVA_ERC20_ADDRESS is the address of a pre-deployed ERC20 token with the following properties:
|
||||||
# - the E2E_KAVA_FUNDED_ACCOUNT_MNEMONIC has nonzero balance
|
# - the E2E_KAVA_FUNDED_ACCOUNT_MNEMONIC has nonzero balance
|
||||||
|
@ -1,18 +1,107 @@
|
|||||||
package e2e_test
|
package e2e_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"time"
|
||||||
|
|
||||||
|
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||||
|
tmtypes "github.com/cometbft/cometbft/types"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
|
||||||
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestUpgradeHandler can be used to run tests post-upgrade. If an upgrade is enabled, all tests
|
func (suite *IntegrationTestSuite) TestUpgradeParams_SDK() {
|
||||||
// are run against the upgraded chain. However, this file is a good place to consolidate all
|
|
||||||
// acceptance tests for a given set of upgrade handlers.
|
|
||||||
func (suite *IntegrationTestSuite) TestUpgradeHandler() {
|
|
||||||
suite.SkipIfUpgradeDisabled()
|
suite.SkipIfUpgradeDisabled()
|
||||||
fmt.Println("An upgrade has run!")
|
|
||||||
suite.True(true)
|
|
||||||
|
|
||||||
// Uncomment & use these contexts to compare chain state before & after the upgrade occurs.
|
beforeUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight - 1)
|
||||||
// beforeUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight - 1)
|
afterUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight)
|
||||||
// afterUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight)
|
|
||||||
|
// Before params
|
||||||
|
grpcClient := suite.Kava.Grpc
|
||||||
|
govParamsBefore, err := grpcClient.Query.Gov.Params(beforeUpgradeCtx, &govtypes.QueryParamsRequest{
|
||||||
|
ParamsType: govtypes.ParamDeposit,
|
||||||
|
})
|
||||||
|
suite.NoError(err)
|
||||||
|
govParamsAfter, err := grpcClient.Query.Gov.Params(afterUpgradeCtx, &govtypes.QueryParamsRequest{
|
||||||
|
ParamsType: govtypes.ParamDeposit,
|
||||||
|
})
|
||||||
|
suite.NoError(err)
|
||||||
|
|
||||||
|
// after upgrade, querying params before upgrade height returns nil
|
||||||
|
// since the param gprc query no longer queries x/params
|
||||||
|
suite.Run("x/gov parameters before upgrade", func() {
|
||||||
|
suite.Assert().Nil(
|
||||||
|
govParamsBefore.DepositParams.MaxDepositPeriod,
|
||||||
|
"x/gov DepositParams max deposit period before upgrade should be nil",
|
||||||
|
)
|
||||||
|
suite.Assert().Nil(
|
||||||
|
govParamsBefore.DepositParams.MinDeposit,
|
||||||
|
"x/gov DepositParams min deposit before upgrade should be 10_000_000 ukava",
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
suite.Run("x/gov parameters after upgrade", func() {
|
||||||
|
suite.Assert().Equal(
|
||||||
|
mustParseDuration("172800s"),
|
||||||
|
govParamsAfter.DepositParams.MaxDepositPeriod,
|
||||||
|
"x/gov DepositParams max deposit period after upgrade should be 172800s",
|
||||||
|
)
|
||||||
|
suite.Assert().Equal(
|
||||||
|
[]sdk.Coin{{Denom: "ukava", Amount: sdk.NewInt(10_000_000)}},
|
||||||
|
govParamsAfter.DepositParams.MinDeposit,
|
||||||
|
"x/gov DepositParams min deposit after upgrade should be 10_000_000 ukava",
|
||||||
|
)
|
||||||
|
|
||||||
|
expectedParams := govtypes.Params{
|
||||||
|
MinDeposit: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(10_000_000))),
|
||||||
|
MaxDepositPeriod: mustParseDuration("172800s"),
|
||||||
|
VotingPeriod: mustParseDuration("30s"),
|
||||||
|
Quorum: "0.334000000000000000",
|
||||||
|
Threshold: "0.500000000000000000",
|
||||||
|
VetoThreshold: "0.334000000000000000",
|
||||||
|
MinInitialDepositRatio: "0.000000000000000000",
|
||||||
|
BurnVoteQuorum: false,
|
||||||
|
BurnProposalDepositPrevote: false,
|
||||||
|
BurnVoteVeto: true,
|
||||||
|
}
|
||||||
|
suite.Require().Equal(expectedParams, *govParamsAfter.Params, "x/gov params after upgrade should be as expected")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *IntegrationTestSuite) TestUpgradeParams_Consensus() {
|
||||||
|
suite.SkipIfUpgradeDisabled()
|
||||||
|
|
||||||
|
afterUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight)
|
||||||
|
|
||||||
|
grpcClient := suite.Kava.Grpc
|
||||||
|
paramsAfter, err := grpcClient.Query.Consensus.Params(afterUpgradeCtx, &consensustypes.QueryParamsRequest{})
|
||||||
|
suite.NoError(err)
|
||||||
|
|
||||||
|
// v25 consensus params from x/params should be migrated to x/consensus
|
||||||
|
expectedParams := tmproto.ConsensusParams{
|
||||||
|
Block: &tmproto.BlockParams{
|
||||||
|
MaxBytes: 22020096,
|
||||||
|
MaxGas: 20000000,
|
||||||
|
},
|
||||||
|
Evidence: &tmproto.EvidenceParams{
|
||||||
|
MaxAgeNumBlocks: 100000,
|
||||||
|
MaxAgeDuration: *mustParseDuration("172800s"),
|
||||||
|
MaxBytes: 1048576,
|
||||||
|
},
|
||||||
|
Validator: &tmproto.ValidatorParams{
|
||||||
|
PubKeyTypes: []string{
|
||||||
|
tmtypes.ABCIPubKeyTypeEd25519,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Version: nil,
|
||||||
|
}
|
||||||
|
suite.Require().Equal(expectedParams, *paramsAfter.Params, "x/consensus params after upgrade should be as expected")
|
||||||
|
}
|
||||||
|
|
||||||
|
func mustParseDuration(s string) *time.Duration {
|
||||||
|
d, err := time.ParseDuration(s)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return &d
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user