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

feat: cosmos-sdk v0.50.x #175

Merged
merged 22 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
11 changes: 6 additions & 5 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ package app

import (
errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
globalfeeante "github.com/OmniFlix/omniflixhub/v5/x/globalfee/ante"
globalfeekeeper "github.com/OmniFlix/omniflixhub/v5/x/globalfee/keeper"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
)

// Lower back to 1 mil after https://github.com/cosmos/relayer/issues/1255
Expand All @@ -27,7 +28,7 @@ type HandlerOptions struct {

GovKeeper govkeeper.Keeper
IBCKeeper *ibckeeper.Keeper
TxCounterStoreKey storetypes.StoreKey
TxCounterStoreKey *storetypes.KVStoreKey
WasmConfig wasmtypes.WasmConfig
Codec codec.BinaryCodec

Expand Down Expand Up @@ -56,7 +57,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // Outermost AnteDecorator, SetUpContext must be called first
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit),
wasmkeeper.NewCountTXDecorator(options.TxCounterStoreKey),
wasmkeeper.NewCountTXDecorator(runtime.NewKVStoreService(options.TxCounterStoreKey)),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
Expand Down
121 changes: 80 additions & 41 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import (

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"cosmossdk.io/log"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/OmniFlix/omniflixhub/v5/app/openapiconsole"
appparams "github.com/OmniFlix/omniflixhub/v5/app/params"
"github.com/OmniFlix/omniflixhub/v5/docs"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
Expand All @@ -39,25 +39,25 @@ 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/crisis"
"github.com/cosmos/cosmos-sdk/x/gov"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
"github.com/spf13/cast"

ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/OmniFlix/omniflixhub/v5/app/keepers"
"github.com/OmniFlix/omniflixhub/v5/app/upgrades"
v012 "github.com/OmniFlix/omniflixhub/v5/app/upgrades/v012"
v2 "github.com/OmniFlix/omniflixhub/v5/app/upgrades/v2"
v2_1 "github.com/OmniFlix/omniflixhub/v5/app/upgrades/v2.1"
v3 "github.com/OmniFlix/omniflixhub/v5/app/upgrades/v3"
v4 "github.com/OmniFlix/omniflixhub/v5/app/upgrades/v4"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
v5 "github.com/OmniFlix/omniflixhub/v5/app/upgrades/v5"
)

const Name = "omniflixhub"
Expand All @@ -76,28 +76,19 @@ var (

func getGovProposalHandlers() []govclient.ProposalHandler {
var govProposalHandlers []govclient.ProposalHandler
govProposalHandlers = append(govProposalHandlers,
paramsclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
)
govProposalHandlers = append(govProposalHandlers, paramsclient.ProposalHandler)

return govProposalHandlers
}

var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string
Upgrades = []upgrades.Upgrade{v012.Upgrade, v2.Upgrade, v2_1.Upgrade, v3.Upgrade, v4.Upgrade}
Upgrades = []upgrades.Upgrade{v012.Upgrade, v2.Upgrade, v2_1.Upgrade, v3.Upgrade, v4.Upgrade, v5.Upgrade}
Forks []upgrades.Fork
)

var (
_ runtime.AppI = (*OmniFlixApp)(nil)
_ servertypes.Application = (*OmniFlixApp)(nil)
)
var _ runtime.AppI = (*OmniFlixApp)(nil)

// OmniFlixApp extends an ABCI application, but with most of its parameters exported.
// They are exported for convenience in creating helper functions, as object
Expand All @@ -112,6 +103,7 @@ type OmniFlixApp struct {
invCheckPeriod uint

mm *module.Manager
ModuleBasics module.BasicManager
sm *module.SimulationManager
configurator module.Configurator
}
Expand Down Expand Up @@ -143,13 +135,15 @@ func NewOmniFlixApp(
appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
txConfig := encodingConfig.TxConfig

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

app := &OmniFlixApp{
AppKeepers: keepers.AppKeepers{},
BaseApp: bApp,
cdc: cdc,
appCodec: appCodec,
Expand Down Expand Up @@ -186,6 +180,8 @@ func NewOmniFlixApp(

app.mm = module.NewManager(appModules(app, encodingConfig, skipGenesisInvariants)...)

// part of sdk v0.50.x migration
app.mm.SetOrderPreBlockers(upgradetypes.ModuleName)
// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so to keep the
// CanWithdrawInvariant invariant.
Expand All @@ -203,18 +199,29 @@ func NewOmniFlixApp(

app.mm.RegisterInvariants(app.CrisisKeeper)
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.mm.RegisterServices(app.configurator)
err := app.mm.RegisterServices(app.configurator)
if err != nil {
panic(err)
}
// Migration check
app.ModuleBasics = module.NewBasicManagerFromManager(
app.mm,
map[string]module.AppModuleBasic{
"gov": gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
}),
},
)

app.setupUpgradeHandlers()
app.setupUpgradeStoreLoaders()

// simulations
app.sm = module.NewSimulationManager(simulationModules(app, encodingConfig, skipGenesisInvariants)...)

app.sm.RegisterStoreDecoders()

// initialize stores
app.MountKVStores(app.GetKVStoreKey())
app.MountTransientStores(app.GetTransientStoreKey())
app.MountMemoryStores(app.GetMemoryStoreKey())

// SDK v47 - since we do not use dep inject, this gives us access to newer gRPC services.
autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.mm.Modules))

Expand All @@ -229,6 +236,11 @@ func NewOmniFlixApp(
panic("error while reading wasm config: " + err.Error())
}

// initialize stores
app.MountKVStores(app.GetKVStoreKey())
app.MountTransientStores(app.GetTransientStoreKey())
app.MountMemoryStores(app.GetMemoryStoreKey())

anteHandler, err := NewAnteHandler(
HandlerOptions{
HandlerOptions: ante.HandlerOptions{
Expand All @@ -255,12 +267,12 @@ func NewOmniFlixApp(

// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetPreBlocker(app.PreBlocker)
app.SetBeginBlocker(app.BeginBlocker)
app.SetAnteHandler(anteHandler)
app.SetEndBlocker(app.EndBlocker)

app.setupUpgradeHandlers()
app.setupUpgradeStoreLoaders()
app.SetPrecommiter(app.PreCommitter)
app.SetPrepareCheckStater(app.PrepareCheckStater)

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
Expand All @@ -274,29 +286,52 @@ func NewOmniFlixApp(
// Name returns the name of the App
func (app *OmniFlixApp) Name() string { return app.BaseApp.Name() }

// PreBlocker application updates before begin of the block
func (app *OmniFlixApp) PreBlocker(ctx sdk.Context, _ *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
return app.mm.PreBlock(ctx)
}

// BeginBlocker application updates every begin block
func (app *OmniFlixApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
func (app *OmniFlixApp) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error) {
BeginBlockForks(ctx, app)
return app.mm.BeginBlock(ctx, req)
return app.mm.BeginBlock(ctx)
}

// EndBlocker application updates every end block
func (app *OmniFlixApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return app.mm.EndBlock(ctx, req)
func (app *OmniFlixApp) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) {
return app.mm.EndBlock(ctx)
}

// InitChainer application update at chain initialization
func (app *OmniFlixApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
func (app *OmniFlixApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
var genesisState GenesisState
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}

app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
if err != nil {
panic(err)
}

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

// PreCommitter application updates before the commit of a block after all transactions have been delivered.
func (app *OmniFlixApp) PreCommitter(ctx sdk.Context) {
mm := app.ModuleManager()
if err := mm.Precommit(ctx); err != nil {
panic(err)
}
}

func (app *OmniFlixApp) PrepareCheckStater(ctx sdk.Context) {
mm := app.ModuleManager()
if err := mm.PrepareCheckState(ctx); err != nil {
panic(err)
}
}

// LoadHeight loads a particular height
func (app *OmniFlixApp) LoadHeight(height int64) error {
return app.LoadVersion(height)
Expand Down Expand Up @@ -354,7 +389,7 @@ func (app *OmniFlixApp) RegisterAPIRoutes(apiSvr *api.Server, _ config.APIConfig
// Register new tx routes from grpc-gateway.
authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// Register new tendermint queries routes from grpc-gateway.
tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
cmtservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register legacy and grpc-gateway routes for all modules.
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
Expand All @@ -372,22 +407,26 @@ func (app *OmniFlixApp) RegisterTxService(clientCtx client.Context) {
authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
}

func (app *OmniFlixApp) ModuleManager() module.Manager {
return *app.mm
}

func (app *OmniFlixApp) SimulationManager() *module.SimulationManager {
return app.sm
}

// RegisterTendermintService implements the Application.RegisterTendermintService method.
func (app *OmniFlixApp) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(
cmtservice.RegisterTendermintService(
clientCtx,
app.BaseApp.GRPCQueryRouter(),
app.interfaceRegistry,
app.Query,
)
}

func (app *OmniFlixApp) RegisterNodeService(clientCtx client.Context) {
nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter())
func (app *OmniFlixApp) RegisterNodeService(clientCtx client.Context, cfg config.Config) {
nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), cfg)
}

func (app *OmniFlixApp) setupUpgradeHandlers() {
Expand Down
Loading
Loading