Skip to content

Commit

Permalink
fix upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Jan 5, 2024
1 parent 0050a33 commit e634eb9
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 139 deletions.
9 changes: 9 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,9 @@ func New(
supply.NewAppModule(app.SupplyKeeper),
nft.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper),
)
app.mm.SetOrderPreBlockers(
upgradetypes.ModuleName,
)

// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
Expand Down Expand Up @@ -696,6 +699,7 @@ func New(

// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetPreBlocker(app.PreBlocker)
app.SetBeginBlocker(app.BeginBlocker)
anteHandler, err := NewAnteHandler(
HandlerOptions{
Expand Down Expand Up @@ -768,6 +772,11 @@ func (app *ChainApp) setPostHandler() {
// Name returns the name of the App
func (app *ChainApp) Name() string { return app.BaseApp.Name() }

// PreBlocker updates every pre begin block
func (app *ChainApp) PreBlocker(ctx sdk.Context, req abci.RequestBeginBlock) (sdk.ResponsePreBlock, error) {
return app.mm.PreBlock(ctx, req)
}

// BeginBlocker application updates every begin block
func (app *ChainApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
// backport: https://github.com/cosmos/cosmos-sdk/pull/16639
Expand Down
91 changes: 0 additions & 91 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,18 @@ import (
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"
"github.com/cosmos/cosmos-sdk/x/group"
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"
ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
clientkeeper "github.com/cosmos/ibc-go/v7/modules/core/02-client/keeper"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
ibctmmigrations "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint/migrations"
icaauthmoduletypes "github.com/crypto-org-chain/chain-main/v4/x/icaauth/types"
nfttransfertypes "github.com/crypto-org-chain/chain-main/v4/x/nft-transfer/types"
)

func (app *ChainApp) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper clientkeeper.Keeper) {
Expand Down Expand Up @@ -82,107 +77,21 @@ func (app *ChainApp) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper

// Migrate Tendermint consensus parameters from x/params module to a dedicated x/consensus module.
baseapp.MigrateParams(ctx, baseAppLegacySS, &app.ConsensusParamsKeeper)

Check warning on line 79 in app/upgrades.go

View check run for this annotation

Codecov / codecov/patch

app/upgrades.go#L78-L79

Added lines #L78 - L79 were not covered by tests

// the minimal commission rate of 5% (0.05)
// (default is needed to be set because of SDK store migrations that set the param)
stakingtypes.DefaultMinCommissionRate = sdk.NewDecWithPrec(5, 2)

app.StakingKeeper.IterateValidators(ctx, func(index int64, val stakingtypes.ValidatorI) (stop bool) {
if val.GetCommission().LT(stakingtypes.DefaultMinCommissionRate) {
validator, found := app.StakingKeeper.GetValidator(ctx, val.GetOperator())
if !found {
ctx.Logger().Error("validator not found", val)
return true
}
ctx.Logger().Info("update validator's commission rate to a minimal one", val)
validator.Commission.Rate = stakingtypes.DefaultMinCommissionRate
if validator.Commission.MaxRate.LT(stakingtypes.DefaultMinCommissionRate) {
validator.Commission.MaxRate = stakingtypes.DefaultMinCommissionRate
}
app.StakingKeeper.SetValidator(ctx, validator)
}
return false
})

icaModule := app.mm.Modules[icatypes.ModuleName].(ica.AppModule)

// set the ICS27 consensus version so InitGenesis is not run
fromVM[icatypes.ModuleName] = icaModule.ConsensusVersion()

// create ICS27 Controller submodule params
controllerParams := icacontrollertypes.Params{
ControllerEnabled: false,
}

// create ICS27 Host submodule params
hostParams := icahosttypes.Params{
HostEnabled: false,
AllowMessages: []string{
"/cosmos.authz.v1beta1.MsgExec",
"/cosmos.authz.v1beta1.MsgGrant",
"/cosmos.authz.v1beta1.MsgRevoke",
"/cosmos.bank.v1beta1.MsgSend",
"/cosmos.bank.v1beta1.MsgMultiSend",
"/cosmos.distribution.v1beta1.MsgSetWithdrawAddress",
"/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission",
"/cosmos.distribution.v1beta1.MsgFundCommunityPool",
"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
"/cosmos.gov.v1beta1.MsgVoteWeighted",
"/cosmos.gov.v1beta1.MsgSubmitProposal",
"/cosmos.gov.v1beta1.MsgDeposit",
"/cosmos.gov.v1beta1.MsgVote",
"/cosmos.staking.v1beta1.MsgCreateValidator",
"/cosmos.staking.v1beta1.MsgEditValidator",
"/cosmos.staking.v1beta1.MsgDelegate",
"/cosmos.staking.v1beta1.MsgUndelegate",
"/cosmos.staking.v1beta1.MsgBeginRedelegate",
"/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation",
"/cosmos.slashing.v1beta1.MsgUnjail",
"/ibc.applications.transfer.v1.MsgTransfer",
"/chainmain.nft_transfer.v1.MsgTransfer",
"/chainmain.nft.v1.MsgBurnNFT",
"/chainmain.nft.v1.MsgEditNFT",
"/chainmain.nft.v1.MsgIssueDenom",
"/chainmain.nft.v1.MsgMintNFT",
"/chainmain.nft.v1.MsgTransferNFT",
},
}

ctx.Logger().Info("start to init interchain account module...")

// initialize ICS27 module
icaModule.InitModule(ctx, controllerParams, hostParams)

ctx.Logger().Info("start to run module migrations...")

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

// testnets need to do a coordinated upgrade to keep in sync with current mainnet version
testnetPlanName := "v4.2.7-testnet"
app.UpgradeKeeper.SetUpgradeHandler(testnetPlanName, func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

if upgradeInfo.Name == planName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
group.ModuleName,
icacontrollertypes.StoreKey,
icahosttypes.StoreKey,
icaauthmoduletypes.StoreKey,
ibcfeetypes.StoreKey,
nfttransfertypes.StoreKey,
consensusparamtypes.StoreKey,
crisistypes.StoreKey,

Check warning on line 92 in app/upgrades.go

View check run for this annotation

Codecov / codecov/patch

app/upgrades.go#L91-L92

Added lines #L91 - L92 were not covered by tests
},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
Expand Down
34 changes: 28 additions & 6 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ def submit_gov_proposal(self, proposal, **kwargs):
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp

def gov_propose_legacy(self, proposer, kind, proposal, no_validate=False, **kwargs):
mode = kwargs.get("broadcast_mode", "block")
event_query_tx = mode != "block"
def gov_propose_legacy(
self,
proposer,
kind,
proposal,
no_validate=False,
event_query_tx=True,
**kwargs,
):
if kind == "software-upgrade":
rsp = json.loads(
self.raw(
Expand All @@ -41,7 +47,7 @@ def gov_propose_legacy(self, proposer, kind, proposal, no_validate=False, **kwar
description=proposal.get("description"),
upgrade_height=proposal.get("upgrade-height"),
upgrade_time=proposal.get("upgrade-time"),
upgrade_info=proposal.get("upgrade-info"),
upgrade_info=proposal.get("upgrade-info", "info"),
deposit=proposal.get("deposit"),
# basic
home=self.data_dir,
Expand Down Expand Up @@ -263,8 +269,24 @@ def cosmos_cli(self, i=0):
def submit_gov_proposal(self, proposer, i=0, **kwargs):
return self.cosmos_cli(i).submit_gov_proposal(proposer, **kwargs)

def gov_propose_legacy(self, proposer, kind, proposal, i=0, **kwargs):
return self.cosmos_cli(i).gov_propose_legacy(proposer, kind, proposal, **kwargs)
def gov_propose_legacy(
self,
proposer,
kind,
proposal,
i=0,
no_validate=False,
event_query_tx=True,
**kwargs,
):
return self.cosmos_cli(i).gov_propose_legacy(
proposer,
kind,
proposal,
no_validate,
event_query_tx,
**kwargs,
)

def transfer(self, from_, to, coins, i=0, generate_only=False, **kwargs):
return self.cosmos_cli(i).transfer(from_, to, coins, generate_only, **kwargs)
Expand Down
8 changes: 4 additions & 4 deletions integration_tests/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration_tests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pytest-github-actions-annotate-failures = "^0.1.7"
protobuf = "^3.20.2"
pyyaml = "^6.0.1"
python-dateutil = "^2.8.1"
pystarport = { git = "https://github.com/crypto-com/pystarport.git", branch = "main", rev = "1c3515549650497ff12fec4d2060a7e9cbaedf33" }
pystarport = { git = "https://github.com/mmsqe/pystarport.git", branch = "fix_json_loads", rev = "df257cc96feeb4873f4987f6e430e58f293cd0c6" }
chainlibpy = "^2.2.0"

# manually upgrade to make hatchling build success in poetry2nix
Expand Down
1 change: 0 additions & 1 deletion integration_tests/test_gov.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ def test_host_enabled(cluster):
}
],
},
broadcast_mode="sync",
)
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(cluster, rsp, msg=",/cosmos.gov.v1.MsgExecLegacyContent")
Expand Down
Loading

0 comments on commit e634eb9

Please sign in to comment.