From afe39374ad3d3446c690aba7ca6850ff12e22702 Mon Sep 17 00:00:00 2001 From: emidev98 Date: Thu, 17 Aug 2023 17:33:00 +0300 Subject: [PATCH] wip: upgrade 2.5 compile --- app/app.go | 262 ++++++++++-------- app/app_test.go | 37 ++- app/export.go | 6 +- app/simulation_test.go | 40 +-- app/upgrades/v2.5/upgrade.go | 28 +- client/docs/config.json | 4 +- client/docs/swagger-ui/swagger.yaml | 4 +- cmd/terrad/genwasm.go | 29 -- cmd/terrad/root.go | 85 +++--- go.mod | 4 +- go.sum | 7 - scripts/chain-upgrade-tester/chain-upgrade.sh | 2 +- 12 files changed, 255 insertions(+), 253 deletions(-) delete mode 100644 cmd/terrad/genwasm.go diff --git a/app/app.go b/app/app.go index b28fa763..5d9d64da 100644 --- a/app/app.go +++ b/app/app.go @@ -1,6 +1,7 @@ package app import ( + "encoding/json" "io" "net/http" "os" @@ -11,18 +12,20 @@ import ( "github.com/terra-money/core/v2/app/rpc" + dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" tmos "github.com/cometbft/cometbft/libs/os" "github.com/gorilla/mux" "github.com/rakyll/statik/fs" "github.com/spf13/cast" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec/types" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/cosmos/cosmos-sdk/baseapp" + nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server/api" @@ -52,7 +55,6 @@ import ( crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" distr "github.com/cosmos/cosmos-sdk/x/distribution" - distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client" distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/evidence" @@ -75,12 +77,14 @@ import ( mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" + consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" + "github.com/cosmos/cosmos-sdk/x/params" paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" - "github.com/cosmos/cosmos-sdk/x/slashing" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" @@ -113,7 +117,8 @@ import ( ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client" ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" - ibchost "github.com/cosmos/ibc-go/v7/modules/core/24-host" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine" ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" @@ -131,7 +136,6 @@ import ( ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types" "github.com/CosmWasm/wasmd/x/wasm" - wasmclient "github.com/CosmWasm/wasmd/x/wasm/client" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/prometheus/client_golang/prometheus" @@ -148,8 +152,6 @@ import ( alliancekeeper "github.com/terra-money/alliance/x/alliance/keeper" alliancetypes "github.com/terra-money/alliance/x/alliance/types" - // this line is used by starport scaffolding # stargate/app/moduleImport - tmjson "github.com/cometbft/cometbft/libs/json" "github.com/terra-money/core/v2/app/ante" @@ -166,7 +168,6 @@ import ( _ "github.com/terra-money/core/v2/client/docs/statik" ) -// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals var ( // If EnabledSpecificProposals is "", and this is "true", then enable all x/wasm proposals. // If EnabledSpecificProposals is "", and this is not "true", then disable all x/wasm proposals. @@ -207,12 +208,9 @@ func GetWasmOpts(app *TerraApp, appOpts servertypes.AppOptions) []wasm.Option { func getGovProposalHandlers() []govclient.ProposalHandler { var govProposalHandlers []govclient.ProposalHandler - // this line is used by starport scaffolding # stargate/app/govProposalHandlers - govProposalHandlers = wasmclient.ProposalHandlers govProposalHandlers = append(govProposalHandlers, paramsclient.ProposalHandler, - distrclient.ProposalHandler, upgradeclient.LegacyProposalHandler, upgradeclient.LegacyCancelProposalHandler, ibcclientclient.UpdateClientProposalHandler, @@ -220,7 +218,6 @@ func getGovProposalHandlers() []govclient.ProposalHandler { allianceclient.CreateAllianceProposalHandler, allianceclient.UpdateAllianceProposalHandler, allianceclient.DeleteAllianceProposalHandler, - // this line is used by starport scaffolding # stargate/app/govProposalHandler ) return govProposalHandlers @@ -259,7 +256,6 @@ var ( router.AppModuleBasic{}, authzmodule.AppModuleBasic{}, tokenfactory.AppModuleBasic{}, - // this line is used by starport scaffolding # stargate/app/moduleBasic ibchooks.AppModuleBasic{}, wasm.AppModuleBasic{}, alliance.AppModuleBasic{}, @@ -275,12 +271,11 @@ var ( stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, govtypes.ModuleName: {authtypes.Burner}, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - // this line is used by starport scaffolding # stargate/app/maccPerms - ibcfeetypes.ModuleName: nil, - wasm.ModuleName: {authtypes.Burner}, - tokenfactorytypes.ModuleName: {authtypes.Burner, authtypes.Minter}, - alliancetypes.ModuleName: {authtypes.Burner, authtypes.Minter}, - alliancetypes.RewardsPoolName: nil, + ibcfeetypes.ModuleName: nil, + wasm.ModuleName: {authtypes.Burner}, + tokenfactorytypes.ModuleName: {authtypes.Burner, authtypes.Minter}, + alliancetypes.ModuleName: {authtypes.Burner, authtypes.Minter}, + alliancetypes.RewardsPoolName: nil, } ) @@ -315,29 +310,30 @@ type TerraApp struct { memKeys map[string]*storetypes.MemoryStoreKey // keepers - AccountKeeper authkeeper.AccountKeeper - BankKeeper bankkeeper.Keeper - CapabilityKeeper *capabilitykeeper.Keeper - StakingKeeper stakingkeeper.Keeper - SlashingKeeper slashingkeeper.Keeper - MintKeeper mintkeeper.Keeper - DistrKeeper distrkeeper.Keeper - GovKeeper govkeeper.Keeper - CrisisKeeper crisiskeeper.Keeper - UpgradeKeeper upgradekeeper.Keeper - ParamsKeeper paramskeeper.Keeper - IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly - EvidenceKeeper evidencekeeper.Keeper - TransferKeeper ibctransferkeeper.Keeper - AuthzKeeper authzkeeper.Keeper - FeeGrantKeeper feegrantkeeper.Keeper - ICAControllerKeeper icacontrollerkeeper.Keeper - ICAHostKeeper icahostkeeper.Keeper - InterTxKeeper intertxkeeper.Keeper - IBCFeeKeeper ibcfeekeeper.Keeper - RouterKeeper routerkeeper.Keeper - TokenFactoryKeeper tokenfactorykeeper.Keeper - AllianceKeeper alliancekeeper.Keeper + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.Keeper + CapabilityKeeper *capabilitykeeper.Keeper + StakingKeeper stakingkeeper.Keeper + SlashingKeeper slashingkeeper.Keeper + MintKeeper mintkeeper.Keeper + DistrKeeper distrkeeper.Keeper + GovKeeper *govkeeper.Keeper + CrisisKeeper *crisiskeeper.Keeper + UpgradeKeeper *upgradekeeper.Keeper + ParamsKeeper paramskeeper.Keeper + ConsensusParamsKeeper consensusparamkeeper.Keeper + IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly + EvidenceKeeper evidencekeeper.Keeper + TransferKeeper ibctransferkeeper.Keeper + AuthzKeeper authzkeeper.Keeper + FeeGrantKeeper feegrantkeeper.Keeper + ICAControllerKeeper icacontrollerkeeper.Keeper + ICAHostKeeper icahostkeeper.Keeper + InterTxKeeper intertxkeeper.Keeper + IBCFeeKeeper ibcfeekeeper.Keeper + RouterKeeper routerkeeper.Keeper + TokenFactoryKeeper tokenfactorykeeper.Keeper + AllianceKeeper alliancekeeper.Keeper // IBC hooks IBCHooksKeeper *ibchookskeeper.Keeper @@ -352,13 +348,12 @@ type TerraApp struct { ScopedICAHostKeeper capabilitykeeper.ScopedKeeper ScopedInterTxKeeper capabilitykeeper.ScopedKeeper - // this line is used by starport scaffolding # stargate/app/keeperDeclaration wasmKeeper wasm.Keeper scopedWasmKeeper capabilitykeeper.ScopedKeeper // the module manager - mm *module.Manager - + mm *module.Manager + basicManager module.BasicManager // the configurator configurator module.Configurator } @@ -389,12 +384,11 @@ func NewTerraApp( keys := sdk.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, + govtypes.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, intertxtypes.StoreKey, authzkeeper.StoreKey, feegrant.StoreKey, icahosttypes.StoreKey, icacontrollertypes.StoreKey, routertypes.StoreKey, tokenfactorytypes.StoreKey, wasm.StoreKey, ibcfeetypes.StoreKey, ibchookstypes.StoreKey, alliancetypes.StoreKey, - // this line is used by starport scaffolding # stargate/app/storeKey ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -413,51 +407,87 @@ func NewTerraApp( app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) // set the BaseApp's parameter store - bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())) + app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String()) + bApp.SetParamStore(&app.ConsensusParamsKeeper) // add capability keeper and ScopeToModule for ibc module app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) // grant capabilities for the ibc and ibc-transfer modules - scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) + scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) scopedInterTxKeeper := app.CapabilityKeeper.ScopeToModule(intertxtypes.ModuleName) scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName) scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) - // this line is used by starport scaffolding # stargate/app/scopedKeeper scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName) // add keepers app.AccountKeeper = authkeeper.NewAccountKeeper( - appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, terraappconfig.AccountAddressPrefix, + appCodec, + keys[authtypes.StoreKey], + authtypes.ProtoBaseAccount, + maccPerms, + terraappconfig.AccountAddressPrefix, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) app.BankKeeper = bankkeeper.NewBaseKeeper( - appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(), + appCodec, + keys[banktypes.StoreKey], + app.AccountKeeper, + app.ModuleAccountAddrs(), + authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) stakingKeeper := stakingkeeper.NewKeeper( - appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), + appCodec, + keys[stakingtypes.StoreKey], + app.AccountKeeper, + app.BankKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) app.MintKeeper = mintkeeper.NewKeeper( - appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper, - app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, + appCodec, + keys[minttypes.StoreKey], + stakingKeeper, + app.AccountKeeper, + app.BankKeeper, + authtypes.FeeCollectorName, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) app.DistrKeeper = distrkeeper.NewKeeper( - appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper, - &stakingKeeper, authtypes.FeeCollectorName, + appCodec, + keys[distrtypes.StoreKey], + app.AccountKeeper, + app.BankKeeper, + stakingKeeper, + authtypes.FeeCollectorName, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) app.SlashingKeeper = slashingkeeper.NewKeeper( - appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName), + appCodec, + app.LegacyAmino(), + keys[slashingtypes.StoreKey], + stakingKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) app.CrisisKeeper = crisiskeeper.NewKeeper( - app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName, + appCodec, + keys[crisistypes.StoreKey], + invCheckPeriod, + app.BankKeeper, + authtypes.FeeCollectorName, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) app.UpgradeKeeper = upgradekeeper.NewKeeper( skipUpgradeHeights, keys[upgradetypes.StoreKey], - appCodec, homePath, nil, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + appCodec, + homePath, + app.BaseApp, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) // upgrade handlers app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) @@ -470,13 +500,18 @@ func NewTerraApp( app.BankKeeper, &app.StakingKeeper, app.DistrKeeper, + authtypes.FeeCollectorName, ) - app.BankKeeper.RegisterKeepers(app.AllianceKeeper, &stakingKeeper) + app.BankKeeper.RegisterKeepers(app.AllianceKeeper, stakingKeeper) // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks - app.StakingKeeper = *stakingKeeper.SetHooks( - stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks(), app.AllianceKeeper.StakingHooks()), + app.StakingKeeper.SetHooks( + stakingtypes.NewMultiStakingHooks( + app.DistrKeeper.Hooks(), + app.SlashingKeeper.Hooks(), + app.AllianceKeeper.StakingHooks(), + ), ) // ... other modules keepers @@ -490,7 +525,7 @@ func NewTerraApp( // Create IBC Keeper app.IBCKeeper = ibckeeper.NewKeeper( - appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper, + appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper, ) app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) @@ -500,7 +535,6 @@ func NewTerraApp( govRouter := govtypesv1beta1.NewRouter() govRouter.AddRoute(govtypes.RouterKey, govtypesv1beta1.ProposalHandler). AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). - AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)). AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)). AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)). AddRoute(alliancetypes.RouterKey, alliance.NewAllianceProposalHandler(app.AllianceKeeper)) @@ -585,20 +619,19 @@ func NewTerraApp( // If evidence needs to be handled for the app, set routes in router here and seal app.EvidenceKeeper = *evidenceKeeper - // this line is used by starport scaffolding # stargate/app/keeperDefinition wasmDir := filepath.Join(homePath, "data") // The last arguments can contain custom message handlers, and custom query handlers, // if we want to allow any custom callbacks - supportedFeatures := "iterator,staking,stargate,token_factory,cosmwasm_1_1" + availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,token_factory" app.wasmKeeper = wasm.NewKeeper( appCodec, keys[wasm.StoreKey], - app.GetSubspace(wasm.ModuleName), app.AccountKeeper, app.BankKeeper, app.StakingKeeper, - app.DistrKeeper, + distrkeeper.NewQuerier(app.DistrKeeper), + app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, scopedWasmKeeper, @@ -607,12 +640,12 @@ func NewTerraApp( app.GRPCQueryRouter(), wasmDir, wasmConfig.ToWasmConfig(), - supportedFeatures, + availableCapabilities, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), GetWasmOpts(app, appOpts)..., ) - contractKeeper := wasmkeeper.NewDefaultPermissionKeeper(app.wasmKeeper) - app.Ics20WasmHooks.ContractKeeper = contractKeeper + app.Ics20WasmHooks.ContractKeeper = &app.wasmKeeper // register wasm gov proposal types enabledProposals := GetEnabledProposals() @@ -636,15 +669,9 @@ func NewTerraApp( app.IBCKeeper.SetRouter(ibcRouter) app.GovKeeper = govkeeper.NewKeeper( - appCodec, - keys[govtypes.StoreKey], - app.GetSubspace(govtypes.ModuleName), - app.AccountKeeper, - app.BankKeeper, - &stakingKeeper, - govRouter, - app.MsgServiceRouter(), - govtypes.DefaultConfig(), + appCodec, keys[govtypes.StoreKey], app.AccountKeeper, + app.BankKeeper, stakingKeeper, + app.MsgServiceRouter(), govtypes.DefaultConfig(), authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) /**** Module Options ****/ @@ -661,17 +688,17 @@ func NewTerraApp( app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx, encodingConfig.TxConfig, ), - auth.NewAppModule(appCodec, app.AccountKeeper, nil), + auth.NewAppModule(appCodec, app.AccountKeeper, nil, app.GetSubspace(authtypes.ModuleName)), vesting.NewAppModule(app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.StakingKeeper), - alliancebank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), - capability.NewAppModule(appCodec, *app.CapabilityKeeper), - crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), + alliancebank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(alliancetypes.ModuleName)), + capability.NewAppModule(appCodec, *app.CapabilityKeeper, false), + crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), - gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), - mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil), - slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)), + mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)), + slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)), + distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)), + staking.NewAppModule(appCodec, &app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)), upgrade.NewAppModule(app.UpgradeKeeper), evidence.NewAppModule(app.EvidenceKeeper), ibc.NewAppModule(app.IBCKeeper), @@ -682,8 +709,7 @@ func NewTerraApp( ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper), intertx.NewAppModule(appCodec, app.InterTxKeeper), router.NewAppModule(&app.RouterKeeper), - // this line is used by starport scaffolding # stargate/app/appModule - wasm.NewAppModule(appCodec, &app.wasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + wasm.NewAppModule(appCodec, &app.wasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)), ibchooks.NewAppModule(app.AccountKeeper), tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper), alliance.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), @@ -711,7 +737,7 @@ func NewTerraApp( paramstypes.ModuleName, vestingtypes.ModuleName, // additional modules - ibchost.ModuleName, + ibcexported.ModuleName, ibctransfertypes.ModuleName, icatypes.ModuleName, ibcfeetypes.ModuleName, @@ -741,7 +767,7 @@ func NewTerraApp( upgradetypes.ModuleName, vestingtypes.ModuleName, // additional non simd modules - ibchost.ModuleName, + ibcexported.ModuleName, ibctransfertypes.ModuleName, icatypes.ModuleName, ibcfeetypes.ModuleName, @@ -775,8 +801,7 @@ func NewTerraApp( upgradetypes.ModuleName, vestingtypes.ModuleName, feegrant.ModuleName, - // this line is used by starport scaffolding # stargate/app/initGenesis - ibchost.ModuleName, + ibcexported.ModuleName, ibctransfertypes.ModuleName, icatypes.ModuleName, ibcfeetypes.ModuleName, @@ -788,8 +813,7 @@ func NewTerraApp( alliancetypes.ModuleName, ) - app.mm.RegisterInvariants(&app.CrisisKeeper) - app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino) + app.mm.RegisterInvariants(app.CrisisKeeper) app.mm.RegisterServices(app.configurator) // initialize stores app.MountKVStores(keys) @@ -862,7 +886,6 @@ func NewTerraApp( app.ScopedTransferKeeper = scopedTransferKeeper app.ScopedICAControllerKeeper = scopedICAControllerKeeper app.ScopedICAHostKeeper = scopedICAHostKeeper - // this line is used by starport scaffolding # stargate/app/beforeInitReturn app.scopedWasmKeeper = scopedWasmKeeper app.ScopedInterTxKeeper = scopedInterTxKeeper @@ -979,6 +1002,8 @@ func (app *TerraApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIC authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) // Register new tendermint queries routes from grpc-gateway. tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + // Register node gRPC service for grpc-gateway. + nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) // Register legacy and grpc-gateway routes for all modules. ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) @@ -1019,7 +1044,13 @@ func (app *TerraApp) RegisterUpgradeHandlers(cfg module.Configurator) { ) app.UpgradeKeeper.SetUpgradeHandler( terraappconfig.Upgrade2_5, - v2_5.CreateUpgradeHandler(app.mm, app.configurator), + v2_5.CreateUpgradeHandler(app.mm, + app.configurator, + app.appCodec, + app.IBCKeeper.ClientKeeper, + app.ParamsKeeper, + app.ConsensusParamsKeeper, + ), ) } @@ -1056,14 +1087,13 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypesv1.ParamKeyTable()) paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(ibctransfertypes.ModuleName) - paramsKeeper.Subspace(ibchost.ModuleName) + paramsKeeper.Subspace(ibcexported.ModuleName) paramsKeeper.Subspace(icahosttypes.SubModuleName) paramsKeeper.Subspace(routertypes.ModuleName).WithKeyTable(routertypes.ParamKeyTable()) paramsKeeper.Subspace(tokenfactorytypes.ModuleName) paramsKeeper.Subspace(icacontrollertypes.SubModuleName) paramsKeeper.Subspace(alliancetypes.ModuleName) - // this line is used by starport scaffolding # stargate/app/paramSubspace paramsKeeper.Subspace(wasm.ModuleName) return paramsKeeper @@ -1148,16 +1178,16 @@ func (app *TerraApp) SimulationManager() *module.SimulationManager { appCodec := app.appCodec // create the simulation manager and define the order of the modules for deterministic simulations sm := module.NewSimulationManager( - auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), + auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), - bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), - capability.NewAppModule(appCodec, *app.CapabilityKeeper), + bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)), + capability.NewAppModule(appCodec, *app.CapabilityKeeper, false), feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), - gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), - mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, minttypes.DefaultInflationCalculationFn), - staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), - distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)), + mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)), + staking.NewAppModule(appCodec, &app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)), + distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)), + slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(stakingtypes.ModuleName)), params.NewAppModule(app.ParamsKeeper), evidence.NewAppModule(app.EvidenceKeeper), ibc.NewAppModule(app.IBCKeeper), @@ -1165,13 +1195,23 @@ func (app *TerraApp) SimulationManager() *module.SimulationManager { ibcfee.NewAppModule(app.IBCFeeKeeper), ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper), router.NewAppModule(&app.RouterKeeper), - wasm.NewAppModule(appCodec, &app.wasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + wasm.NewAppModule(appCodec, &app.wasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasm.ModuleName)), tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper), alliance.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), // does not implement simulation // intertx.NewAppModule(appCodec, app.InterTxKeeper), // ibchooks.NewAppModule(app.AccountKeeper), ) + sm.RegisterStoreDecoders() return sm } + +// DefaultGenesis returns a default genesis from the registered AppModuleBasic's. +func (a *TerraApp) DefaultGenesis() map[string]json.RawMessage { + return a.basicManager.DefaultGenesis(a.appCodec) +} + +func (app *TerraApp) RegisterNodeService(clientCtx client.Context) { + nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter()) +} diff --git a/app/app_test.go b/app/app_test.go index 369619cb..e9085a3a 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -5,18 +5,18 @@ import ( "os" "testing" + dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + mocktestutils "github.com/cosmos/cosmos-sdk/testutil/mock" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" - dbm "github.com/tendermint/tm-db" "github.com/terra-money/core/v2/app/wasmconfig" - "cosmossdk.io/simapp" tmtypes "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/cosmos/cosmos-sdk/tests/mocks" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" @@ -43,7 +43,6 @@ import ( ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" "github.com/cosmos/ibc-go/v7/modules/apps/transfer" ibc "github.com/cosmos/ibc-go/v7/modules/core" - "github.com/cosmos/ibc-go/v7/testing/mock" "github.com/strangelove-ventures/packet-forward-middleware/v7/router" "github.com/CosmWasm/wasmd/x/wasm" @@ -69,11 +68,11 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { db := dbm.NewMemDB() app := NewTerraApp( log.NewTMLogger(log.NewSyncWriter(os.Stdout)), - db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0, encCfg, - simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig()) + db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, + simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig()) // generate validator private/public key - privVal := mock.NewPV() + privVal := mocktestutils.NewPV() pubKey, err := privVal.GetPubKey() require.NoError(t, err) @@ -105,9 +104,9 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { // Making a new app object with the db, so that initchain hasn't been called app2 := NewTerraApp( log.NewTMLogger(log.NewSyncWriter(os.Stdout)), - db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0, - encCfg, simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig()) - _, err = app2.ExportAppStateAndValidators(false, []string{}) + db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, + encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig()) + _, err = app2.ExportAppStateAndValidators(false, []string{}, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } @@ -122,7 +121,7 @@ func TestInitGenesisOnMigration(t *testing.T) { logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) app := NewTerraApp( logger, db, nil, true, map[int64]bool{}, - simapp.DefaultNodeHome, 0, encCfg, simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig()) + DefaultNodeHome, 0, encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig()) ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) @@ -130,7 +129,7 @@ func TestInitGenesisOnMigration(t *testing.T) { // adding during a migration. mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockModule := mocks.NewMockAppModule(mockCtrl) + mockModule := mocktestutils.NewMockAppModuleWithAllExtensions(mockCtrl) mockDefaultGenesis := json.RawMessage(`{"key": "value"}`) mockModule.EXPECT().DefaultGenesis(gomock.Eq(app.appCodec)).Times(1).Return(mockDefaultGenesis) mockModule.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(app.appCodec), gomock.Eq(mockDefaultGenesis)).Times(1).Return(nil) @@ -174,7 +173,7 @@ func TestLegacyAmino(t *testing.T) { app := NewTerraApp( log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, - encCfg, simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig()) + encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig()) require.Equal(t, encCfg.Amino, app.LegacyAmino()) } @@ -185,7 +184,7 @@ func TestAppCodec(t *testing.T) { app := NewTerraApp( log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, - encCfg, simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig()) + encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig()) require.Equal(t, encCfg.Marshaler, app.AppCodec()) } @@ -196,7 +195,7 @@ func TestInterfaceRegistry(t *testing.T) { app := NewTerraApp( log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, - encCfg, simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig()) + encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig()) require.Equal(t, encCfg.InterfaceRegistry, app.InterfaceRegistry()) } @@ -207,7 +206,7 @@ func TestGetKey(t *testing.T) { app := NewTerraApp( log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, - encCfg, simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig()) + encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig()) require.NotEmpty(t, app.GetKey(banktypes.StoreKey)) require.NotEmpty(t, app.GetTKey(paramstypes.TStoreKey)) @@ -219,8 +218,8 @@ func TestSimAppEnforceStakingForVestingTokens(t *testing.T) { db := dbm.NewMemDB() app := NewTerraApp( log.NewTMLogger(log.NewSyncWriter(os.Stdout)), - db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0, encCfg, - simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig(), + db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, + simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig(), ) genAccounts := authtypes.GenesisAccounts{ vestingtypes.NewContinuousVestingAccount( @@ -258,7 +257,7 @@ func TestSimAppEnforceStakingForVestingTokens(t *testing.T) { } // generate validator private/public key - privVal := mock.NewPV() + privVal := mocktestutils.NewPV() pubKey, err := privVal.GetPubKey() require.NoError(t, err, "PubKey should not have an error") validator := tmtypes.NewValidator(pubKey, 1) diff --git a/app/export.go b/app/export.go index 094b91a7..5dd21b7a 100644 --- a/app/export.go +++ b/app/export.go @@ -16,7 +16,9 @@ import ( // ExportAppStateAndValidators exports the state of the application for a genesis // file. func (app *TerraApp) ExportAppStateAndValidators( - forZeroHeight bool, jailAllowedAddrs []string, + forZeroHeight bool, + jailAllowedAddrs []string, + modulesToExport []string, ) (servertypes.ExportedApp, error) { // as if they could withdraw from the start of the next block ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) @@ -35,7 +37,7 @@ func (app *TerraApp) ExportAppStateAndValidators( return servertypes.ExportedApp{}, err } - validators, err := staking.WriteValidators(ctx, app.StakingKeeper) + validators, err := staking.WriteValidators(ctx, &app.StakingKeeper) if err != nil { return servertypes.ExportedApp{}, err } diff --git a/app/simulation_test.go b/app/simulation_test.go index 3faa0128..4f788ad9 100644 --- a/app/simulation_test.go +++ b/app/simulation_test.go @@ -4,28 +4,29 @@ import ( "os" "testing" + dbm "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" - dbm "github.com/tendermint/tm-db" abci "github.com/cometbft/cometbft/abci/types" "github.com/stretchr/testify/require" "github.com/terra-money/core/v2/app" "github.com/terra-money/core/v2/app/wasmconfig" - "cosmossdk.io/simapp" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simulationtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" ) func init() { - simapp.GetSimulatorFlags() + simcli.GetSimulatorFlags() } -type SimApp interface { +type AppTest interface { app.TerraApp GetBaseApp() *baseapp.BaseApp AppCodec() codec.Codec @@ -44,10 +45,11 @@ type SimApp interface { // Running as go benchmark test: // `go test -benchmem -run=^$ -bench ^BenchmarkSimulation ./app -NumBlocks=200 -BlockSize 50 -Commit=true -Verbose=true -Enabled=true` func BenchmarkSimulation(b *testing.B) { - simapp.FlagEnabledValue = true - simapp.FlagCommitValue = true + config := simcli.NewConfigFromFlags() + simcli.FlagEnabledValue = true + simcli.FlagCommitValue = true - config, db, dir, logger, _, err := simapp.SetupSimulation("goleveldb-app-sim", "Simulation") + db, dir, logger, _, err := simtestutil.SetupSimulation(config, "goleveldb-app-sim", "Simulation", true, false) require.NoError(b, err, "simulation setup failed") b.Cleanup(func() { @@ -58,7 +60,7 @@ func BenchmarkSimulation(b *testing.B) { encoding := app.MakeEncodingConfig() - simApp := app.NewTerraApp( + AppTest := app.NewTerraApp( logger, db, nil, @@ -67,7 +69,7 @@ func BenchmarkSimulation(b *testing.B) { app.DefaultNodeHome, 0, encoding, - simapp.EmptyAppOptions{}, + simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig(), ) @@ -75,22 +77,22 @@ func BenchmarkSimulation(b *testing.B) { _, simParams, simErr := simulation.SimulateFromSeed( b, os.Stdout, - simApp.BaseApp, - simapp.AppStateFn(simApp.AppCodec(), simApp.SimulationManager()), + AppTest.BaseApp, + simtestutil.AppStateFn(AppTest.AppCodec(), AppTest.SimulationManager(), app.DefaultGenesis()), simulationtypes.RandomAccounts, - simapp.SimulationOperations(simApp, simApp.AppCodec(), config), - simApp.ModuleAccountAddrs(), + simtestutil.SimulationOperations(AppTest, AppTest.AppCodec(), config), + AppTest.ModuleAccountAddrs(), config, - simApp.AppCodec(), + AppTest.AppCodec(), ) // export state and simParams before the simulation error is checked - err = simapp.CheckExportSimulation(simApp, config, simParams) + err = simtestutil.CheckExportSimulation(AppTest, config, simParams) require.NoError(b, err) require.NoError(b, simErr) if config.Commit { - simapp.PrintStats(db) + simtestutil.PrintStats(db) } } @@ -98,7 +100,7 @@ func TestSimulationManager(t *testing.T) { db := dbm.NewMemDB() encoding := app.MakeEncodingConfig() - simApp := app.NewTerraApp( + AppTest := app.NewTerraApp( log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, @@ -107,9 +109,9 @@ func TestSimulationManager(t *testing.T) { app.DefaultNodeHome, 0, encoding, - simapp.EmptyAppOptions{}, + simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig(), ) - sm := simApp.SimulationManager() + sm := AppTest.SimulationManager() require.NotNil(t, sm) } diff --git a/app/upgrades/v2.5/upgrade.go b/app/upgrades/v2.5/upgrade.go index fb7dd700..12a26369 100644 --- a/app/upgrades/v2.5/upgrade.go +++ b/app/upgrades/v2.5/upgrade.go @@ -1,24 +1,44 @@ package v2_5 import ( + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + clientkeeper "github.com/cosmos/ibc-go/v7/modules/core/02-client/keeper" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ibctmmigrations "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint/migrations" - "github.com/terra-money/core/v2/app" ) func CreateUpgradeHandler( mm *module.Manager, cfg module.Configurator, + cdc codec.Codec, + clientKeeper clientkeeper.Keeper, + paramsKeeper paramskeeper.Keeper, + consensusParamsKeeper consensuskeeper.Keeper, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // prune expired tendermint consensus states to save storage space - _, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, app.Codec, app.IBCKeeper.ClientKeeper) + + baseAppLegacySS := paramsKeeper.Subspace(baseapp.Paramspace). + WithKeyTable(paramstypes.ConsensusParamsKeyTable()) + baseapp.MigrateParams(ctx, baseAppLegacySS, &consensusParamsKeeper) + + // READ: https://github.com/cosmos/ibc-go/blob/v7.2.0/docs/migrations/v6-to-v7.md#chains + _, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, cdc, clientKeeper) if err != nil { return nil, err } - return app.mm.RunMigrations(ctx, app.configurator, fromVM) + // READ: https://github.com/cosmos/ibc-go/blob/v7.2.0/docs/migrations/v7-to-v7_1.md#chains + params := clientKeeper.GetParams(ctx) + params.AllowedClients = append(params.AllowedClients, ibcexported.Localhost) + clientKeeper.SetParams(ctx, params) + + return mm.RunMigrations(ctx, cfg, fromVM) } } diff --git a/client/docs/config.json b/client/docs/config.json index 0561e758..3a9fde87 100644 --- a/client/docs/config.json +++ b/client/docs/config.json @@ -2,8 +2,8 @@ "swagger": "2.0", "info": { "title": "Terra Core Rest API", - "description": "Rest Interface for Terra Core v2.4 https://github.com/terra-money/core", - "version": "2.4" + "description": "Rest Interface for Terra Core v2.5 https://github.com/terra-money/core", + "version": "2.5" }, "apis": [ { diff --git a/client/docs/swagger-ui/swagger.yaml b/client/docs/swagger-ui/swagger.yaml index f5a6ec88..e5c7afcf 100644 --- a/client/docs/swagger-ui/swagger.yaml +++ b/client/docs/swagger-ui/swagger.yaml @@ -1,8 +1,8 @@ swagger: '2.0' info: title: Terra Core Rest API - description: Rest Interface for Terra Core v2.4 https://github.com/terra-money/core - version: 2.4 + description: Rest Interface for Terra Core v2.5 https://github.com/terra-money/core + version: 2.5 paths: /terra/alliances: get: diff --git a/cmd/terrad/genwasm.go b/cmd/terrad/genwasm.go deleted file mode 100644 index 3be61bfe..00000000 --- a/cmd/terrad/genwasm.go +++ /dev/null @@ -1,29 +0,0 @@ -package main - -import ( - "github.com/cosmos/cosmos-sdk/client" - "github.com/spf13/cobra" - - wasmcli "github.com/CosmWasm/wasmd/x/wasm/client/cli" -) - -// AddGenesisWasmMsgCmd add wasm genesis message -func AddGenesisWasmMsgCmd(defaultNodeHome string) *cobra.Command { - txCmd := &cobra.Command{ - Use: "add-wasm-genesis-message", - Short: "Wasm genesis subcommands", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - genesisIO := wasmcli.NewDefaultGenesisIO() - txCmd.AddCommand( - wasmcli.GenesisStoreCodeCmd(defaultNodeHome, genesisIO), - wasmcli.GenesisInstantiateContractCmd(defaultNodeHome, genesisIO), - wasmcli.GenesisExecuteContractCmd(defaultNodeHome, genesisIO), - wasmcli.GenesisListContractsCmd(defaultNodeHome, genesisIO), - wasmcli.GenesisListCodesCmd(defaultNodeHome, genesisIO), - ) - - return txCmd -} diff --git a/cmd/terrad/root.go b/cmd/terrad/root.go index 9559685e..ae09cf5c 100644 --- a/cmd/terrad/root.go +++ b/cmd/terrad/root.go @@ -4,17 +4,17 @@ import ( "errors" "io" "os" - "path/filepath" + rosettaCmd "cosmossdk.io/tools/rosetta/cmd" + dbm "github.com/cometbft/cometbft-db" tmcli "github.com/cometbft/cometbft/libs/cli" "github.com/cometbft/cometbft/libs/log" "github.com/spf13/cast" + "github.com/spf13/cobra" "github.com/spf13/viper" - dbm "github.com/tendermint/tm-db" tmcfg "github.com/cometbft/cometbft/config" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" sdkconfig "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/debug" @@ -23,15 +23,14 @@ import ( "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" - "github.com/cosmos/cosmos-sdk/snapshots" - snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" - "github.com/cosmos/cosmos-sdk/store" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/crisis" + "github.com/cosmos/cosmos-sdk/x/genutil" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" terraapp "github.com/terra-money/core/v2/app" "github.com/terra-money/core/v2/app/params" @@ -93,7 +92,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { }, } - initRootCmd(rootCmd, encodingConfig) + initRootCmd(rootCmd, terraapp.ModuleBasics, encodingConfig) return rootCmd, encodingConfig } @@ -110,13 +109,14 @@ func initTendermintConfig() *tmcfg.Config { return cfg } -func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { +func initRootCmd(rootCmd *cobra.Command, moduleBasics module.BasicManager, encodingConfig params.EncodingConfig) { // TODO check gaia before make release candidate // authclient.Codec = encodingConfig.Marshaler + gentxModule := moduleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic) rootCmd.AddCommand( InitCmd(terraapp.ModuleBasics, terraapp.DefaultNodeHome), - genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, terraapp.DefaultNodeHome), + genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, terraapp.DefaultNodeHome, gentxModule.GenTxValidator), genutilcli.GenTxCmd(terraapp.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, terraapp.DefaultNodeHome), genutilcli.ValidateGenesisCmd(terraapp.ModuleBasics), AddGenesisAccountCmd(terraapp.DefaultNodeHome), @@ -136,7 +136,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { ) // add rosetta commands - rootCmd.AddCommand(server.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Marshaler)) + rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Marshaler)) } func addModuleInitFlags(startCmd *cobra.Command) { @@ -202,65 +202,42 @@ type appCreator struct { // newApp is an AppCreator func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application { - var cache sdk.MultiStorePersistentCache - if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) { - cache = store.NewCommitKVStoreCacheManager() - } + baseappOptions := server.DefaultBaseappOptions(appOpts) skipUpgradeHeights := make(map[int64]bool) for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) { skipUpgradeHeights[int64(h)] = true } - pruningOpts, err := server.GetPruningOptionsFromFlags(appOpts) - if err != nil { - panic(err) - } - - snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots") - err = os.MkdirAll(snapshotDir, os.ModePerm) - if err != nil { - panic(err) - } - - snapshotDB, err := sdk.NewLevelDB("metadata", snapshotDir) - if err != nil { - panic(err) - } - snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir) - if err != nil { - panic(err) - } - - snapshotOptions := snapshottypes.NewSnapshotOptions( - cast.ToUint64(appOpts.Get(server.FlagStateSyncSnapshotInterval)), - cast.ToUint32(appOpts.Get(server.FlagStateSyncSnapshotKeepRecent)), - ) - return terraapp.NewTerraApp( - logger, db, traceStore, true, skipUpgradeHeights, + logger, + db, + traceStore, + true, + skipUpgradeHeights, cast.ToString(appOpts.Get(flags.FlagHome)), cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), a.encodingConfig, appOpts, wasmconfig.GetConfig(appOpts), - baseapp.SetPruning(pruningOpts), - baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))), - baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))), - baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(server.FlagHaltTime))), - baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(server.FlagMinRetainBlocks))), - baseapp.SetInterBlockCache(cache), - baseapp.SetTrace(cast.ToBool(appOpts.Get(server.FlagTrace))), - baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))), - baseapp.SetSnapshot(snapshotStore, snapshotOptions), - baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(flagIAVLCacheSize))), + baseappOptions..., ) } func (a appCreator) appExport( - logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, - appOpts servertypes.AppOptions) (servertypes.ExportedApp, error) { + logger log.Logger, + db dbm.DB, + traceStore io.Writer, + height int64, + forZeroHeight bool, + jailAllowedAddrs []string, + appOpts servertypes.AppOptions, + modulesToExport []string, +) ( + servertypes.ExportedApp, + error, +) { homePath, ok := appOpts.Get(flags.FlagHome).(string) if !ok || homePath == "" { @@ -278,5 +255,5 @@ func (a appCreator) appExport( terraApp = terraapp.NewTerraApp(logger, db, traceStore, true, map[int64]bool{}, homePath, cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), a.encodingConfig, appOpts, wasmconfig.DefaultConfig()) } - return terraApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) + return terraApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) } diff --git a/go.mod b/go.mod index 41fe49cd..e2217a9b 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( cosmossdk.io/simapp v0.0.0-20230224204036-a6adb0821462 github.com/CosmWasm/wasmd v0.40.0 github.com/cometbft/cometbft v0.37.2 + github.com/cometbft/cometbft-db v0.8.0 github.com/cosmos/cosmos-sdk v0.47.4 github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20230803181732-7c8f814d3b79 @@ -21,7 +22,6 @@ require ( github.com/spf13/viper v1.16.0 github.com/strangelove-ventures/packet-forward-middleware/v7 v7.0.0-20230523193151-73dea436e53f github.com/stretchr/testify v1.8.4 - github.com/tendermint/tm-db v0.6.7 github.com/terra-money/alliance v0.2.3 ) @@ -58,13 +58,11 @@ require ( github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect - github.com/cometbft/cometbft-db v0.8.0 // indirect github.com/confio/ics23/go v0.9.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/gogoproto v1.4.10 // indirect - github.com/cosmos/gorocksdb v1.2.0 // indirect github.com/cosmos/iavl v0.20.0 // indirect github.com/cosmos/ics23/go v0.10.0 // indirect github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect diff --git a/go.sum b/go.sum index 049aea58..e31dd888 100644 --- a/go.sum +++ b/go.sum @@ -398,8 +398,6 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gogoproto v1.4.10 h1:QH/yT8X+c0F4ZDacDv3z+xE3WU1P1Z3wQoLMBRJoKuI= github.com/cosmos/gogoproto v1.4.10/go.mod h1:3aAZzeRWpAwr+SS/LLkICX2/kDFyaYVzckBDzygIxek= -github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y= -github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= github.com/cosmos/iavl v0.20.0 h1:fTVznVlepH0KK8NyKq8w+U7c2L6jofa27aFX6YGlm38= github.com/cosmos/iavl v0.20.0/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A= github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20230803181732-7c8f814d3b79 h1:pCxyhIxgWTabAQC5UerkITraHG3SwajdLKKMCFDWCv4= @@ -486,9 +484,6 @@ github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go. github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/ethereum/go-ethereum v1.10.17/go.mod h1:Lt5WzjM07XlXc95YzrhosmR4J9Ahd6X2wyEV2SvGhk0= -github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= -github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A= -github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 h1:7HZCaLC5+BZpmbhCOZJ293Lz68O7PYrF2EzeiFMwCLk= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= @@ -1143,8 +1138,6 @@ github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d h1:vfofYNRScrDd github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= -github.com/tendermint/tm-db v0.6.7 h1:fE00Cbl0jayAoqlExN6oyQJ7fR/ZtoVOmvPJ//+shu8= -github.com/tendermint/tm-db v0.6.7/go.mod h1:byQDzFkZV1syXr/ReXS808NxA2xvyuuVgXOJ/088L6I= github.com/terra-money/alliance v0.2.3 h1:Ibxjgm1HFE2JBUD28FR4Y0VExhcVReIfToBTxif3XJ0= github.com/terra-money/alliance v0.2.3/go.mod h1:zo6pmH0n6PjJRYBVfH33ov9l8KBt0756ZH4JEOrUemg= github.com/terra-money/cosmos-sdk v0.47.4-terra.rc.1 h1:4URIYtFOmoNbJCF8KybNVuSYmpq/iiH6mUk/6Wbcq8c= diff --git a/scripts/chain-upgrade-tester/chain-upgrade.sh b/scripts/chain-upgrade-tester/chain-upgrade.sh index 24541d98..2cbb1cf5 100644 --- a/scripts/chain-upgrade-tester/chain-upgrade.sh +++ b/scripts/chain-upgrade-tester/chain-upgrade.sh @@ -6,7 +6,7 @@ CHAIN_ID=pisco-1 CHAIN_HOME=.testnet ROOT=$(pwd) DENOM=uluna -SOFTWARE_UPGRADE_NAME="v2.4" +SOFTWARE_UPGRADE_NAME="v2.5" GOV_PERIOD="10s" VAL_MNEMONIC_1="clock post desk civil pottery foster expand merit dash seminar song memory figure uniform spice circle try happy obvious trash crime hybrid hood cushion"