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

Valset update #81

Merged
merged 28 commits into from
Nov 15, 2023
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
102 changes: 41 additions & 61 deletions demo/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,33 +137,8 @@ const appName = "MeshApp"
var (
NodeDir = ".meshd"
Bech32Prefix = "mesh"

// If EnabledSpecificProposals is "", and this is "true", then enable all x/wasm proposals.
// If EnabledSpecificProposals is "", and this is not "true", then disable all x/wasm proposals.
ProposalsEnabled = "false"
// If set to non-empty string it must be comma-separated list of values that are all a subset
// of "EnableAllProposals" (takes precedence over ProposalsEnabled)
// https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificProposals = ""
)

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
// produce a list of enabled proposals to pass into wasmd app.
func GetEnabledProposals() []wasm.ProposalType {
if EnableSpecificProposals == "" {
if ProposalsEnabled == "true" {
return wasm.EnableAllProposals
}
return wasm.DisableAllProposals
}
chunks := strings.Split(EnableSpecificProposals, ",")
proposals, err := wasm.ConvertToProposals(chunks)
if err != nil {
panic(err)
}
return proposals
}

// These constants are derived from the above variables.
// These are the ones we will want to use in the code, based on
// any overrides above
Expand Down Expand Up @@ -239,7 +214,7 @@ var (
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: nil,
icatypes.ModuleName: nil,
wasm.ModuleName: {authtypes.Burner},
wasmtypes.ModuleName: {authtypes.Burner},
meshsectypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}
)
Expand Down Expand Up @@ -286,7 +261,7 @@ type MeshApp struct {
ICAControllerKeeper icacontrollerkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
WasmKeeper wasm.Keeper
WasmKeeper wasmkeeper.Keeper
MeshSecKeeper *meshseckeeper.Keeper

ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand All @@ -312,9 +287,8 @@ func NewMeshApp(
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
enabledProposals []wasm.ProposalType,
appOpts servertypes.AppOptions,
wasmOpts []wasm.Option,
wasmOpts []wasmkeeper.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *MeshApp {
encodingConfig := MakeEncodingConfig()
Expand All @@ -337,13 +311,13 @@ func NewMeshApp(
authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey,
// non sdk store keys
ibcexported.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey,
wasm.StoreKey, icahosttypes.StoreKey,
wasmtypes.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey,
meshsectypes.StoreKey,
)

tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey, meshsectypes.MemStoreKey)

// load state streaming if enabled
if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, logger, keys); err != nil {
Expand Down Expand Up @@ -384,7 +358,7 @@ func NewMeshApp(
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName)
app.CapabilityKeeper.Seal()

// add keepers
Expand Down Expand Up @@ -430,11 +404,25 @@ func NewMeshApp(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// setup mesh-security keeper with vanilla Cosmos-SDK
// see also NewKeeperX constructor for integration with Osmosis SDK fork
// should be initialized before wasm keeper for custom query/msg handlers
app.MeshSecKeeper = meshseckeeper.NewKeeper(
app.appCodec,
keys[meshsectypes.StoreKey],
memKeys[meshsectypes.MemStoreKey],
app.BankKeeper,
app.StakingKeeper,
&app.WasmKeeper, // ensure this is a pointer as we instantiate the keeper a bit later
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec,
legacyAmino,
keys[slashingtypes.StoreKey],
app.StakingKeeper,
// decorate the sdk keeper to capture all jail/ unjail events for MS
meshseckeeper.NewStakingDecorator(app.StakingKeeper, app.MeshSecKeeper),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

Expand All @@ -453,7 +441,12 @@ func NewMeshApp(
// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
stakingtypes.NewMultiStakingHooks(
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
// register hook to capture valset updates
app.MeshSecKeeper.Hooks(),
),
)

app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper)
Expand Down Expand Up @@ -534,7 +527,8 @@ func NewMeshApp(
appCodec,
keys[evidencetypes.StoreKey],
app.StakingKeeper,
app.SlashingKeeper,
// decorate the SlashingKeeper to capture the tombstone event
meshseckeeper.CaptureTombstoneDecorator(app.MeshSecKeeper, app.SlashingKeeper, app.StakingKeeper),
)
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper
Expand Down Expand Up @@ -582,18 +576,6 @@ func NewMeshApp(
app.MsgServiceRouter(),
)

// setup mesh-security keeper with vanilla Cosmos-SDK
// see also NewKeeperX constructor for integration with Osmosis SDK fork
// should be initialized before wasm keeper for custom query/msg handlers
app.MeshSecKeeper = meshseckeeper.NewKeeper(
app.appCodec,
keys[meshsectypes.StoreKey],
app.BankKeeper,
app.StakingKeeper,
&app.WasmKeeper, // ensure this is a pointer as we instantiate the keeper a bit later
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
Expand All @@ -602,21 +584,23 @@ func NewMeshApp(

meshMessageHandler := wasmkeeper.WithMessageHandlerDecorator(func(nested wasmkeeper.Messenger) wasmkeeper.Messenger {
return wasmkeeper.NewMessageHandlerChain(
// security layer for system integrity, should always be first in chain
meshseckeeper.NewIntegrityHandler(app.MeshSecKeeper),
nested,
// append our custom message handler
// append our custom message handler for mesh-security
meshseckeeper.NewDefaultCustomMsgHandler(app.MeshSecKeeper),
)
})
wasmOpts = append(wasmOpts, meshMessageHandler,
// add support for the mesh-security queries
wasmkeeper.WithQueryHandlerDecorator(meshseckeeper.NewQueryDecorator(app.MeshSecKeeper, app.SlashingKeeper)),
)
// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
availableCapabilities := strings.Join(AllCapabilities(), ",")
app.WasmKeeper = wasm.NewKeeper(
app.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
keys[wasm.StoreKey],
keys[wasmtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
Expand All @@ -635,10 +619,6 @@ func NewMeshApp(
wasmOpts...,
)

// The gov proposal types can be individually enabled
if len(enabledProposals) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, enabledProposals))
}
// Set legacy router for backwards compatibility with gov v1beta1
app.GovKeeper.SetLegacyRouter(govRouter)

Expand Down Expand Up @@ -671,7 +651,7 @@ func NewMeshApp(
// Create static IBC router, add app routes, then set and seal it
ibcRouter := porttypes.NewRouter().
AddRoute(ibctransfertypes.ModuleName, transferStack).
AddRoute(wasm.ModuleName, wasmStack).
AddRoute(wasmtypes.ModuleName, wasmStack).
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack)
app.IBCKeeper.SetRouter(ibcRouter)
Expand Down Expand Up @@ -733,7 +713,7 @@ func NewMeshApp(
ibcexported.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
wasm.ModuleName,
wasmtypes.ModuleName,
meshsectypes.ModuleName,
)

Expand All @@ -749,8 +729,8 @@ func NewMeshApp(
ibcexported.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
wasm.ModuleName,
meshsectypes.ModuleName,
wasmtypes.ModuleName,
meshsectypes.ModuleName, // last to capture all chain events
)

// NOTE: The genutils module must occur after staking so that pools are
Expand All @@ -773,7 +753,7 @@ func NewMeshApp(
icatypes.ModuleName,
ibcfeetypes.ModuleName,
// wasm after ibc transfer
wasm.ModuleName,
wasmtypes.ModuleName,
meshsectypes.ModuleName,
}
app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...)
Expand Down Expand Up @@ -821,7 +801,7 @@ func NewMeshApp(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)
app.setAnteHandler(encodingConfig.TxConfig, wasmConfig, keys[wasm.StoreKey])
app.setAnteHandler(encodingConfig.TxConfig, wasmConfig, keys[wasmtypes.StoreKey])

// must be before Loading version
// requires the snapshot store to be created and registered as a BaseAppOption
Expand Down Expand Up @@ -1088,7 +1068,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(wasm.ModuleName)
paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(meshsectypes.ModuleName)

return paramsKeeper
Expand Down
34 changes: 1 addition & 33 deletions demo/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
Expand All @@ -26,7 +25,7 @@ func TestMeshdExport(t *testing.T) {
gapp.Commit()

// Making a new app object with the db, so that initchain hasn't been called
newGapp := NewMeshApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, wasm.EnableAllProposals, simtestutil.NewAppOptionsWithFlagHome(t.TempDir()), emptyWasmOpts)
newGapp := NewMeshApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir()), emptyWasmOpts)
_, err := newGapp.ExportAppStateAndValidators(false, []string{}, nil)
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}
Expand All @@ -52,34 +51,3 @@ func TestGetMaccPerms(t *testing.T) {
dup := GetMaccPerms()
require.Equal(t, maccPerms, dup, "duplicated module account permissions differed from actual module account permissions")
}

func TestGetEnabledProposals(t *testing.T) {
cases := map[string]struct {
proposalsEnabled string
specificEnabled string
expected []wasm.ProposalType
}{
"all disabled": {
proposalsEnabled: "false",
expected: wasm.DisableAllProposals,
},
"all enabled": {
proposalsEnabled: "true",
expected: wasm.EnableAllProposals,
},
"some enabled": {
proposalsEnabled: "okay",
specificEnabled: "StoreCode,InstantiateContract",
expected: []wasm.ProposalType{wasm.ProposalTypeStoreCode, wasm.ProposalTypeInstantiateContract},
},
}

for name, tc := range cases {
t.Run(name, func(t *testing.T) {
ProposalsEnabled = tc.proposalsEnabled
EnableSpecificProposals = tc.specificEnabled
proposals := GetEnabledProposals()
assert.Equal(t, tc.expected, proposals)
})
}
}
9 changes: 4 additions & 5 deletions demo/app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"
"testing"

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -131,7 +130,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewMeshApp(log.NewNopLogger(), newDB, nil, true, wasm.EnableAllProposals, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
newApp := NewMeshApp(log.NewNopLogger(), newDB, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "MeshApp", newApp.Name())

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

newApp := NewMeshApp(log.NewNopLogger(), newDB, nil, true, wasm.EnableAllProposals, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
newApp := NewMeshApp(log.NewNopLogger(), newDB, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "MeshApp", newApp.Name())

newApp.InitChain(abci.RequestInitChain{
Expand Down Expand Up @@ -275,7 +274,7 @@ func setupSimulationApp(t *testing.T, msg string) (simtypes.Config, dbm.DB, simt
appOptions[flags.FlagHome] = dir // ensure a unique folder
appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue

app := NewMeshApp(logger, db, nil, true, wasm.EnableAllProposals, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
app := NewMeshApp(logger, db, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "MeshApp", app.Name())
return config, db, appOptions, app
}
Expand Down Expand Up @@ -314,7 +313,7 @@ func TestAppStateDeterminism(t *testing.T) {
}

db := dbm.NewMemDB()
app := NewMeshApp(logger, db, nil, true, wasm.EnableAllProposals, appOptions, emptyWasmOpts, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID))
app := NewMeshApp(logger, db, nil, true, appOptions, emptyWasmOpts, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID))

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
Expand Down
Loading
Loading