Skip to content

Commit

Permalink
Update app.go to correctly do module upgrade logic, add authz, IBC v2 (
Browse files Browse the repository at this point in the history
…#610)

* Update app.go to correctly do SDK module upgrade logic

* Add the logic for initializing txfees

* Add authz module

* Make corrections for InitGenesis handling to work

* Update to IBC v2
  • Loading branch information
ValarDragon authored Nov 21, 2021
1 parent 7891a34 commit f68d6ed
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 23 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* Upgraded Osmosis to Cosmos-sdk 0.44.2
* Upgrade to Cosmos-sdk 0.44.3
* Includes Rosetta API
* Upgrade to IBC-v2
* Add [Authz module](https://github.com/cosmos/cosmos-sdk/tree/master/x/authz/spec)
* Store block height in epochs module for debugging
* Allow zero-weight pool-incentive distribution records
* Fix bug in incentives epoch distribution events, used to use raw address, now uses bech32 addr
Expand Down
4 changes: 2 additions & 2 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

ante "github.com/cosmos/cosmos-sdk/x/auth/ante"

channelkeeper "github.com/cosmos/ibc-go/modules/core/04-channel/keeper"
ibcante "github.com/cosmos/ibc-go/modules/core/ante"
channelkeeper "github.com/cosmos/ibc-go/v2/modules/core/04-channel/keeper"
ibcante "github.com/cosmos/ibc-go/v2/modules/core/ante"
txfeeskeeper "github.com/osmosis-labs/osmosis/x/txfees/keeper"
txfeestypes "github.com/osmosis-labs/osmosis/x/txfees/types"
)
Expand Down
95 changes: 80 additions & 15 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"fmt"
"io"
"net/http"
"os"
Expand All @@ -14,9 +15,11 @@ import (
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

ibcclient "github.com/cosmos/ibc-go/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types"
ibcclient "github.com/cosmos/ibc-go/v2/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v2/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v2/modules/core/03-connection/types"

"github.com/cosmos/cosmos-sdk/x/authz"
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand All @@ -28,6 +31,7 @@ import (
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
store "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand All @@ -40,6 +44,8 @@ import (
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -75,14 +81,14 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
transfer "github.com/cosmos/ibc-go/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/modules/core/02-client/client"
porttypes "github.com/cosmos/ibc-go/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/modules/core/keeper"
transfer "github.com/cosmos/ibc-go/v2/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v2/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v2/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v2/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/v2/modules/core/02-client/client"
porttypes "github.com/cosmos/ibc-go/v2/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v2/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v2/modules/core/keeper"
"github.com/gorilla/mux"

appparams "github.com/osmosis-labs/osmosis/app/params"
Expand Down Expand Up @@ -115,6 +121,7 @@ import (
)

const appName = "OsmosisApp"
const v5UpgradeName = "v5"

var (
// DefaultNodeHome default home directories for the application daemon
Expand All @@ -139,6 +146,7 @@ var (
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
authzmodule.AppModuleBasic{},
ibc.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
Expand Down Expand Up @@ -210,6 +218,7 @@ type OsmosisApp struct {
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
ClaimKeeper *claimkeeper.Keeper
GAMMKeeper gammkeeper.Keeper
IncentivesKeeper incentiveskeeper.Keeper
Expand All @@ -227,6 +236,9 @@ type OsmosisApp struct {

// simulation manager
sm *module.SimulationManager

// module migration manager
configurator module.Configurator
}

func init() {
Expand Down Expand Up @@ -259,7 +271,7 @@ func NewOsmosisApp(
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
gammtypes.StoreKey, lockuptypes.StoreKey, claimtypes.StoreKey, incentivestypes.StoreKey,
epochstypes.StoreKey, poolincentivestypes.StoreKey, txfeestypes.StoreKey,
epochstypes.StoreKey, poolincentivestypes.StoreKey, authzkeeper.StoreKey, txfeestypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -297,7 +309,11 @@ func NewOsmosisApp(
app.GetSubspace(banktypes.ModuleName),
app.BlockedAddrs(),
)

app.AuthzKeeper = authzkeeper.NewKeeper(
keys[authzkeeper.StoreKey],
appCodec,
app.BaseApp.MsgServiceRouter(),
)
stakingKeeper := stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
)
Expand Down Expand Up @@ -340,18 +356,59 @@ func NewOsmosisApp(

// // configure upgrade for gamm module's pool creation fee param add
// app.GAMMKeeper.SetParams(ctx, gammtypes.NewParams(sdk.Coins{sdk.NewInt64Coin("uosmo", 1)})) // 1 uOSMO
// // execute prop12. See implementation in
// prop12(ctx, app)
return vm, nil
})

app.UpgradeKeeper.SetUpgradeHandler(
"v5", func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
v5UpgradeName,
func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
// Set IBC updates from {inside SDK} to v1
// https://github.com/cosmos/ibc-go/blob/main/docs/migrations/ibc-migration-043.md#in-place-store-migrations
app.IBCKeeper.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams())

totalLiquidity := app.GAMMKeeper.GetLegacyTotalLiquidity(ctx)
app.GAMMKeeper.DeleteLegacyTotalLiquidity(ctx)
app.GAMMKeeper.SetTotalLiquidity(ctx, totalLiquidity)
return vm, nil

// Set all modules "old versions" to 1.
// Then the run migrations logic will handle running their upgrade logics
fromVM := make(map[string]uint64)
for moduleName := range app.mm.Modules {
fromVM[moduleName] = 1
}
// override versions for authz module as to not skip InitGenesis
// for txfees module, we will override txfees ourselves.
delete(fromVM, authz.ModuleName)

newVM, err := app.mm.RunMigrations(ctx, app.configurator, fromVM)
if err != nil {
return nil, err
}

// Override txfees genesis here
txfees.InitGenesis(ctx, app.TxFeesKeeper, txfeestypes.GenesisState{
Basedenom: app.StakingKeeper.BondDenom(ctx),
Feetokens: []txfeestypes.FeeToken{},
})
return newVM, nil
})

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

if upgradeInfo.Name == v5UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := store.StoreUpgrades{
Added: []string{authz.ModuleName, txfees.ModuleName},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}

// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -498,6 +555,7 @@ func NewOsmosisApp(
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
transferModule,
Expand All @@ -523,6 +581,7 @@ func NewOsmosisApp(
app.mm.SetOrderEndBlockers(
lockuptypes.ModuleName,
crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName, claimtypes.ModuleName,
authz.ModuleName,
// Note: epochs' endblock should be "real" end of epochs, we keep epochs endblock at the end
epochstypes.ModuleName,
)
Expand All @@ -544,11 +603,13 @@ func NewOsmosisApp(
incentivestypes.ModuleName,
epochstypes.ModuleName,
lockuptypes.ModuleName,
authz.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
app.mm.RegisterServices(module.NewConfigurator(app.AppCodec(), app.MsgServiceRouter(), app.GRPCQueryRouter()))
app.configurator = module.NewConfigurator(app.AppCodec(), app.MsgServiceRouter(), app.GRPCQueryRouter())
app.mm.RegisterServices(app.configurator)

// create the simulation manager and define the order of the modules for deterministic simulations
//
Expand All @@ -558,6 +619,7 @@ func NewOsmosisApp(
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
gamm.NewAppModule(appCodec, app.GAMMKeeper, app.AccountKeeper, app.BankKeeper),
txfees.NewAppModule(appCodec, app.TxFeesKeeper),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
Expand Down Expand Up @@ -639,6 +701,9 @@ func (app *OsmosisApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) a
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}

app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())

return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ require (
github.com/cosmos/cosmos-sdk v0.44.3
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/iavl v0.17.2
github.com/cosmos/ibc-go v1.2.3
github.com/cosmos/ibc-go/v2 v2.0.0
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1
github.com/spf13/cast v1.3.1
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/iavl v0.17.2 h1:BT2u7DUvLLB+RYz9RItn/8n7Bt5xe5rj8QRTkk/PQU0=
github.com/cosmos/iavl v0.17.2/go.mod h1:prJoErZFABYZGDHka1R6Oay4z9PrNeFFiMKHDAMOi4w=
github.com/cosmos/ibc-go v1.2.3 h1:+Xdhshvls9c6NQNAj7jz5YUtpqCd7AwadEImpaeVReo=
github.com/cosmos/ibc-go v1.2.3/go.mod h1:TNJMo+fPU4GmpAGxqedjuA1l6izRLGPvuIRLpWAbXuE=
github.com/cosmos/ibc-go/v2 v2.0.0 h1:BMRg73JcdV9wGPI51j89ihm7VBZQsDLkqQ+tmzdeA9Y=
github.com/cosmos/ibc-go/v2 v2.0.0/go.mod h1:n53VhNSUxCtMLysvgyNhwrGHL8OW+318LMjtSmaVe9Q=
github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4=
github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY=
github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI=
Expand Down Expand Up @@ -747,8 +747,9 @@ github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI=
Expand Down
5 changes: 5 additions & 0 deletions x/txfees/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var (
_ module.AppModuleBasic = AppModuleBasic{}
)

const ModuleName = types.ModuleName

// ----------------------------------------------------------------------------
// AppModuleBasic
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -144,6 +146,9 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.Ra
var genState types.GenesisState
// Initialize global index to index in genesis state
cdc.MustUnmarshalJSON(gs, &genState)
if genState.Basedenom == "" {
panic("genState.Basedenom must be set for txfees")
}

InitGenesis(ctx, am.keeper, genState)

Expand Down

0 comments on commit f68d6ed

Please sign in to comment.