Skip to content

Commit

Permalink
Cosmos SDK 0.44.* series upgrade for Osmosis (osmosis-labs#538)
Browse files Browse the repository at this point in the history
Co-authored-by: ValarDragon <[email protected]>
  • Loading branch information
faddat and ValarDragon authored Nov 21, 2021
1 parent f70c7a7 commit dedcfb8
Show file tree
Hide file tree
Showing 84 changed files with 1,340 additions and 891 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/sim.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Simulation
# Simulation workflow runs simulation test
# This workflow is run on pushes to master & every Pull Requests where a .go, .mod, .sum have been changed
on:
pull_request:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.17
- name: Display go version
run: go version
- name: Run simulation
run: go test ./simapp
5 changes: 4 additions & 1 deletion .github/workflows/statesync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: State Sync
# or API.
on: [workflow_dispatch]

# This workflow tests state sync against the Notional archive server.
# This workflow tests state sync against the Notional archive server.
# To decentralize this workflow, add additional nodes to scripts/statesync.sh

jobs:
Expand All @@ -15,6 +15,9 @@ jobs:
name: osmosis state sync
steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: '^1.17'

- name: state sync
run: bash scripts/statesync.sh
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ jobs:
run: go test -mod=readonly -timeout 30m -coverprofile=coverage.txt -tags='norace' -covermode=atomic `go list ./... | grep -v simapp`
- name: Codecov
uses: codecov/[email protected]
- name: Run simulation
run: go test ./simapp
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* Upgraded Osmosis to Cosmos-sdk 0.44.2
* 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
7 changes: 3 additions & 4 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/cosmos-sdk/x/ibc/core/04-channel/keeper"
ibcante "github.com/cosmos/cosmos-sdk/x/ibc/core/ante"
channelkeeper "github.com/cosmos/ibc-go/modules/core/04-channel/keeper"
ibcante "github.com/cosmos/ibc-go/modules/core/ante"
txfeeskeeper "github.com/osmosis-labs/osmosis/x/txfees/keeper"
txfeestypes "github.com/osmosis-labs/osmosis/x/txfees/types"
)
Expand All @@ -35,10 +35,9 @@ func NewAnteHandler(
ante.TxTimeoutHeightDecorator{},
ante.NewValidateMemoDecorator(ak),
ante.NewConsumeGasForTxSizeDecorator(ak),
ante.NewRejectFeeGranterDecorator(),
ante.NewDeductFeeDecorator(ak, bankKeeper, nil),
ante.NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(ak),
ante.NewDeductFeeDecorator(ak, bankKeeper),
ante.NewSigGasConsumeDecorator(ak, sigGasConsumer),
ante.NewSigVerificationDecorator(ak, signModeHandler),
ante.NewIncrementSequenceDecorator(ak),
Expand Down
126 changes: 68 additions & 58 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import (
"os"
"path/filepath"

"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"

abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client"
ibcclient "github.com/cosmos/ibc-go/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types"

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

"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -62,13 +61,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
transfer "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer"
ibctransferkeeper "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/keeper"
ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types"
ibc "github.com/cosmos/cosmos-sdk/x/ibc/core"
porttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/05-port/types"
ibchost "github.com/cosmos/cosmos-sdk/x/ibc/core/24-host"
ibckeeper "github.com/cosmos/cosmos-sdk/x/ibc/core/keeper"
"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"
Expand All @@ -83,6 +75,15 @@ 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"
"github.com/gorilla/mux"

appparams "github.com/osmosis-labs/osmosis/app/params"
_ "github.com/osmosis-labs/osmosis/client/docs/statik"
Expand Down Expand Up @@ -133,6 +134,7 @@ var (
gov.NewAppModuleBasic(
paramsclient.ProposalHandler, distrclient.ProposalHandler, upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
poolincentivesclient.UpdatePoolIncentivesHandler,
ibcclientclient.UpdateClientProposalHandler, ibcclientclient.UpgradeProposalHandler,
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand Down Expand Up @@ -183,7 +185,7 @@ var _ App = (*OsmosisApp)(nil)
type OsmosisApp struct {
*baseapp.BaseApp
cdc *codec.LegacyAmino
appCodec codec.Marshaler
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry

invCheckPeriod uint
Expand Down Expand Up @@ -248,7 +250,7 @@ func NewOsmosisApp(

bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetAppVersion(version.Version)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)

keys := sdk.NewKVStoreKeys(
Expand Down Expand Up @@ -282,14 +284,20 @@ func NewOsmosisApp(
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
app.CapabilityKeeper.Seal()

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms,
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.BlockedAddrs(),
appCodec,
keys[banktypes.StoreKey],
app.AccountKeeper,
app.GetSubspace(banktypes.ModuleName),
app.BlockedAddrs(),
)

stakingKeeper := stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
)
Expand All @@ -304,43 +312,54 @@ func NewOsmosisApp(
app.CrisisKeeper = crisiskeeper.NewKeeper(
app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName,
)
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath)
app.UpgradeKeeper = upgradekeeper.NewKeeper(
skipUpgradeHeights,
keys[upgradetypes.StoreKey],
appCodec,
homePath,
app.BaseApp,
)

// this configures a no-op upgrade handler for the v2 upgrade,
// this configures a no-op upgrade handler for the v4 upgrade,
// which improves the lockup module's store management.
app.UpgradeKeeper.SetUpgradeHandler(
"v4", func(ctx sdk.Context, plan upgradetypes.Plan) {
// Upgrade all of the lock storages
locks, err := app.LockupKeeper.GetLegacyPeriodLocks(ctx)
if err != nil {
panic(err)
}
// clear all lockup module locking / unlocking queue items
app.LockupKeeper.ClearAllLockRefKeys(ctx)
app.LockupKeeper.ClearAllAccumulationStores(ctx)

// reset all lock and references
if err := app.LockupKeeper.ResetAllLocks(ctx, locks); err != nil {
panic(err)
}

// 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

prop12(ctx, app)

"v4", func(ctx sdk.Context, _plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
// // Upgrade all of the lock storages
// locks, err := app.LockupKeeper.GetLegacyPeriodLocks(ctx)
// if err != nil {
// panic(err)
// }
// // clear all lockup module locking / unlocking queue items
// app.LockupKeeper.ClearAllLockRefKeys(ctx)
// app.LockupKeeper.ClearAllAccumulationStores(ctx)

// // reset all lock and references
// if err := app.LockupKeeper.ResetAllLocks(ctx, locks); err != nil {
// panic(err)
// }

// // 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
// prop12(ctx, app)
return vm, nil
})

app.UpgradeKeeper.SetUpgradeHandler("v5", func(ctx sdk.Context, plan upgradetypes.Plan) {
totalLiquidity := app.GAMMKeeper.GetLegacyTotalLiquidity(ctx)
app.GAMMKeeper.DeleteLegacyTotalLiquidity(ctx)
app.GAMMKeeper.SetTotalLiquidity(ctx, totalLiquidity)
})
app.UpgradeKeeper.SetUpgradeHandler(
"v5", func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
totalLiquidity := app.GAMMKeeper.GetLegacyTotalLiquidity(ctx)
app.GAMMKeeper.DeleteLegacyTotalLiquidity(ctx)
app.GAMMKeeper.SetTotalLiquidity(ctx, totalLiquidity)
return vm, nil
})

// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), &stakingKeeper, scopedIBCKeeper,
)
appCodec,
keys[ibchost.StoreKey],
app.GetSubspace(ibchost.ModuleName),
app.StakingKeeper,
app.UpgradeKeeper,
scopedIBCKeeper)

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
Expand Down Expand Up @@ -397,8 +416,9 @@ func NewOsmosisApp(
govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibchost.RouterKey, ibcclient.NewClientUpdateProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(poolincentivestypes.RouterKey, poolincentives.NewPoolIncentivesProposalHandler(app.PoolIncentivesKeeper))

govKeeper := govkeeper.NewKeeper(
Expand Down Expand Up @@ -528,7 +548,7 @@ func NewOsmosisApp(

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

// create the simulation manager and define the order of the modules for deterministic simulations
//
Expand Down Expand Up @@ -583,16 +603,6 @@ func NewOsmosisApp(
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
}

// Initialize and seal the capability keeper so all persistent capabilities
// are loaded in-memory and prevent any further modules from creating scoped
// sub-keepers.
// This must be done during creation of baseapp rather than in InitChain so
// that in-memory capabilities get regenerated on app restart.
// Note that since this reads from the store, we can only perform it when
// `loadLatest` is set to true.
ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})
app.CapabilityKeeper.InitializeAndSeal(ctx)
}

app.ScopedIBCKeeper = scopedIBCKeeper
Expand All @@ -604,7 +614,7 @@ func NewOsmosisApp(
// MakeCodecs constructs the *std.Codec and *codec.LegacyAmino instances used by
// simapp. It is useful for tests and clients who do not want to construct the
// full simapp
func MakeCodecs() (codec.Marshaler, *codec.LegacyAmino) {
func MakeCodecs() (codec.Codec, *codec.LegacyAmino) {
config := MakeEncodingConfig()
return config.Marshaler, config.Amino
}
Expand Down Expand Up @@ -670,7 +680,7 @@ func (app *OsmosisApp) LegacyAmino() *codec.LegacyAmino {
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *OsmosisApp) AppCodec() codec.Marshaler {
func (app *OsmosisApp) AppCodec() codec.Codec {
return app.appCodec
}

Expand Down Expand Up @@ -767,7 +777,7 @@ func GetMaccPerms() map[string][]string {
}

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper {
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

paramsKeeper.Subspace(authtypes.ModuleName)
Expand Down
47 changes: 26 additions & 21 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/osmosis-labs/osmosis/app/params"
dbm "github.com/tendermint/tm-db"

servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand All @@ -28,26 +29,30 @@ func DefaultConfig() network.Config {
LegacyAmino: encCfg.Amino,
InterfaceRegistry: encCfg.InterfaceRegistry,
AccountRetriever: authtypes.AccountRetriever{},
AppConstructor: func(val network.Validator) servertypes.Application {
return NewOsmosisApp(
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
encCfg,
simapp.EmptyAppOptions{},
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
)
},
GenesisState: ModuleBasics.DefaultGenesis(encCfg.Marshaler),
TimeoutCommit: 2 * time.Second,
ChainID: "osmosis-1",
NumValidators: 1,
BondDenom: sdk.DefaultBondDenom,
MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom),
AccountTokens: sdk.TokensFromConsensusPower(1000),
StakingTokens: sdk.TokensFromConsensusPower(500),
BondedTokens: sdk.TokensFromConsensusPower(100),
PruningStrategy: storetypes.PruningOptionNothing,
CleanupDir: true,
SigningAlgo: string(hd.Secp256k1Type),
KeyringOptions: []keyring.Option{},
AppConstructor: NewAppConstructor(encCfg),
GenesisState: ModuleBasics.DefaultGenesis(encCfg.Marshaler),
TimeoutCommit: 1 * time.Second,
ChainID: "osmosis-code-test",
NumValidators: 1,
BondDenom: sdk.DefaultBondDenom,
MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom),
AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction),
StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction),
BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction),
PruningStrategy: storetypes.PruningOptionNothing,
CleanupDir: true,
SigningAlgo: string(hd.Secp256k1Type),
KeyringOptions: []keyring.Option{},
}
}

func NewAppConstructor(encodingCfg params.EncodingConfig) network.AppConstructor {
return func(val network.Validator) servertypes.Application {
return NewOsmosisApp(
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
encodingCfg,
simapp.EmptyAppOptions{},
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
)
}
}
2 changes: 1 addition & 1 deletion app/params/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Marshaler codec.Marshaler
Marshaler codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
Loading

0 comments on commit dedcfb8

Please sign in to comment.