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

Add wasmd module #769

Merged
merged 17 commits into from
Feb 3, 2022
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
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
arch: [amd64, arm64]
arch: [amd64]
targetos: [darwin, linux]
include:
- targetos: windows
arch: amd64
# include:
# - targetos: windows
# arch: amd64
name: osmosis ${{ matrix.arch }} for ${{ matrix.targetos }}
steps:
- uses: actions/checkout@v2
Expand Down
59 changes: 54 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ import (
txfeeskeeper "github.com/osmosis-labs/osmosis/x/txfees/keeper"
txfeestypes "github.com/osmosis-labs/osmosis/x/txfees/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"

// Modules related to bech32-ibc, which allows new ibc funcationality based on the bech32 prefix of addresses
"github.com/osmosis-labs/bech32-ibc/x/bech32ibc"
bech32ibckeeper "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/keeper"
Expand All @@ -195,6 +198,36 @@ import (

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.
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 = ""

// use this for clarity in argument list
EmptyWasmOpts []wasm.Option
)

// GetWasmEnabledProposals parses the WasmProposalsEnabled / EnableSpecificWasmProposals values to
// produce a list of enabled proposals to pass into wasmd app.
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
Expand All @@ -211,9 +244,11 @@ var (
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
paramsclient.ProposalHandler, distrclient.ProposalHandler, upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
poolincentivesclient.UpdatePoolIncentivesHandler,
ibcclientclient.UpdateClientProposalHandler, ibcclientclient.UpgradeProposalHandler,
append(
wasmclient.ProposalHandlers,
paramsclient.ProposalHandler, distrclient.ProposalHandler, upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
poolincentivesclient.UpdatePoolIncentivesHandler,
ibcclientclient.UpdateClientProposalHandler, ibcclientclient.UpgradeProposalHandler)...,
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand All @@ -233,6 +268,7 @@ var (
claim.AppModuleBasic{},
superfluid.AppModuleBasic{},
bech32ibc.AppModuleBasic{},
wasm.AppModuleBasic{},
)

// module account permissions
Expand All @@ -252,6 +288,7 @@ var (
poolincentivestypes.ModuleName: nil,
superfluidtypes.ModuleName: nil,
txfeestypes.ModuleName: nil,
wasm.ModuleName: {authtypes.Burner},
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -288,6 +325,7 @@ type OsmosisApp struct {
// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper

// "Normal" keepers
AccountKeeper *authkeeper.AccountKeeper
Expand All @@ -311,6 +349,7 @@ type OsmosisApp struct {
TxFeesKeeper *txfeeskeeper.Keeper
SuperfluidKeeper superfluidkeeper.Keeper
GovKeeper *govkeeper.Keeper
WasmKeeper *wasm.Keeper

transferModule transfer.AppModule
// the module manager
Expand All @@ -335,7 +374,9 @@ func init() {
// NewOsmosis returns a reference to an initialized Osmosis.
func NewOsmosisApp(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp),
homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig, appOpts servertypes.AppOptions,
wasmEnabledProposals []wasm.ProposalType, wasmOpts []wasm.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *OsmosisApp {

appCodec := encodingConfig.Marshaler
Expand Down Expand Up @@ -373,6 +414,7 @@ func NewOsmosisApp(
txfeestypes.StoreKey,
superfluidtypes.StoreKey,
bech32ibctypes.StoreKey,
wasm.StoreKey,
)
// Define transient store keys
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand All @@ -393,7 +435,7 @@ func NewOsmosisApp(

app.InitSpecialKeepers(skipUpgradeHeights, homePath, invCheckPeriod)
app.setupUpgradeStoreLoaders()
app.InitNormalKeepers()
app.InitNormalKeepers(homePath, appOpts, wasmEnabledProposals, wasmOpts)
app.SetupHooks()
app.setupUpgradeHandlers()

Expand Down Expand Up @@ -428,6 +470,7 @@ func NewOsmosisApp(
distr.NewAppModule(appCodec, *app.DistrKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper),
staking.NewAppModule(appCodec, *app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
upgrade.NewAppModule(*app.UpgradeKeeper),
wasm.NewAppModule(appCodec, app.WasmKeeper, app.StakingKeeper),
evidence.NewAppModule(*app.EvidenceKeeper),
authzmodule.NewAppModule(appCodec, *app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
ibc.NewAppModule(app.IBCKeeper),
Expand Down Expand Up @@ -474,6 +517,7 @@ func NewOsmosisApp(
paramstypes.ModuleName, vestingtypes.ModuleName,
gammtypes.ModuleName, incentivestypes.ModuleName, lockuptypes.ModuleName, claimtypes.ModuleName,
poolincentivestypes.ModuleName, superfluidtypes.ModuleName, bech32ibctypes.ModuleName, txfeestypes.ModuleName,
wasm.ModuleName,
)

// Tell the app's module manager how to set the order of EndBlockers, which are run at the end of every block.
Expand All @@ -489,6 +533,7 @@ func NewOsmosisApp(
poolincentivestypes.ModuleName, superfluidtypes.ModuleName, bech32ibctypes.ModuleName, txfeestypes.ModuleName,
// Note: epochs' endblock should be "real" end of epochs, we keep epochs endblock at the end
epochstypes.ModuleName,
wasm.ModuleName,
)

// NOTE: The genutils moodule must occur after staking so that pools are
Expand Down Expand Up @@ -523,6 +568,8 @@ func NewOsmosisApp(
epochstypes.ModuleName,
lockuptypes.ModuleName,
authz.ModuleName,
// wasm after ibc transfer
wasm.ModuleName,
)

app.mm.RegisterInvariants(app.CrisisKeeper)
Expand All @@ -548,6 +595,7 @@ func NewOsmosisApp(
staking.NewAppModule(appCodec, *app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
params.NewAppModule(*app.ParamsKeeper),
evidence.NewAppModule(*app.EvidenceKeeper),
wasm.NewAppModule(appCodec, app.WasmKeeper, app.StakingKeeper),
ibc.NewAppModule(app.IBCKeeper),
incentives.NewAppModule(appCodec, *app.IncentivesKeeper, app.AccountKeeper, app.BankKeeper, app.EpochsKeeper),
lockup.NewAppModule(appCodec, *app.LockupKeeper, app.AccountKeeper, app.BankKeeper),
Expand Down Expand Up @@ -842,6 +890,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(poolincentivestypes.ModuleName)
paramsKeeper.Subspace(superfluidtypes.ModuleName)
paramsKeeper.Subspace(gammtypes.ModuleName)
paramsKeeper.Subspace(wasm.ModuleName)
Copy link

Choose a reason for hiding this comment

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

@ethanfrey
The pinned contracts are not loaded within the if loadLatest block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very good catch. Thank you


return paramsKeeper
}
2 changes: 2 additions & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func NewAppConstructor(encodingCfg params.EncodingConfig) network.AppConstructor
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
encodingCfg,
simapp.EmptyAppOptions{},
GetWasmEnabledProposals(),
EmptyWasmOpts,
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
)
}
Expand Down
21 changes: 20 additions & 1 deletion app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package app

import (
"encoding/json"
"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

// The genesis state of the blockchain is represented here as a map of raw json
Expand All @@ -13,8 +15,25 @@ import (
// object provided to it during init.
type GenesisState map[string]json.RawMessage

const (
// DefaultMaxWasmCodeSize limit max bytes read to prevent gzip bombs
// 600 KB is copied from x/wasm, but you can customize here as desired
DefaultMaxWasmCodeSize = 600 * 1024 * 2
)

// NewDefaultGenesisState generates the default state for the application.
func NewDefaultGenesisState() GenesisState {
encCfg := MakeEncodingConfig()
return ModuleBasics.DefaultGenesis(encCfg.Marshaler)
gen := ModuleBasics.DefaultGenesis(encCfg.Marshaler)

// here we override wasm config to make it permissioned by default
wasmGen := wasm.GenesisState{
Params: wasmtypes.Params{
CodeUploadAccess: wasmtypes.AllowNobody,
InstantiateDefaultPermission: wasmtypes.AccessTypeEverybody,
MaxWasmCodeSize: DefaultMaxWasmCodeSize,
},
Comment on lines +29 to +35
Copy link
Member

Choose a reason for hiding this comment

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

Oh cool! So when we do the upgrade to cosmwasm, do we need to override these in InitGenesis as well?

Heres what we had to do for x/txfees in our v5 upgrade: https://github.com/osmosis-labs/osmosis/blob/main/app/upgrades/v5/upgrades.go#L60-L66

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we will need a migration step, that will set the params explicitly.
I wanted to do that on another PR. I could copy your migration setup, but would be happier to add a few lines to an existing one (if you could set up the framework for v6 upgrade)

}
gen[wasm.ModuleName] = encCfg.Marshaler.MustMarshalJSON(&wasmGen)
return gen
}
55 changes: 53 additions & 2 deletions app/keepers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package app

import (
"fmt"
"path/filepath"

"github.com/CosmWasm/wasmd/x/wasm"
"github.com/cosmos/cosmos-sdk/baseapp"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
Expand Down Expand Up @@ -85,6 +90,7 @@ func (app *OsmosisApp) InitSpecialKeepers(
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
app.ScopedIBCKeeper = app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
app.ScopedTransferKeeper = app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
app.ScopedWasmKeeper = app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
app.CapabilityKeeper.Seal()

// TODO: Make a SetInvCheckPeriod fn on CrisisKeeper.
Expand All @@ -104,7 +110,13 @@ func (app *OsmosisApp) InitSpecialKeepers(
app.UpgradeKeeper = &upgradeKeeper
}

func (app *OsmosisApp) InitNormalKeepers() {
// Note: I put x/wasm here as I need to write it up to these other ones
func (app *OsmosisApp) InitNormalKeepers(
homePath string,
appOpts servertypes.AppOptions,
wasmEnabledProposals []wasm.ProposalType,
wasmOpts []wasm.Option,
) {
appCodec := app.appCodec
bApp := app.BaseApp
keys := app.keys
Expand Down Expand Up @@ -176,7 +188,7 @@ func (app *OsmosisApp) InitNormalKeepers() {
// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, app.transferModule)
app.IBCKeeper.SetRouter(ibcRouter)
// Note: the sealing is done after creating wasmd and wiring that up

app.Bech32IBCKeeper = bech32ibckeeper.NewKeeper(
app.IBCKeeper.ChannelKeeper, appCodec, keys[bech32ibctypes.StoreKey],
Expand Down Expand Up @@ -257,6 +269,40 @@ func (app *OsmosisApp) InitNormalKeepers() {
)
app.TxFeesKeeper = &txFeesKeeper

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error while reading wasm config: %s", err))
}

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
supportedFeatures := "iterator,staking,stargate"
wasmKeeper := wasm.NewKeeper(
appCodec,
keys[wasm.StoreKey],
app.GetSubspace(wasm.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.DistrKeeper,
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.ScopedWasmKeeper,
app.TransferKeeper,
app.MsgServiceRouter(),
app.GRPCQueryRouter(),
wasmDir,
wasmConfig,
supportedFeatures,
wasmOpts...,
)
app.WasmKeeper = &wasmKeeper

// wire up x/wasm to IBC
ibcRouter.AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper))
app.IBCKeeper.SetRouter(ibcRouter)

// register the proposal types
// TODO: This appears to be missing tx fees proposal type
govRouter := govtypes.NewRouter()
Expand All @@ -270,6 +316,11 @@ func (app *OsmosisApp) InitNormalKeepers() {
AddRoute(bech32ibctypes.RouterKey, bech32ibc.NewBech32IBCProposalHandler(*app.Bech32IBCKeeper)).
AddRoute(txfeestypes.RouterKey, txfees.NewUpdateFeeTokenProposalHandler(*app.TxFeesKeeper))

// The gov proposal types can be individually enabled
if len(wasmEnabledProposals) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, wasmEnabledProposals))
}

govKeeper := govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey],
app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
Expand Down
4 changes: 2 additions & 2 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// Setup initializes a new OsmosisApp
func Setup(isCheckTx bool) *OsmosisApp {
db := dbm.NewMemDB()
app := NewOsmosisApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig(), simapp.EmptyAppOptions{})
app := NewOsmosisApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig(), simapp.EmptyAppOptions{}, GetWasmEnabledProposals(), EmptyWasmOpts)
if !isCheckTx {
genesisState := NewDefaultGenesisState()
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
Expand Down Expand Up @@ -42,7 +42,7 @@ func SetupTestingAppWithLevelDb(isCheckTx bool) (app *OsmosisApp, cleanupFn func
if err != nil {
panic(err)
}
app = NewOsmosisApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig(), simapp.EmptyAppOptions{})
app = NewOsmosisApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig(), simapp.EmptyAppOptions{}, GetWasmEnabledProposals(), EmptyWasmOpts)
if !isCheckTx {
genesisState := NewDefaultGenesisState()
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
Expand Down
6 changes: 6 additions & 0 deletions app/wasmtest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Wasm Tests

This contains a few high level test that `x/wasm` is properly integrated.

Since the code tested is not in this repo, and we are just testing the application
integration (app.go), I figured this is the most suitable location for it
Loading