From 45d61196276cf3908f1e96971a2ccb319927e2fe Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Wed, 6 Mar 2024 12:35:20 +0700 Subject: [PATCH] feat: add upgrade handler v4.1.3 --- app/app.go | 58 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/app/app.go b/app/app.go index b5db0a6c..fdd01773 100644 --- a/app/app.go +++ b/app/app.go @@ -45,9 +45,9 @@ import ( crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" distr "github.com/cosmos/cosmos-sdk/x/distribution" govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + icq "github.com/cosmos/ibc-apps/modules/async-icq/v7" solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine" ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" - icq "github.com/strangelove-ventures/async-icq/v7" distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -107,12 +107,12 @@ import ( ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router" + routerkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/keeper" + routertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/types" + icqkeeper "github.com/cosmos/ibc-apps/modules/async-icq/v7/keeper" + icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" ibcmock "github.com/cosmos/ibc-go/v7/testing/mock" - icqkeeper "github.com/strangelove-ventures/async-icq/v7/keeper" - icqtypes "github.com/strangelove-ventures/async-icq/v7/types" - "github.com/strangelove-ventures/packet-forward-middleware/v7/router" - routerkeeper "github.com/strangelove-ventures/packet-forward-middleware/v7/router/keeper" - routertypes "github.com/strangelove-ventures/packet-forward-middleware/v7/router/types" terracustombank "github.com/terra-money/core/v2/custom/bank" custombankkeeper "github.com/terra-money/core/v2/custom/bank/keeper" @@ -147,17 +147,19 @@ import ( tmproto "github.com/cometbft/cometbft/proto/tendermint/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/gorilla/mux" - "github.com/rakyll/statik/fs" "github.com/spf13/cast" "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" appparams "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/params" - v4 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_1_0" + // unnamed import of statik for swagger UI support + "github.com/rakyll/statik/fs" + v4 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_1_0" + v43 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_1_3" // unnamed import of statik for swagger UI support - _ "github.com/cosmos/cosmos-sdk/client/docs/statik" + _ "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/client/docs/statik" ) const ( @@ -647,15 +649,16 @@ func NewMigalooApp( app.Ics20WasmHooks.ContractKeeper = &app.WasmKeeper // ICQ Keeper + authority := authtypes.NewModuleAddress(govtypes.ModuleName).String() app.ICQKeeper = icqkeeper.NewKeeper( appCodec, keys[icqtypes.StoreKey], - app.GetSubspace(icqtypes.ModuleName), app.IBCKeeper.ChannelKeeper, // may be replaced with middleware app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, scopedICQKeeper, - app.BaseApp, // may be replaced + app.BaseApp.GRPCQueryRouter(), + authority, ) // Create Transfer Stack @@ -767,7 +770,7 @@ func NewMigalooApp( params.NewAppModule(app.ParamsKeeper), transfer.NewAppModule(app.TransferKeeper), icaModule, - icq.NewAppModule(app.ICQKeeper), + icq.NewAppModule(app.ICQKeeper, app.GetSubspace(icqtypes.ModuleName)), alliancemodule.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry, app.GetSubspace(alliancemoduletypes.ModuleName)), ibcfee.NewAppModule(app.IBCFeeKeeper), ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper), @@ -987,7 +990,6 @@ func (app *MigalooApp) ModuleConfigurator() module.Configurator { // BeginBlocker application updates every begin block func (app *MigalooApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { - BeginBlockForks(ctx, app) return app.mm.BeginBlock(ctx, req) } @@ -1108,17 +1110,27 @@ func (app *MigalooApp) AppCodec() codec.Codec { // RegisterSwaggerAPI registers swagger route with API Server func RegisterSwaggerAPI(rtr *mux.Router) { - statikFS, err := fs.New() + cosmosStatikFs, err := fs.New() + if err != nil { + panic(err) + } + + cosmosStaticServer := http.FileServer(cosmosStatikFs) + + statikFS, err := fs.NewWithNamespace("migaloo") if err != nil { panic(err) } staticServer := http.FileServer(statikFS) + + rtr.PathPrefix("/swagger/cosmos-sdk/").Handler(http.StripPrefix("/swagger/cosmos-sdk/", cosmosStaticServer)) rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer)) } // Setup Upgrade Handler func (app *MigalooApp) setupUpgradeHandlers() { + // !! ATTENTION !! // v4 upgrade handler // !! WHEN UPGRADING TO SDK v0.47 MAKE SURE TO INCLUDE THIS @@ -1135,6 +1147,14 @@ func (app *MigalooApp) setupUpgradeHandlers() { ), ) + app.UpgradeKeeper.SetUpgradeHandler( + v43.UpgradeName, + v43.CreateUpgradeHandler( + app.mm, + app.configurator, + ), + ) + // When a planned update height is reached, the old binary will panic // writing on disk the height and name of the update that triggered it // This will read that value, and execute the preparations for the upgrade. @@ -1157,6 +1177,7 @@ func (app *MigalooApp) setupUpgradeHandlers() { crisistypes.StoreKey, icqtypes.StoreKey, feeburnmoduletypes.StoreKey, + authtypes.FeeCollectorName, }, Deleted: []string{ "intertx", @@ -1165,6 +1186,15 @@ func (app *MigalooApp) setupUpgradeHandlers() { // configure store loader that checks if version == upgradeHeight and applies store upgrades app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades)) } + + if upgradeInfo.Name == v43.UpgradeName { + storeUpgrades := &storetypes.StoreUpgrades{ + Added: []string{}, + Deleted: []string{}, + } + // configure store loader that checks if version == upgradeHeight and applies store upgrades + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades)) + } } // GetMaccPerms returns a copy of the module account permissions