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

chore: app package housekeeping #1125

Merged
merged 9 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
13 changes: 7 additions & 6 deletions app/ante.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package app

import (
wasm "github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
ante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

channelkeeper "github.com/cosmos/ibc-go/v2/modules/core/04-channel/keeper"
ibcante "github.com/cosmos/ibc-go/v2/modules/core/ante"

wasm "github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"

txfeeskeeper "github.com/osmosis-labs/osmosis/v7/x/txfees/keeper"
txfeestypes "github.com/osmosis-labs/osmosis/v7/x/txfees/types"
)
Expand All @@ -23,14 +21,17 @@ func NewAnteHandler(
appOpts servertypes.AppOptions,
wasmConfig wasm.Config,
txCounterStoreKey sdk.StoreKey,
ak ante.AccountKeeper, bankKeeper authtypes.BankKeeper,
txFeesKeeper *txfeeskeeper.Keeper, spotPriceCalculator txfeestypes.SpotPriceCalculator,
ak ante.AccountKeeper,
bankKeeper authtypes.BankKeeper,
txFeesKeeper *txfeeskeeper.Keeper,
spotPriceCalculator txfeestypes.SpotPriceCalculator,
sigGasConsumer ante.SignatureVerificationGasConsumer,
signModeHandler signing.SignModeHandler,
channelKeeper channelkeeper.Keeper,
) sdk.AnteHandler {
mempoolFeeOptions := txfeestypes.NewMempoolFeeOptions(appOpts)
mempoolFeeDecorator := txfeeskeeper.NewMempoolFeeDecorator(*txFeesKeeper, mempoolFeeOptions)

return sdk.ChainAnteDecorators(
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
wasmkeeper.NewLimitSimulationGasDecorator(wasmConfig.SimulationGasLimit),
Expand Down
183 changes: 81 additions & 102 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
package app

import (
// Imports from the Go Standard Library
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"

// HTTP Router
"github.com/gorilla/mux"

// Used to serve OpenAPI information
"github.com/rakyll/statik/fs"

// A CLI helper
"github.com/spf13/cast"

// Imports from Tendermint, Osmosis' consensus protocol
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"

// Utilities from the Cosmos-SDK other than Cosmos modules
"github.com/CosmWasm/wasmd/x/wasm"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand All @@ -41,127 +23,110 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"

// Cosmos-SDK Modules
// https://github.com/cosmos/cosmos-sdk/tree/master/x
// NB: Osmosis uses a fork of the cosmos-sdk which can be found at: https://github.com/osmosis-labs/cosmos-sdk

// Auth: Authentication of accounts and transactions for Cosmos SDK applications.
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"

// Capability: allows developers to atomically define what a module can and cannot do
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"

// Crisis: Halting the blockchain under certain circumstances (e.g. if an invariant is broken).
"github.com/cosmos/cosmos-sdk/x/crisis"

// Evidence handling for double signing, misbehaviour, etc.

// Params: Parameters that are always available
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"

// Upgrade: Software upgrades handling and coordination.
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

// IBC Transfer: Defines the "transfer" IBC port
transfer "github.com/cosmos/ibc-go/v2/modules/apps/transfer"
"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"

// Osmosis application prarmeters
Copy link
Member

Choose a reason for hiding this comment

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

Do you think we should revert these comments / the prior ordering of imports here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean keep them?

Import blocks aren't meant to be annotated. If you think devs would really find them useful, I can revert :)

Copy link
Member

Choose a reason for hiding this comment

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

@faddat was the one who added them, presumably he's found it helpful when explaining app.go's to people.

We could put the same comments in the AppKeepers struct though, I don't think theres anything particularly important about this info being in the imports

Copy link
Contributor Author

@alexanderbez alexanderbez Mar 23, 2022

Choose a reason for hiding this comment

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

Gotcha, yeah I mean I guess I can see how they're helpful, but then a few questions/points arise:

  • Do I now too have to keep these up to date and add them for any new imports (burden on me)
  • Import blocks become extremely verbose

@faddat are you against removing these annotations?

appparams "github.com/osmosis-labs/osmosis/v7/app/params"

// Upgrades from earlier versions of Osmosis
v4 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v4"
v5 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v5"
v7 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v7"
_ "github.com/osmosis-labs/osmosis/v7/client/docs/statik"

// Superfluid: Allows users to stake gamm (bonded liquidity)
superfluidtypes "github.com/osmosis-labs/osmosis/v7/x/superfluid/types"

// Wasm: Allows Osmosis to interact with web assembly smart contracts
"github.com/CosmWasm/wasmd/x/wasm"
)

const appName = "OsmosisApp"

var (
// If EnableSpecificWasmProposals is "", and this is "true", then enable all x/wasm proposals.
// If EnableSpecificWasmProposals is "", and this is not "true", then disable all x/wasm proposals.
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration
// and genesis verification.
ModuleBasics = module.NewBasicManager(appModuleBasics...)

// module account permissions
maccPerms = moduleAccountPermissions

// module accounts that are allowed to receive tokens
allowedReceivingModAcc = map[string]bool{}

// WasmProposalsEnabled enables all x/wasm proposals when it's value is "true"
// and EnableSpecificWasmProposals is empty. Otherwise, all x/wasm proposals
// are disabled.
WasmProposalsEnabled = "true"
// If set to non-empty string it must be comma-separated list of values that are all a subset
// of "EnableAllProposals" (takes precedence over WasmProposalsEnabled)
// https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34

// EnableSpecificWasmProposals, if set, must be comma-separated list of values
// that are all a subset of "EnableAllProposals", which takes precedence over
// WasmProposalsEnabled.
//
// See: https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificWasmProposals = ""

// use this for clarity in argument list
// EmptyWasmOpts defines a type alias for a list of wasm options.
EmptyWasmOpts []wasm.Option

_ App = (*OsmosisApp)(nil)
)

// GetWasmEnabledProposals parses the WasmProposalsEnabled / EnableSpecificWasmProposals values to
// produce a list of enabled proposals to pass into wasmd app.
// GetWasmEnabledProposals parses the WasmProposalsEnabled and
// EnableSpecificWasmProposals values to produce a list of enabled proposals to
// pass into the application.
func GetWasmEnabledProposals() []wasm.ProposalType {
if EnableSpecificWasmProposals == "" {
if WasmProposalsEnabled == "true" {
return wasm.EnableAllProposals
}

return wasm.DisableAllProposals
}

chunks := strings.Split(EnableSpecificWasmProposals, ",")

proposals, err := wasm.ConvertToProposals(chunks)
if err != nil {
panic(err)
}

return proposals
}

var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration
// and genesis verification.
ModuleBasics = module.NewBasicManager(appModuleBasics...)

// module account permissions
maccPerms = moduleAaccountPermissions

// module accounts that are allowed to receive tokens
allowedReceivingModAcc = map[string]bool{}
)

var _ App = (*OsmosisApp)(nil)

// Osmosis extends an ABCI application, but with most of its parameters exported.
// OsmosisApp extends an ABCI application, but with most of its parameters exported.
// They are exported for convenience in creating helper functions, as object
// capabilities aren't needed for testing.
type OsmosisApp struct {
*baseapp.BaseApp

appKeepers

cdc *codec.LegacyAmino
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry

invCheckPeriod uint
invCheckPeriod uint

// keys to access the substores
keys map[string]*sdk.KVStoreKey
tkeys map[string]*sdk.TransientStoreKey
memKeys map[string]*sdk.MemoryStoreKey

transferModule transfer.AppModule
// the module manager
mm *module.Manager

// simulation manager
sm *module.SimulationManager

// module migration manager
configurator module.Configurator
mm *module.Manager
sm *module.SimulationManager
configurator module.Configurator
}

func init() {
Expand Down Expand Up @@ -325,29 +290,27 @@ func NewOsmosisApp(
return app
}

// 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
// MakeCodecs returns the application codec and a legacy Amino codec.
func MakeCodecs() (codec.Codec, *codec.LegacyAmino) {
config := MakeEncodingConfig()
return config.Marshaler, config.Amino
}

// Name returns the name of the App
// Name returns the name of the App.
func (app *OsmosisApp) Name() string { return app.BaseApp.Name() }

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

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

// InitChainer application update at chain initialization
// InitChainer application update at chain initialization.
func (app *OsmosisApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState GenesisState
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
Expand Down Expand Up @@ -414,7 +377,7 @@ func (app *OsmosisApp) GetSubspace(moduleName string) paramstypes.Subspace {
return subspace
}

// SimulationManager implements the SimulationApp interface
// SimulationManager implements the SimulationApp interface.
func (app *OsmosisApp) SimulationManager() *module.SimulationManager {
return app.sm
}
Expand Down Expand Up @@ -446,7 +409,8 @@ func (app *OsmosisApp) RegisterTxService(clientCtx client.Context) {
authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
}

// RegisterTendermintService implements the Application.RegisterTendermintService method.
// RegisterTendermintService implements the Application.RegisterTendermintService
// method.
func (app *OsmosisApp) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry)
}
Expand All @@ -472,30 +436,44 @@ func (app *OsmosisApp) setupUpgradeHandlers() {
// this configures a no-op upgrade handler for the v4 upgrade,
// which improves the lockup module's store management.
app.UpgradeKeeper.SetUpgradeHandler(
v4.UpgradeName, v4.CreateUpgradeHandler(
app.mm, app.configurator,
*app.BankKeeper, app.DistrKeeper, app.GAMMKeeper))
v4.UpgradeName,
v4.CreateUpgradeHandler(
app.mm,
app.configurator,
*app.BankKeeper,
app.DistrKeeper,
app.GAMMKeeper,
),
)

app.UpgradeKeeper.SetUpgradeHandler(
v5.UpgradeName,
v5.CreateUpgradeHandler(
app.mm, app.configurator,
&app.IBCKeeper.ConnectionKeeper, app.TxFeesKeeper,
app.GAMMKeeper, app.StakingKeeper))
app.mm,
app.configurator,
&app.IBCKeeper.ConnectionKeeper,
app.TxFeesKeeper,
app.GAMMKeeper,
app.StakingKeeper,
),
)

app.UpgradeKeeper.SetUpgradeHandler(
v7.UpgradeName,
v7.CreateUpgradeHandler(
app.mm, app.configurator,
app.mm,
app.configurator,
app.WasmKeeper,
app.SuperfluidKeeper,
app.EpochsKeeper,
app.LockupKeeper,
app.MintKeeper,
app.AccountKeeper))
app.AccountKeeper,
),
)
}

// RegisterSwaggerAPI registers swagger route with API Server
// RegisterSwaggerAPI registers swagger route with API Server.
func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) {
statikFS, err := fs.New()
if err != nil {
Expand All @@ -507,11 +485,12 @@ func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) {
rtr.PathPrefix("/swagger/").Handler(staticServer)
}

// GetMaccPerms returns a copy of the module account permissions
// GetMaccPerms returns a copy of the module account permissions.
func GetMaccPerms() map[string][]string {
dupMaccPerms := make(map[string][]string)
for k, v := range maccPerms {
dupMaccPerms[k] = v
}

return dupMaccPerms
}
3 changes: 3 additions & 0 deletions app/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"

v3 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v3"
v6 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v6"
)
Expand All @@ -11,8 +12,10 @@ func BeginBlockForks(ctx sdk.Context, app *OsmosisApp) {
switch ctx.BlockHeight() {
case v3.UpgradeHeight:
v3.RunForkLogic(ctx, app.GovKeeper, app.StakingKeeper)

case v6.UpgradeHeight:
v6.RunForkLogic(ctx)

default:
// do nothing
return
Expand Down
Loading