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..f60036f23 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -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( @@ -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, @@ -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) diff --git a/integration_tests/poetry.lock b/integration_tests/poetry.lock index 22a221f3b..69994a98f 100644 --- a/integration_tests/poetry.lock +++ b/integration_tests/poetry.lock @@ -842,9 +842,9 @@ tomlkit = "^0.7.0" [package.source] type = "git" -url = "https://github.com/crypto-com/pystarport.git" -reference = "1c3515549650497ff12fec4d2060a7e9cbaedf33" -resolved_reference = "1c3515549650497ff12fec4d2060a7e9cbaedf33" +url = "https://github.com/mmsqe/pystarport.git" +reference = "df257cc96feeb4873f4987f6e430e58f293cd0c6" +resolved_reference = "df257cc96feeb4873f4987f6e430e58f293cd0c6" [[package]] name = "pytest" @@ -1217,4 +1217,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "3c7139251d8478b416b8efa506b5c6118ad0346d9fead29f96697007b6f74222" +content-hash = "769419b600cf606de74d03af5c9a177e7470464dbe984ad630d32db31d5431eb" diff --git a/integration_tests/pyproject.toml b/integration_tests/pyproject.toml index 79d910e92..be16c4189 100644 --- a/integration_tests/pyproject.toml +++ b/integration_tests/pyproject.toml @@ -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 diff --git a/integration_tests/test_gov.py b/integration_tests/test_gov.py index 829de03a8..22d36ebb3 100644 --- a/integration_tests/test_gov.py +++ b/integration_tests/test_gov.py @@ -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") diff --git a/integration_tests/test_upgrade.py b/integration_tests/test_upgrade.py index 53b639174..fd828926e 100644 --- a/integration_tests/test_upgrade.py +++ b/integration_tests/test_upgrade.py @@ -142,13 +142,21 @@ def test_cosmovisor(cosmovisor_cluster): wait_for_block(cluster, target_height + 2, 480) -def propose_and_pass(cluster, kind, proposal, cosmos_sdk_47=True, **kwargs): - if cosmos_sdk_47: +def propose_and_pass( + cluster, + kind, + proposal, + propose_legacy=True, + event_query_tx=True, + **kwargs, +): + if propose_legacy: rsp = cluster.gov_propose_legacy( "community", kind, proposal, - broadcast_mode="sync", + no_validate=True, + event_query_tx=event_query_tx, **kwargs, ) else: @@ -160,20 +168,23 @@ def propose_and_pass(cluster, kind, proposal, cosmos_sdk_47=True, **kwargs): ) assert rsp["code"] == 0, rsp["raw_log"] # get proposal_id - if cosmos_sdk_47: + if propose_legacy: proposal_id = get_proposal_id(rsp, ",/cosmos.gov.v1.MsgExecLegacyContent") else: ev = parse_events(rsp["logs"])["submit_proposal"] assert ev["proposal_type"] == "SoftwareUpgrade", rsp proposal_id = ev["proposal_id"] 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) - assert rsp["code"] == 0, rsp["raw_log"] - rsp = cluster.gov_vote("validator", proposal_id, "yes", i=1, event_query_tx=wait) - assert rsp["code"] == 0, rsp["raw_log"] + for i in range(2): + rsp = cluster.gov_vote( + "validator", + proposal_id, + "yes", + i=i, + event_query_tx=event_query_tx, + ) + assert rsp["code"] == 0, rsp["raw_log"] proposal = cluster.query_proposal(proposal_id) wait_for_block_time( @@ -185,9 +196,8 @@ def propose_and_pass(cluster, kind, proposal, cosmos_sdk_47=True, **kwargs): return proposal -def upgrade(cluster, plan_name, target_height, cosmos_sdk_47=True): +def upgrade(cluster, plan_name, target_height, propose_legacy=True): print("upgrade height", target_height) - propose_and_pass( cluster, "software-upgrade", @@ -198,7 +208,8 @@ def upgrade(cluster, plan_name, target_height, cosmos_sdk_47=True): "upgrade-height": target_height, "deposit": "0.1cro", }, - cosmos_sdk_47, + propose_legacy=propose_legacy, + event_query_tx=False, ) # wait for upgrade plan activated @@ -217,14 +228,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( @@ -269,7 +280,7 @@ def test_manual_upgrade(cosmovisor_cluster): wait_for_new_blocks(cluster, 1) target_height = cluster.block_height() + 15 - upgrade(cluster, "v2.0.0", target_height, cosmos_sdk_47=False) + upgrade(cluster, "v2.0.0", target_height, propose_legacy=False) def test_manual_upgrade_all(cosmovisor_cluster): @@ -342,7 +353,7 @@ def assert_commission(adr, expected): assert cluster.staking_pool() == old_bonded + 2009999498 target_height = cluster.block_height() + 30 - upgrade(cluster, "v3.0.0", target_height, cosmos_sdk_47=False) + upgrade(cluster, "v3.0.0", target_height, propose_legacy=False) rsp = cluster.delegate_amount( validator2_operator_address, @@ -372,16 +383,15 @@ def assert_commission(adr, expected): "creator": creator, }, ev - target_height = cluster.block_height() + 30 - upgrade(cluster, "v4.0.0", target_height, cosmos_sdk_47=False) + target_height = cluster.block_height() + 15 + upgrade(cluster, "v4.2.0", target_height, propose_legacy=False) cli = cluster.cosmos_cli() # check denom after upgrade rsp = cluster.query_nft(denomid) - print("mm-nft", rsp) assert rsp["name"] == denomname, rsp - # assert rsp["uri"] == "", rsp + assert rsp["uri"] == "", rsp # check icaauth params rsp = json.loads( @@ -407,16 +417,18 @@ def assert_commission(adr, expected): output="json", ) ) - print("mm-commission", rsp) - # print("min commission", rsp["min_commission_rate"]) + print("min commission", rsp["min_commission_rate"]) min_commission_rate = "0.050000000000000000" - # assert rsp["min_commission_rate"] == min_commission_rate, rsp + assert rsp["min_commission_rate"] == min_commission_rate, rsp assert_commission(validator1_operator_address, min_commission_rate) assert_commission(validator2_operator_address, default_rate) - target_height = cluster.block_height() + 30 - # upgrade(cluster, "sdk47-upgrade", target_height, cosmos_sdk_47=False) + target_height = cluster.block_height() + 15 + # test migrate keystore + for i in range(2): + cluster.migrate_keystore(i=i) + upgrade(cluster, "sdk47-upgrade", target_height, propose_legacy=True) def test_cancel_upgrade(cluster): @@ -441,7 +453,6 @@ def test_cancel_upgrade(cluster): "upgrade-height": upgrade_height, "deposit": "0.1cro", }, - no_validate=True, ) print("cancel upgrade plan") @@ -453,7 +464,6 @@ def test_cancel_upgrade(cluster): "description": "there is bug, cancel upgrade", "deposit": "0.1cro", }, - no_validate=True, ) # wait for blocks after upgrade, should success since upgrade is canceled diff --git a/integration_tests/upgrade-test.nix b/integration_tests/upgrade-test.nix index cc23e22a2..cd4497d9d 100644 --- a/integration_tests/upgrade-test.nix +++ b/integration_tests/upgrade-test.nix @@ -3,13 +3,20 @@ let released = (import (builtins.fetchTarball "https://github.com/crypto-org-chain/chain-main/archive/v1.1.0.tar.gz") { }).chain-maind; released2 = (import (builtins.fetchTarball "https://github.com/crypto-org-chain/chain-main/archive/v2.0.1.tar.gz") { }).chain-maind; released3 = (import (builtins.fetchTarball "https://github.com/crypto-org-chain/chain-main/archive/v3.3.4.tar.gz") { }).chain-maind; - released4 = (import (builtins.fetchTarball "https://github.com/crypto-org-chain/chain-main/archive/v4.0.0-alpha3-croeseid.tar.gz") { }).chain-maind; + fetchFlake = repo: rev: (pkgs.flake-compat { + src = { + outPath = builtins.fetchTarball "https://github.com/${repo}/archive/${rev}.tar.gz"; + inherit rev; + shortRev = builtins.substring 0 7 rev; + }; + }).defaultNix; + released4 = (fetchFlake "crypto-org-chain/chain-main" "b3226f06fd2a236f9957304c4d83b0ea06ed2604").default; current = pkgs.callPackage ../. { }; in 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; } ] diff --git a/nix/default.nix b/nix/default.nix index 393ce79c9..e6a4949a5 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -2,6 +2,7 @@ import sources.nixpkgs { overlays = [ (_: pkgs: { + flake-compat = import sources.flake-compat; cosmovisor = pkgs.buildGoModule rec { name = "cosmovisor"; src = sources.cosmos-sdk + "/cosmovisor"; diff --git a/nix/sources.json b/nix/sources.json index 20aba3331..f5551f6c9 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -46,5 +46,17 @@ "type": "tarball", "url": "https://github.com/NixOS/nixpkgs/archive/90aa73fc8e1550b16d1ebdc436e48d9951f7989b.tar.gz", "url_template": "https://github.com///archive/.tar.gz" + }, + "flake-compat": { + "branch": "master", + "description": null, + "homepage": null, + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "sha256": "1qc703yg0babixi6wshn5wm2kgl5y1drcswgszh4xxzbrwkk9sv7", + "type": "tarball", + "url": "https://github.com/edolstra/flake-compat/archive/b4a34015c698c7793d592d66adbab377907a2be8.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" } }