Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade cosmos sdk to latest release. #1343

Merged
merged 9 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 82 additions & 46 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ 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"
ibc "github.com/cosmos/cosmos-sdk/x/ibc/core"
porttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/05-port/types"
"github.com/cosmos/cosmos-sdk/x/mint"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/upgrade"
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"
ibc "github.com/cosmos/ibc-go/modules/core"
porttypes "github.com/cosmos/ibc-go/modules/core/05-port/types"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
Expand All @@ -63,13 +63,11 @@ import (
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/ovrclk/akash/app/migrations"
"github.com/ovrclk/akash/x/audit"
"github.com/ovrclk/akash/x/cert"
escrowkeeper "github.com/ovrclk/akash/x/escrow/keeper"

"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

abci "github.com/tendermint/tendermint/abci/types"
Expand All @@ -81,14 +79,14 @@ import (
distr "github.com/cosmos/cosmos-sdk/x/distribution"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
ibctransferkeeper "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/keeper"
ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types"
ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client"
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/slashing"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
ibctransferkeeper "github.com/cosmos/ibc-go/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types"
ibcclient "github.com/cosmos/ibc-go/modules/core/02-client"
ibchost "github.com/cosmos/ibc-go/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/modules/core/keeper"

dkeeper "github.com/ovrclk/akash/x/deployment/keeper"
mkeeper "github.com/ovrclk/akash/x/market/keeper"
Expand All @@ -114,7 +112,7 @@ var (
type AkashApp struct {
*bam.BaseApp
cdc *codec.LegacyAmino
appCodec codec.Marshaler
appCodec codec.Codec
interfaceRegistry codectypes.InterfaceRegistry

invCheckPeriod uint
Expand Down Expand Up @@ -156,6 +154,9 @@ type AkashApp struct {

// simulation manager
sm *module.SimulationManager

// module configurator
configurator module.Configurator
}

// https://github.com/cosmos/sdk-tutorials/blob/c6754a1e313eb1ed973c5c91dcc606f2fd288811/app.go#L73
Expand All @@ -174,7 +175,7 @@ func NewApp(

bapp := bam.NewBaseApp(AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), options...)
bapp.SetCommitMultiStoreTracer(tio)
bapp.SetAppVersion(version.Version)
bapp.SetVersion(version.Version)
bapp.SetInterfaceRegistry(interfaceRegistry)

keys := kvStoreKeys()
Expand All @@ -191,6 +192,7 @@ func NewApp(
tkeys: tkeys,
memkeys: memkeys,
}
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())

app.keeper.params = initParamsKeeper(appCodec, cdc, app.keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])

Expand All @@ -201,6 +203,9 @@ func NewApp(
app.keeper.cap = capabilitykeeper.NewKeeper(appCodec, app.keys[capabilitytypes.StoreKey], app.memkeys[capabilitytypes.MemStoreKey])
scopedIBCKeeper := app.keeper.cap.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.keeper.cap.ScopeToModule(ibctransfertypes.ModuleName)
// seal the capability keeper so all persistent capabilities are loaded in-memory and prevent
// any further modules from creating scoped sub-keepers.
app.keeper.cap.Seal()

app.keeper.acct = authkeeper.NewAccountKeeper(
appCodec,
Expand Down Expand Up @@ -261,14 +266,8 @@ func NewApp(
authtypes.FeeCollectorName,
)

app.keeper.upgrade = upgradekeeper.NewKeeper(skipUpgradeHeights, app.keys[upgradetypes.StoreKey], appCodec, homePath)

app.keeper.upgrade.SetUpgradeHandler("akashnet-2-upgrade-1", func(ctx sdk.Context, plan upgradetypes.Plan) {
migrations.MigrateAkashnet2Upgrade1(ctx, app.keeper.acct, app.keeper.bank, app.keeper.staking)

// Set staking HistoricalEntries to 10000, required positive value for ibc
app.GetSubspace(stakingtypes.ModuleName).Set(ctx, stakingtypes.KeyHistoricalEntries, uint32(10000))
})
app.keeper.upgrade = upgradekeeper.NewKeeper(skipUpgradeHeights, app.keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp)
app.registerUpgradeHandlers()

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
Expand All @@ -281,7 +280,8 @@ func NewApp(

// register IBC Keeper
app.keeper.ibc = ibckeeper.NewKeeper(
appCodec, app.keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.keeper.staking, scopedIBCKeeper,
appCodec, app.keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName),
app.keeper.staking, app.keeper.upgrade, scopedIBCKeeper,
)

// register the proposal types
Expand All @@ -290,7 +290,7 @@ func NewApp(
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.keeper.params)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.keeper.distr)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.keeper.upgrade)).
AddRoute(ibchost.RouterKey, ibcclient.NewClientUpdateProposalHandler(app.keeper.ibc.ClientKeeper))
AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.keeper.ibc.ClientKeeper))

app.keeper.gov = govkeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -350,9 +350,15 @@ func NewApp(
}, app.akashAppModules()...)...,
)

// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
// CanWithdrawInvariant invariant.
// NOTE: staking module is required if HistoricalEntries param > 0
// NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you find this information somewhere in the Cosmos docs or just figure it out from reading the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took it from cosmos sdk code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put a link to that in the source code? Someone else may want to look at that as well.

app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,
upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName,
distrtypes.ModuleName, slashingtypes.ModuleName, evidencetypes.ModuleName,
stakingtypes.ModuleName, ibchost.ModuleName,
)
app.mm.SetOrderEndBlockers(
append([]string{
Expand Down Expand Up @@ -386,7 +392,7 @@ func NewApp(

app.mm.RegisterInvariants(&app.keeper.crisis)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
app.mm.RegisterServices(module.NewConfigurator(app.MsgServiceRouter(), app.GRPCQueryRouter()))
app.mm.RegisterServices(app.configurator)

// add test gRPC service for testing gRPC queries in isolation
testdata.RegisterQueryServer(app.GRPCQueryRouter(), testdata.QueryImpl{})
Expand Down Expand Up @@ -421,31 +427,23 @@ func NewApp(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)

app.SetAnteHandler(
ante.NewAnteHandler(
app.keeper.acct,
app.keeper.bank,
ante.DefaultSigVerificationGasConsumer,
encodingConfig.TxConfig.SignModeHandler(),
),
)
handler, err := ante.NewAnteHandler(ante.HandlerOptions{
AccountKeeper: app.keeper.acct,
BankKeeper: app.keeper.bank,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
})
if err != nil {
panic(err)
}
app.SetAnteHandler(handler)

app.SetEndBlocker(app.EndBlocker)

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit("app initialization:" + 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.keeper.cap.InitializeAndSeal(ctx)
}

app.keeper.scopedIBC = scopedIBCKeeper
Expand All @@ -454,10 +452,46 @@ func NewApp(
return app
}

func (app *AkashApp) registerUpgradeHandlers() {
app.keeper.upgrade.SetUpgradeHandler("akash_v0.13.0_cosmos_v0.43.0", func(ctx sdk.Context,
plan upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {
// 1st-time running in-store migrations, using 1 as fromVersion to
// avoid running InitGenesis.
fromVM := map[string]uint64{
"auth": 1,
"bank": 1,
"capability": 1,
"crisis": 1,
"distribution": 1,
"evidence": 1,
"gov": 1,
"mint": 1,
"params": 1,
"slashing": 1,
"staking": 1,
"upgrade": 1,
"vesting": 1,
"ibc": 1,
"genutil": 1,
"transfer": 1,

// akash modules
"audit": 1,
"cert": 1,
"deployment": 1,
"escrow": 1,
"market": 1,
"provider": 1,
}

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})
}

// 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 All @@ -471,6 +505,7 @@ func (app *AkashApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abc
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
app.keeper.upgrade.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
}

Expand All @@ -492,7 +527,7 @@ func (app *AkashApp) LegacyAmino() *codec.LegacyAmino {
}

// AppCodec returns AkashApp's app codec.
func (app *AkashApp) AppCodec() codec.Marshaler {
func (app *AkashApp) AppCodec() codec.Codec {
return app.appCodec
}

Expand Down Expand Up @@ -588,7 +623,8 @@ func (app *AkashApp) LoadHeight(height int64) error {
}

// 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
8 changes: 4 additions & 4 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/gov"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
transfer "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer"
ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types"
ibc "github.com/cosmos/cosmos-sdk/x/ibc/core"
ibchost "github.com/cosmos/cosmos-sdk/x/ibc/core/24-host"
"github.com/cosmos/cosmos-sdk/x/mint"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params"
Expand All @@ -37,6 +33,10 @@ import (
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
transfer "github.com/cosmos/ibc-go/modules/apps/transfer"
ibctransfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/modules/core"
ibchost "github.com/cosmos/ibc-go/modules/core/24-host"
appparams "github.com/ovrclk/akash/app/params"
)

Expand Down
2 changes: 1 addition & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (app *AkashApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs
counter := int16(0)

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
validator, found := app.keeper.staking.GetValidator(ctx, addr)
if !found {
panic("expected validator, not found")
Expand Down
2 changes: 1 addition & 1 deletion app/mac.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibctransfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types"
escrowtypes "github.com/ovrclk/akash/x/escrow/types"
)

Expand Down
Loading