Skip to content

Commit

Permalink
revert: revert wasmd implementation as it is being worked in #133
Browse files Browse the repository at this point in the history
  • Loading branch information
queencre committed Dec 20, 2022
1 parent b7c94f5 commit 9ebf864
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 185 deletions.
9 changes: 1 addition & 8 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@ import (

ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
ante.HandlerOptions

IBCKeeper *ibckeeper.Keeper
WasmConfig *wasmtypes.WasmConfig
TXCounterStoreKey sdk.StoreKey
IBCKeeper *ibckeeper.Keeper
}

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
Expand All @@ -40,8 +35,6 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(),
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early
wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey),
ante.NewRejectExtensionOptionsDecorator(),
ante.NewMempoolFeeDecorator(),
ante.NewValidateBasicDecorator(),
Expand Down
110 changes: 1 addition & 109 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http"
"os"
"path/filepath"
"strings"

"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
Expand Down Expand Up @@ -82,7 +81,6 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"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"

// IBC modules
Expand Down Expand Up @@ -141,45 +139,10 @@ import (
mintkeeper "github.com/crescent-network/crescent/v3/x/mint/keeper"
minttypes "github.com/crescent-network/crescent/v3/x/mint/types"

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

// unnamed import of statik for swagger UI support
_ "github.com/crescent-network/crescent/v3/client/docs/statik"
)

var (
// 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"

// 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
EnableSpecificProposals = ""
)

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

var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string
Expand Down Expand Up @@ -225,7 +188,6 @@ var (
marketmaker.AppModuleBasic{},
lpfarm.AppModuleBasic{},
ica.AppModuleBasic{},
wasm.AppModuleBasic{},
)

// module account permissions
Expand All @@ -246,7 +208,6 @@ var (
marketmakertypes.ModuleName: nil,
lpfarmtypes.ModuleName: nil,
icatypes.ModuleName: nil,
wasm.ModuleName: {authtypes.Burner},
}
)

Expand Down Expand Up @@ -299,13 +260,11 @@ type App struct {
MarketMakerKeeper marketmakerkeeper.Keeper
LPFarmKeeper lpfarmkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
WasmKeeper wasm.Keeper

// scoped keepers
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper

// IBC app modules
transferModule transfer.AppModule
Expand Down Expand Up @@ -341,8 +300,6 @@ func NewApp(
invCheckPeriod uint,
encodingConfig farmingparams.EncodingConfig,
appOpts servertypes.AppOptions,
wasmEnabledProposals []wasm.ProposalType,
wasmOpts []wasm.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
appCodec := encodingConfig.Marshaler
Expand Down Expand Up @@ -379,7 +336,6 @@ func NewApp(
marketmakertypes.StoreKey,
lpfarmtypes.StoreKey,
icahosttypes.StoreKey,
wasm.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -411,7 +367,6 @@ func NewApp(
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
app.CapabilityKeeper.Seal()

// add keepers
Expand Down Expand Up @@ -570,11 +525,6 @@ func NewApp(
AddRoute(marketmakertypes.RouterKey, marketmaker.NewMarketMakerProposalHandler(app.MarketMakerKeeper)).
AddRoute(lpfarmtypes.RouterKey, lpfarm.NewFarmingPlanProposalHandler(app.LPFarmKeeper))

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

app.GovKeeper = govkeeper.NewKeeper(
appCodec,
keys[govtypes.StoreKey],
Expand Down Expand Up @@ -634,40 +584,10 @@ func NewApp(
)
app.EvidenceKeeper = *evidenceKeeper

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
availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1"
app.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,
scopedWasmKeeper,
app.TransferKeeper,
app.MsgServiceRouter(),
app.GRPCQueryRouter(),
wasmDir,
wasmConfig,
availableCapabilities,
wasmOpts...,
)

// create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()

ibcRouter.
AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper)).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule)
app.IBCKeeper.SetRouter(ibcRouter)
Expand Down Expand Up @@ -710,7 +630,6 @@ func NewApp(
lpfarm.NewAppModule(appCodec, app.LPFarmKeeper, app.AccountKeeper, app.BankKeeper, app.LiquidityKeeper),
app.transferModule,
app.icaModule,
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -747,7 +666,6 @@ func NewApp(
claimtypes.ModuleName,
marketmakertypes.ModuleName,
icatypes.ModuleName,
wasm.ModuleName,
)
app.mm.SetOrderEndBlockers(
// EndBlocker of crisis module called AssertInvariants
Expand Down Expand Up @@ -780,7 +698,6 @@ func NewApp(
marketmakertypes.ModuleName,
lpfarmtypes.ModuleName,
icatypes.ModuleName,
wasm.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -817,7 +734,6 @@ func NewApp(
upgradetypes.ModuleName,
vestingtypes.ModuleName,
icatypes.ModuleName,
wasm.ModuleName,

// InitGenesis of crisis module called AssertInvariants
crisistypes.ModuleName,
Expand Down Expand Up @@ -855,8 +771,6 @@ func NewApp(
liquidfarming.NewAppModule(appCodec, app.LiquidFarmingKeeper, app.AccountKeeper, app.BankKeeper),
marketmaker.NewAppModule(appCodec, app.MarketMakerKeeper, app.AccountKeeper, app.BankKeeper),
lpfarm.NewAppModule(appCodec, app.LPFarmKeeper, app.AccountKeeper, app.BankKeeper, app.LiquidityKeeper),
// Temporarily disable x/wasm simulation since $ make test-sim-after-import panics
// wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
ibc.NewAppModule(app.IBCKeeper),
app.transferModule,
)
Expand All @@ -877,9 +791,7 @@ func NewApp(
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
IBCKeeper: app.IBCKeeper,
WasmConfig: &wasmConfig,
TXCounterStoreKey: keys[wasm.StoreKey],
IBCKeeper: app.IBCKeeper,
},
)
if err != nil {
Expand All @@ -894,33 +806,14 @@ func NewApp(
app.SetUpgradeStoreLoaders()
app.SetUpgradeHandlers(app.mm, app.configurator)

// must be before Loading version
// requires the snapshot store to be created and registered as a BaseAppOption
// see cmd/wasmd/root.go: 206 - 214 approx
if manager := app.SnapshotManager(); manager != nil {
err := manager.RegisterExtensions(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper),
)
if err != nil {
panic(fmt.Errorf("failed to register snapshot extension: %s", err))
}
}

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper
app.ScopedWasmKeeper = scopedWasmKeeper

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(fmt.Sprintf("failed to load latest version: %s", err))
}
ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})

// Initialize pinned codes in wasmvm as they are not persisted there
if err := app.WasmKeeper.InitializePinnedCodes(ctx); err != nil {
tmos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err))
}
}

return app
Expand Down Expand Up @@ -1087,7 +980,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(marketmakertypes.ModuleName)
paramsKeeper.Subspace(lpfarmtypes.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(wasm.ModuleName)

return paramsKeeper
}
Expand Down
12 changes: 5 additions & 7 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"testing"

"github.com/CosmWasm/wasmd/x/wasm"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/tests/mocks"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -50,7 +49,7 @@ import (
func TestSimAppExportAndBlockedAddrs(t *testing.T) {
encCfg := MakeTestEncodingConfig()
db := dbm.NewMemDB()
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{}, wasm.EnableAllProposals, EmptyWasmOpts)
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{})
for acc := range maccPerms {
require.True(
t,
Expand All @@ -73,7 +72,7 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) {
app.Commit()

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

Expand All @@ -85,7 +84,7 @@ func TestRunMigrations(t *testing.T) {
db := dbm.NewMemDB()
encCfg := MakeTestEncodingConfig()
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
app := NewApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{}, wasm.EnableAllProposals, EmptyWasmOpts)
app := NewApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{})

// Create a new baseapp and configurator for the purpose of this test.
bApp := baseapp.NewBaseApp(AppName, logger, db, encCfg.TxConfig.TxDecoder())
Expand Down Expand Up @@ -202,7 +201,6 @@ func TestRunMigrations(t *testing.T) {
"ibc": ibc.AppModule{}.ConsensusVersion(),
"transfer": transfer.AppModule{}.ConsensusVersion(),
"interchainaccounts": ica.AppModule{}.ConsensusVersion(),
"wasm": wasm.AppModule{}.ConsensusVersion(),
},
)
if tc.expRunErr {
Expand All @@ -220,7 +218,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
db := dbm.NewMemDB()
encCfg := MakeTestEncodingConfig()
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
app := NewApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{}, wasm.EnableAllProposals, EmptyWasmOpts)
app := NewApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{})
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})

// Create a mock module. This module will serve as the new module we're
Expand Down Expand Up @@ -273,7 +271,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
func TestUpgradeStateOnGenesis(t *testing.T) {
encCfg := MakeTestEncodingConfig()
db := dbm.NewMemDB()
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{}, wasm.EnableAllProposals, EmptyWasmOpts)
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{})
genesisState := NewDefaultGenesisState(encCfg.Marshaler)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)
Expand Down
Loading

0 comments on commit 9ebf864

Please sign in to comment.