Skip to content

Commit

Permalink
feat: add upgrade handler v4.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed Mar 6, 2024
1 parent dd7fdfd commit 45d6119
Showing 1 changed file with 44 additions and 14 deletions.
58 changes: 44 additions & 14 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -1157,6 +1177,7 @@ func (app *MigalooApp) setupUpgradeHandlers() {
crisistypes.StoreKey,
icqtypes.StoreKey,
feeburnmoduletypes.StoreKey,
authtypes.FeeCollectorName,
},
Deleted: []string{
"intertx",
Expand All @@ -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
Expand Down

0 comments on commit 45d6119

Please sign in to comment.