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

feat!: change wasm module to wrapped x/wasmplus #141

Merged
merged 4 commits into from
Feb 13, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (lbm-sdk) [\#137](https://github.com/line/lbm/pull/137) Bump line/lbm-sdk to 6c84a4cffa
* (x/collection,token) [\#138](https://github.com/line/lbm/pull/138) Add x/token and x/collection
* (ibc-go) [\#140](https://github.com/line/lbm/pull/140) apply ibc-go
* (x/wasmplus) [\#141](https://github.com/line/lbm/pull/141) change wasm module to wrapped `x/wasmplus`

### Improvements

Expand Down
9 changes: 8 additions & 1 deletion ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import (
sdk "github.com/line/lbm-sdk/types"
sdkerrors "github.com/line/lbm-sdk/types/errors"
"github.com/line/lbm-sdk/x/auth/ante"
wasmkeeper "github.com/line/wasmd/x/wasm/keeper"
wasmtypes "github.com/line/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
IBCkeeper *ibckeeper.Keeper
WasmConfig *wasmtypes.WasmConfig
}

func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
Expand All @@ -26,6 +29,9 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
if opts.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for AnteHandler")
}
if opts.WasmConfig == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder")
}

sigGasConsumer := opts.SigGasConsumer
if sigGasConsumer == nil {
Expand All @@ -34,6 +40,7 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(),
wasmkeeper.NewLimitSimulationGasDecorator(opts.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early
ante.NewRejectExtensionOptionsDecorator(),
ante.NewMempoolFeeDecorator(),
ante.NewValidateBasicDecorator(),
Expand Down
42 changes: 24 additions & 18 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ import (
"github.com/line/wasmd/x/wasm"
wasmclient "github.com/line/wasmd/x/wasm/client"
wasmkeeper "github.com/line/wasmd/x/wasm/keeper"
"github.com/line/wasmd/x/wasmplus"
wasmpluskeeper "github.com/line/wasmd/x/wasmplus/keeper"
wasmplustypes "github.com/line/wasmd/x/wasmplus/types"

appante "github.com/line/lbm/ante"
appparams "github.com/line/lbm/app/params"
Expand Down Expand Up @@ -167,7 +170,7 @@ var (
ibc.AppModuleBasic{},
transfer.AppModuleBasic{},
ica.AppModuleBasic{},
wasm.AppModuleBasic{},
wasmplus.AppModuleBasic{},
)

// module account permissions
Expand All @@ -182,6 +185,7 @@ var (
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
wasmplustypes.ModuleName: {authtypes.Burner},
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -233,7 +237,7 @@ type LinkApp struct { // nolint: golint
ClassKeeper classkeeper.Keeper
TokenKeeper tokenkeeper.Keeper
CollectionKeeper collectionkeeper.Keeper
WasmKeeper wasm.Keeper
WasmKeeper wasmpluskeeper.Keeper

ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -294,7 +298,7 @@ func NewLinkApp(
ibchost.StoreKey,
ibctransfertypes.StoreKey,
icahosttypes.StoreKey,
wasm.StoreKey,
wasmplustypes.StoreKey,
)

tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -327,7 +331,7 @@ func NewLinkApp(
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasmplustypes.ModuleName)

// Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating
// their scoped modules in `NewApp` with `ScopeToModule`
Expand Down Expand Up @@ -420,7 +424,8 @@ func NewLinkApp(
// create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(wasmplustypes.ModuleName, wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper))

app.IBCKeeper.SetRouter(ibcRouter)

Expand All @@ -432,11 +437,11 @@ func NewLinkApp(

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
supportedFeatures := "iterator,staking,stargate"
app.WasmKeeper = wasm.NewKeeper(
availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1"
app.WasmKeeper = wasmpluskeeper.NewKeeper(
appCodec,
keys[wasm.StoreKey],
app.GetSubspace(wasm.ModuleName),
keys[wasmplustypes.StoreKey],
app.GetSubspace(wasmplustypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
Expand All @@ -449,7 +454,7 @@ func NewLinkApp(
app.GRPCQueryRouter(),
wasmDir,
wasmConfig,
supportedFeatures,
availableCapabilities,
wasmOpts...,
)

Expand All @@ -460,7 +465,7 @@ func NewLinkApp(
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(wasm.RouterKey, wasmkeeper.NewWasmProposalHandler(app.WasmKeeper, wasm.EnableAllProposals))
AddRoute(wasmplustypes.RouterKey, wasmpluskeeper.NewWasmProposalHandler(&app.WasmKeeper, wasmplustypes.EnableAllProposals))

govKeeper := govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
Expand Down Expand Up @@ -504,7 +509,7 @@ func NewLinkApp(
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
stakingplusmodule.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.FoundationKeeper),
upgrade.NewAppModule(app.UpgradeKeeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
wasmplus.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
params.NewAppModule(app.ParamsKeeper),
tokenmodule.NewAppModule(appCodec, app.TokenKeeper),
Expand Down Expand Up @@ -542,7 +547,7 @@ func NewLinkApp(
ibctransfertypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
wasm.ModuleName,
wasmplustypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
crisistypes.ModuleName,
Expand All @@ -567,7 +572,7 @@ func NewLinkApp(
ibctransfertypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
wasm.ModuleName,
wasmplustypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -603,7 +608,7 @@ func NewLinkApp(
ibchost.ModuleName,
icatypes.ModuleName,
// wasm after ibc transfer
wasm.ModuleName,
wasmplustypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down Expand Up @@ -640,7 +645,8 @@ func NewLinkApp(
FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
IBCkeeper: app.IBCKeeper,
IBCkeeper: app.IBCKeeper,
WasmConfig: &wasmConfig,
},
)
if err != nil {
Expand All @@ -655,7 +661,7 @@ func NewLinkApp(
// see cmd/lbm/cmd/root.go: 257-265
if manager := app.SnapshotManager(); manager != nil {
err := manager.RegisterExtensions(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper),
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper.Keeper),
)
if err != nil {
panic(fmt.Errorf("failed to register snapshot extension: %s", err))
Expand Down Expand Up @@ -860,7 +866,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(wasm.ModuleName)
paramsKeeper.Subspace(wasmplustypes.ModuleName)

return paramsKeeper
}
2 changes: 2 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
foundationmodule "github.com/line/lbm-sdk/x/foundation/module"
"github.com/line/lbm-sdk/x/genutil"
"github.com/line/lbm-sdk/x/gov"
"github.com/line/wasmd/x/wasmplus"

"github.com/line/ibc-go/v3/modules/apps/transfer"
ibc "github.com/line/ibc-go/v3/modules/core"
Expand Down Expand Up @@ -179,6 +180,7 @@ func TestRunMigrations(t *testing.T) {
"foundation": foundationmodule.AppModule{}.ConsensusVersion(),
"token": tokenmodule.AppModule{}.ConsensusVersion(),
"collection": collectionmodule.AppModule{}.ConsensusVersion(),
"wasm": wasmplus.AppModule{}.ConsensusVersion(),
},
)
if tc.expRunErr {
Expand Down