Skip to content

Commit

Permalink
Merge pull request #186 from CosmWasm/toggle_gov_types_175
Browse files Browse the repository at this point in the history
Define enabled wasm gov proposal types
  • Loading branch information
ethanfrey committed Jul 15, 2020
2 parents 9ab18fc + aff2214 commit 74e99b8
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 89 deletions.
12 changes: 6 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ type WasmWrapper struct {
}

// NewWasmApp returns a reference to an initialized WasmApp.
func NewWasmApp(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
invCheckPeriod uint, skipUpgradeHeights map[int64]bool, baseAppOptions ...func(*bam.BaseApp),
) *WasmApp {
func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
invCheckPeriod uint, enabledProposals []wasm.ProposalType, skipUpgradeHeights map[int64]bool,
baseAppOptions ...func(*bam.BaseApp)) *WasmApp {

cdc := MakeCodec()

Expand Down Expand Up @@ -252,8 +251,9 @@ func NewWasmApp(
supportedFeatures := "staking"
app.wasmKeeper = wasm.NewKeeper(app.cdc, keys[wasm.StoreKey], app.subspaces[wasm.ModuleName], app.accountKeeper, app.bankKeeper, app.stakingKeeper, wasmRouter, wasmDir, wasmConfig, supportedFeatures, nil, nil)

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

app.govKeeper = gov.NewKeeper(
Expand Down
6 changes: 3 additions & 3 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ import (

func TestWasmdExport(t *testing.T) {
db := db.NewMemDB()
gapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0, map[int64]bool{})
gapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0, wasm.EnableAllProposals, map[int64]bool{})
err := setGenesis(gapp)
require.NoError(t, err)

// Making a new app object with the db, so that initchain hasn't been called
newGapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0, map[int64]bool{})
newGapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0, wasm.EnableAllProposals, map[int64]bool{})
_, _, err = newGapp.ExportAppStateAndValidators(false, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}

// ensure that black listed addresses are properly set in bank keeper
func TestBlackListedAddrs(t *testing.T) {
db := db.NewMemDB()
gapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0, map[int64]bool{})
gapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0, wasm.EnableAllProposals, map[int64]bool{})

for acc := range maccPerms {
require.True(t, gapp.bankKeeper.BlacklistedAddr(gapp.supplyKeeper.GetModuleAddress(acc)))
Expand Down
5 changes: 3 additions & 2 deletions app/integration/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

wasmd "github.com/CosmWasm/wasmd/app"
"github.com/CosmWasm/wasmd/x/wasm"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
Expand All @@ -31,7 +32,7 @@ const (
// Setup initializes a new wasmd.WasmApp. A Nop logger is set in WasmApp.
func Setup(isCheckTx bool) *wasmd.WasmApp {
db := dbm.NewMemDB()
app := wasmd.NewWasmApp(log.NewNopLogger(), db, nil, true, 0, nil)
app := wasmd.NewWasmApp(log.NewNopLogger(), db, nil, true, 0, wasm.EnableAllProposals, nil)
// app := wasmd.NewWasmApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, 0)
if !isCheckTx {
// init chain must be called to stop deliverState from being nil
Expand All @@ -57,7 +58,7 @@ func Setup(isCheckTx bool) *wasmd.WasmApp {
// genesis accounts.
func SetupWithGenesisAccounts(genAccs []authexported.GenesisAccount) *wasmd.WasmApp {
db := dbm.NewMemDB()
app := wasmd.NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0, nil)
app := wasmd.NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0, wasm.EnableAllProposals, nil)
// app := wasmd.NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, 0)

// initialize the chain with the passed in genesis accounts
Expand Down
8 changes: 4 additions & 4 deletions app/sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"os"
"testing"

abci "github.com/tendermint/tendermint/abci/types"

"github.com/CosmWasm/wasmd/x/wasm"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/x/simulation"
abci "github.com/tendermint/tendermint/abci/types"
)

// Profile with:
Expand All @@ -27,7 +27,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {
}
}()

app := NewWasmApp(logger, db, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, interBlockCacheOpt())
app := NewWasmApp(logger, db, nil, true, simapp.FlagPeriodValue, wasm.EnableAllProposals, map[int64]bool{}, interBlockCacheOpt())

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
Expand Down Expand Up @@ -66,7 +66,7 @@ func BenchmarkInvariants(b *testing.B) {
}
}()

app := NewWasmApp(logger, db, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, interBlockCacheOpt())
app := NewWasmApp(logger, db, nil, true, simapp.FlagPeriodValue, wasm.EnableAllProposals, map[int64]bool{}, interBlockCacheOpt())

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
Expand Down
13 changes: 7 additions & 6 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"testing"

wasm2 "github.com/CosmWasm/wasmd/x/wasm"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
Expand Down Expand Up @@ -62,7 +63,7 @@ func TestFullAppSimulation(t *testing.T) {
require.NoError(t, os.RemoveAll(dir))
}()

app := NewWasmApp(logger, db, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, fauxMerkleModeOpt)
app := NewWasmApp(logger, db, nil, true, simapp.FlagPeriodValue, wasm2.EnableAllProposals, map[int64]bool{}, fauxMerkleModeOpt)
require.Equal(t, appName, app.Name())

// run randomized simulation
Expand Down Expand Up @@ -94,7 +95,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(dir))
}()

app := NewWasmApp(logger, db, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, fauxMerkleModeOpt)
app := NewWasmApp(logger, db, nil, true, simapp.FlagPeriodValue, wasm2.EnableAllProposals, map[int64]bool{}, fauxMerkleModeOpt)
require.Equal(t, appName, app.Name())

// Run randomized simulation
Expand Down Expand Up @@ -128,7 +129,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, fauxMerkleModeOpt)
newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, simapp.FlagPeriodValue, wasm2.EnableAllProposals, map[int64]bool{}, fauxMerkleModeOpt)
require.Equal(t, appName, newApp.Name())

var genesisState GenesisState
Expand Down Expand Up @@ -180,7 +181,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(dir))
}()

app := NewWasmApp(logger, db, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, fauxMerkleModeOpt)
app := NewWasmApp(logger, db, nil, true, simapp.FlagPeriodValue, wasm2.EnableAllProposals, map[int64]bool{}, fauxMerkleModeOpt)
require.Equal(t, appName, app.Name())

// Run randomized simulation
Expand Down Expand Up @@ -219,7 +220,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, fauxMerkleModeOpt)
newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, simapp.FlagPeriodValue, wasm2.EnableAllProposals, map[int64]bool{}, fauxMerkleModeOpt)
require.Equal(t, appName, newApp.Name())

newApp.InitChain(abci.RequestInitChain{
Expand Down Expand Up @@ -263,7 +264,7 @@ func TestAppStateDeterminism(t *testing.T) {

db := dbm.NewMemDB()

app := NewWasmApp(logger, db, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, interBlockCacheOpt())
app := NewWasmApp(logger, db, nil, true, simapp.FlagPeriodValue, wasm2.EnableAllProposals, map[int64]bool{}, interBlockCacheOpt())

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
Expand Down
29 changes: 13 additions & 16 deletions cmd/wasmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,8 @@ import (
"encoding/json"
"io"

"github.com/spf13/cobra"
"github.com/spf13/viper"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"

"github.com/CosmWasm/wasmd/app"

"github.com/CosmWasm/wasmd/x/wasm"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -24,6 +15,13 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/spf13/cobra"
"github.com/spf13/viper"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"
)

const flagInvCheckPeriod = "inv-check-period"
Expand Down Expand Up @@ -87,29 +85,28 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application
skipUpgradeHeights[int64(h)] = true
}

return app.NewWasmApp(
logger, db, traceStore, true, invCheckPeriod, skipUpgradeHeights,
return app.NewWasmApp(logger, db, traceStore, true, invCheckPeriod,
wasm.EnableAllProposals, skipUpgradeHeights,
baseapp.SetPruning(store.NewPruningOptionsFromString(viper.GetString("pruning"))),
baseapp.SetMinGasPrices(viper.GetString(server.FlagMinGasPrices)),
baseapp.SetHaltHeight(viper.GetUint64(server.FlagHaltHeight)),
baseapp.SetHaltTime(viper.GetUint64(server.FlagHaltTime)),
baseapp.SetInterBlockCache(cache),
)
baseapp.SetInterBlockCache(cache))
}

func exportAppStateAndTMValidators(
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string,
) (json.RawMessage, []tmtypes.GenesisValidator, error) {

if height != -1 {
gapp := app.NewWasmApp(logger, db, traceStore, false, uint(1), nil)
gapp := app.NewWasmApp(logger, db, traceStore, false, uint(1), wasm.EnableAllProposals, nil)
err := gapp.LoadHeight(height)
if err != nil {
return nil, nil, err
}
return gapp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
}

gapp := app.NewWasmApp(logger, db, traceStore, true, uint(1), nil)
gapp := app.NewWasmApp(logger, db, traceStore, true, uint(1), wasm.EnableAllProposals, nil)
return gapp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
}
19 changes: 8 additions & 11 deletions cmd/wasmd/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ import (
"path/filepath"
"time"

"github.com/CosmWasm/wasmd/app"
"github.com/CosmWasm/wasmd/x/wasm"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
cpm "github.com/otiai10/copy"
"github.com/spf13/cobra"

abci "github.com/tendermint/tendermint/abci/types"
tmos "github.com/tendermint/tendermint/libs/os"
"github.com/tendermint/tendermint/proxy"
tmsm "github.com/tendermint/tendermint/state"
tmstore "github.com/tendermint/tendermint/store"
tm "github.com/tendermint/tendermint/types"

"github.com/CosmWasm/wasmd/app"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func replayCmd() *cobra.Command {
Expand Down Expand Up @@ -94,9 +92,8 @@ func replayTxs(rootDir string) error {
fmt.Fprintln(os.Stderr, "Creating application")
gapp := app.NewWasmApp(
// TODO: do we want to set skipUpgradeHieghts here?
ctx.Logger, appDB, traceStoreWriter, true, uint(1), nil,
baseapp.SetPruning(store.PruneEverything), // nothing
)
ctx.Logger, appDB, traceStoreWriter, true, uint(1), wasm.EnableAllProposals, nil,
baseapp.SetPruning(store.PruneEverything))

// Genesis
var genDocPath = filepath.Join(configDir, "genesis.json")
Expand Down
3 changes: 2 additions & 1 deletion lcd_test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
dbm "github.com/tendermint/tm-db"

"github.com/CosmWasm/wasmd/app"
"github.com/CosmWasm/wasmd/x/wasm"
)

// TODO: Make InitializeTestLCD safe to call in multiple tests at the same time
Expand All @@ -73,7 +74,7 @@ func InitializeLCD(nValidators int, initAddrs []sdk.AccAddress, minting bool, po
logger = log.NewFilter(logger, log.AllowError())

db := dbm.NewMemDB()
gapp := app.NewWasmApp(logger, db, nil, true, 0, nil, baseapp.SetPruning(store.PruneNothing))
gapp := app.NewWasmApp(logger, db, nil, true, 0, wasm.EnableAllProposals, nil, baseapp.SetPruning(store.PruneNothing))
cdc = app.MakeCodec()

genDoc, valConsPubKeys, valOperAddrs, privVal, err := defaultGenesis(config, nValidators, initAddrs, minting)
Expand Down
36 changes: 19 additions & 17 deletions x/wasm/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,28 @@ var (
NewWasmProposalHandler = keeper.NewWasmProposalHandler

// variable aliases
ModuleCdc = types.ModuleCdc
DefaultCodespace = types.DefaultCodespace
ErrCreateFailed = types.ErrCreateFailed
ErrAccountExists = types.ErrAccountExists
ErrInstantiateFailed = types.ErrInstantiateFailed
ErrExecuteFailed = types.ErrExecuteFailed
ErrGasLimit = types.ErrGasLimit
ErrInvalidGenesis = types.ErrInvalidGenesis
ErrNotFound = types.ErrNotFound
ErrQueryFailed = types.ErrQueryFailed
ErrInvalidMsg = types.ErrInvalidMsg
KeyLastCodeID = types.KeyLastCodeID
KeyLastInstanceID = types.KeyLastInstanceID
CodeKeyPrefix = types.CodeKeyPrefix
ContractKeyPrefix = types.ContractKeyPrefix
ContractStorePrefix = types.ContractStorePrefix
DefaultEnabledProposals = types.DefaultEnabledProposals
ModuleCdc = types.ModuleCdc
DefaultCodespace = types.DefaultCodespace
ErrCreateFailed = types.ErrCreateFailed
ErrAccountExists = types.ErrAccountExists
ErrInstantiateFailed = types.ErrInstantiateFailed
ErrExecuteFailed = types.ErrExecuteFailed
ErrGasLimit = types.ErrGasLimit
ErrInvalidGenesis = types.ErrInvalidGenesis
ErrNotFound = types.ErrNotFound
ErrQueryFailed = types.ErrQueryFailed
ErrInvalidMsg = types.ErrInvalidMsg
KeyLastCodeID = types.KeyLastCodeID
KeyLastInstanceID = types.KeyLastInstanceID
CodeKeyPrefix = types.CodeKeyPrefix
ContractKeyPrefix = types.ContractKeyPrefix
ContractStorePrefix = types.ContractStorePrefix
EnableAllProposals = types.EnableAllProposals
DisableAllProposals = types.DisableAllProposals
)

type (
ProposalType = types.ProposalType
GenesisState = types.GenesisState
Code = types.Code
Contract = types.Contract
Expand Down
6 changes: 5 additions & 1 deletion x/wasm/internal/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ const ( // TODO: same as in handler
)

// NewWasmProposalHandler creates a new governance Handler for wasm proposals
func NewWasmProposalHandler(k Keeper, enabledTypes map[string]struct{}) govtypes.Handler {
func NewWasmProposalHandler(k Keeper, enabledProposalTypes []types.ProposalType) govtypes.Handler {
enabledTypes := make(map[string]struct{}, len(enabledProposalTypes))
for i := range enabledProposalTypes {
enabledTypes[string(enabledProposalTypes[i])] = struct{}{}
}
return func(ctx sdk.Context, content govtypes.Content) error {
if content == nil {
return sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "content must not be empty")
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/internal/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, tempDir string, supportedFeat
govRouter := gov.NewRouter().
AddRoute(params.RouterKey, params.NewParamChangeProposalHandler(paramsKeeper)).
AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
AddRoute(wasmtypes.RouterKey, NewWasmProposalHandler(keeper, wasmtypes.DefaultEnabledProposals))
AddRoute(wasmtypes.RouterKey, NewWasmProposalHandler(keeper, wasmtypes.EnableAllProposals))

govKeeper := gov.NewKeeper(
cdc, keyGov, paramsKeeper.Subspace(govtypes.DefaultParamspace).WithKeyTable(gov.ParamKeyTable()), supplyKeeper, stakingKeeper, govRouter,
Expand Down
Loading

0 comments on commit 74e99b8

Please sign in to comment.