diff --git a/app/app.go b/app/app.go index 041eb8870..968f335ac 100644 --- a/app/app.go +++ b/app/app.go @@ -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 @@ -696,6 +699,7 @@ func New( // initialize BaseApp app.SetInitChainer(app.InitChainer) + app.SetPreBlocker(app.PreBlocker) app.SetBeginBlocker(app.BeginBlocker) anteHandler, err := NewAnteHandler( HandlerOptions{ @@ -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 diff --git a/app/upgrades.go b/app/upgrades.go index 6e14c46d6..29ea1ba9b 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -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) { @@ -82,85 +77,7 @@ 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) - - // 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) }) @@ -168,21 +85,13 @@ func (app *ChainApp) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper 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, }, } - // configure store loader that checks if version == upgradeHeight and applies store upgrades app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) } diff --git a/integration_tests/cosmoscli.py b/integration_tests/cosmoscli.py index 5441bedea..546a865da 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -26,31 +26,33 @@ def gov_propose_legacy(self, proposer, kind, proposal, no_validate=False, **kwar mode = kwargs.get("broadcast_mode", "block") event_query_tx = mode != "block" if kind == "software-upgrade": - rsp = json.loads( - self.raw( - "tx", - "gov", - "submit-legacy-proposal", - kind, - proposal["name"], - "-y", - "--no-validate" if no_validate else None, - from_=proposer, - # content - title=proposal.get("title"), - description=proposal.get("description"), - upgrade_height=proposal.get("upgrade-height"), - upgrade_time=proposal.get("upgrade-time"), - upgrade_info=proposal.get("upgrade-info"), - deposit=proposal.get("deposit"), - # basic - home=self.data_dir, - node=self.node_rpc, - keyring_backend="test", - chain_id=self.chain_id, - **kwargs, - ) + raw = self.raw( + "tx", + "gov", + "submit-legacy-proposal", + kind, + proposal["name"], + "-y", + "--no-validate" if no_validate else None, + from_=proposer, + # content + title=proposal.get("title"), + description=proposal.get("description"), + upgrade_height=proposal.get("upgrade-height"), + upgrade_time=proposal.get("upgrade-time"), + upgrade_info=proposal.get("upgrade-info", "info"), + deposit=proposal.get("deposit"), + # basic + home=self.data_dir, + node=self.node_rpc, + keyring_backend="test", + chain_id=self.chain_id, + **kwargs, ) + # skip success log info that breaks json.loads + brace_index = raw.index(b"{") + json_part = raw[brace_index:] + rsp = json.loads(json_part) if rsp["code"] == 0 and event_query_tx: rsp = self.event_query_tx_for(rsp["txhash"]) return rsp diff --git a/integration_tests/test_upgrade.py b/integration_tests/test_upgrade.py index 53b639174..53d31da90 100644 --- a/integration_tests/test_upgrade.py +++ b/integration_tests/test_upgrade.py @@ -144,11 +144,12 @@ def test_cosmovisor(cosmovisor_cluster): def propose_and_pass(cluster, kind, proposal, cosmos_sdk_47=True, **kwargs): if cosmos_sdk_47: + kwargs.setdefault("output", "json") rsp = cluster.gov_propose_legacy( "community", kind, proposal, - broadcast_mode="sync", + no_validate=True, **kwargs, ) else: @@ -169,10 +170,9 @@ def propose_and_pass(cluster, kind, proposal, cosmos_sdk_47=True, **kwargs): proposal = cluster.query_proposal(proposal_id) print("mm-proposal", proposal) assert proposal["status"] == "PROPOSAL_STATUS_VOTING_PERIOD", proposal - wait = cosmos_sdk_47 - rsp = cluster.gov_vote("validator", proposal_id, "yes", event_query_tx=wait) + rsp = cluster.gov_vote("validator", proposal_id, "yes", event_query_tx=False) assert rsp["code"] == 0, rsp["raw_log"] - rsp = cluster.gov_vote("validator", proposal_id, "yes", i=1, event_query_tx=wait) + rsp = cluster.gov_vote("validator", proposal_id, "yes", i=1, event_query_tx=False) assert rsp["code"] == 0, rsp["raw_log"] proposal = cluster.query_proposal(proposal_id) @@ -187,7 +187,6 @@ def propose_and_pass(cluster, kind, proposal, cosmos_sdk_47=True, **kwargs): def upgrade(cluster, plan_name, target_height, cosmos_sdk_47=True): print("upgrade height", target_height) - propose_and_pass( cluster, "software-upgrade", @@ -217,14 +216,14 @@ def upgrade(cluster, plan_name, target_height, cosmos_sdk_47=True): ) # check upgrade-info.json file is written - assert ( - json.load((cluster.home(0) / "data/upgrade-info.json").open()) - == json.load((cluster.home(1) / "data/upgrade-info.json").open()) - == { - "name": plan_name, - "height": target_height, - } - ) + js1 = json.load((cluster.home(0) / "data/upgrade-info.json").open()) + js2 = json.load((cluster.home(1) / "data/upgrade-info.json").open()) + expected = { + "name": plan_name, + "height": target_height, + } + assert js1 == js2 + assert expected.items() <= js1.items() # use the upgrade-test binary edit_chain_program( @@ -373,7 +372,7 @@ def assert_commission(adr, expected): }, ev target_height = cluster.block_height() + 30 - upgrade(cluster, "v4.0.0", target_height, cosmos_sdk_47=False) + upgrade(cluster, "v4.2.0", target_height, cosmos_sdk_47=False) cli = cluster.cosmos_cli() diff --git a/integration_tests/upgrade-test.nix b/integration_tests/upgrade-test.nix index cc23e22a2..1dbe2fd74 100644 --- a/integration_tests/upgrade-test.nix +++ b/integration_tests/upgrade-test.nix @@ -10,6 +10,6 @@ pkgs.linkFarm "upgrade-test-package" [ { name = "genesis"; path = released; } { name = "v2.0.0"; path = released2; } { name = "v3.0.0"; path = released3; } - { name = "v4.0.0"; path = released4; } + { name = "v4.2.0"; path = released4; } { name = "sdk47-upgrade"; path = current; } ]