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

added wasm light client #1224

Merged
merged 2 commits into from
Jun 24, 2024
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
35 changes: 34 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
wasmvm "github.com/CosmWasm/wasmvm"
"github.com/Stride-Labs/ibc-rate-limiting/ratelimit"
ratelimitkeeper "github.com/Stride-Labs/ibc-rate-limiting/ratelimit/keeper"
ratelimittypes "github.com/Stride-Labs/ibc-rate-limiting/ratelimit/types"
Expand Down Expand Up @@ -88,6 +89,9 @@ import (
ibchooks "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7"
ibchookskeeper "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/keeper"
ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types"
ibcwasm "github.com/cosmos/ibc-go/modules/light-clients/08-wasm"
ibcwasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper"
ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
icacontroller "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
Expand Down Expand Up @@ -227,6 +231,7 @@ var (
stakedym.AppModuleBasic{},
wasm.AppModuleBasic{},
ibchooks.AppModuleBasic{},
ibcwasm.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -311,6 +316,7 @@ type StrideApp struct {
WasmKeeper wasmkeeper.Keeper
ContractKeeper *wasmkeeper.PermissionedKeeper
IBCHooksKeeper ibchookskeeper.Keeper
WasmClientKeeper ibcwasmkeeper.Keeper

// Middleware for IBCHooks
Ics20WasmHooks *ibchooks.WasmHooks
Expand Down Expand Up @@ -391,6 +397,7 @@ func NewStrideApp(
stakedymtypes.StoreKey,
wasmtypes.StoreKey,
ibchookstypes.StoreKey,
ibcwasmtypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -542,14 +549,27 @@ func NewStrideApp(
// Set the TransferKeeper reference in the PacketForwardKeeper
app.PacketForwardKeeper.SetTransferKeeper(app.TransferKeeper)

// Add wasm keeper (must be after IBCKeeper and TransferKeeper)
// Add wasm keeper and wasm client keeper (must be after IBCKeeper and TransferKeeper)
wasmContractMemoryLimit := uint32(32)
wasmCapabilities := "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4"
wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error while reading wasm config: %s", err))
}

wasmer, err := wasmvm.NewVM(
wasmDir,
wasmCapabilities,
wasmContractMemoryLimit,
wasmConfig.ContractDebugMode,
wasmConfig.MemoryCacheSize,
)
if err != nil {
panic(err)
}
wasmOpts = append(wasmOpts, wasmkeeper.WithWasmEngine(wasmer))

scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName)
app.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
Expand All @@ -573,6 +593,15 @@ func NewStrideApp(
)
app.ContractKeeper = wasmkeeper.NewDefaultPermissionKeeper(app.WasmKeeper)

app.WasmClientKeeper = ibcwasmkeeper.NewKeeperWithVM(
appCodec,
keys[ibcwasmtypes.StoreKey],
app.IBCKeeper.ClientKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmer,
app.GRPCQueryRouter(),
)
assafmo marked this conversation as resolved.
Show resolved Hide resolved

// Create evidence Keeper for to register the IBC light client misbehaviour evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec, keys[evidencetypes.StoreKey], &app.ConsumerKeeper, app.SlashingKeeper,
Expand Down Expand Up @@ -874,6 +903,7 @@ func NewStrideApp(
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.BaseApp.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
ibchooks.NewAppModule(app.AccountKeeper),
transfer.NewAppModule(app.TransferKeeper),
ibcwasm.NewAppModule(app.WasmClientKeeper),
// monitoringModule,
stakeibcModule,
epochsModule,
Expand Down Expand Up @@ -930,6 +960,7 @@ func NewStrideApp(
stakedymtypes.ModuleName,
wasmtypes.ModuleName,
ibchookstypes.ModuleName,
ibcwasmtypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand Down Expand Up @@ -969,6 +1000,7 @@ func NewStrideApp(
stakedymtypes.ModuleName,
wasmtypes.ModuleName,
ibchookstypes.ModuleName,
ibcwasmtypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -1013,6 +1045,7 @@ func NewStrideApp(
stakedymtypes.ModuleName,
wasmtypes.ModuleName,
ibchookstypes.ModuleName,
ibcwasmtypes.ModuleName,
)

app.mm.RegisterInvariants(app.CrisisKeeper)
Expand Down
6 changes: 6 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types"
ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
consumertypes "github.com/cosmos/interchain-security/v4/x/ccv/consumer/types"
evmosvestingtypes "github.com/evmos/vesting/x/vesting/types"

Expand Down Expand Up @@ -303,6 +304,7 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) {
v23.CreateUpgradeHandler(
app.mm,
app.configurator,
app.IBCKeeper.ClientKeeper,
app.StakeibcKeeper,
),
)
Expand Down Expand Up @@ -364,6 +366,10 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) {
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{ibchookstypes.StoreKey},
}
case "v23":
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{ibcwasmtypes.ModuleName},
}
}

if storeUpgrades != nil {
Expand Down
13 changes: 13 additions & 0 deletions app/upgrades/v23/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
clientkeeper "github.com/cosmos/ibc-go/v7/modules/core/02-client/keeper"

stakeibckeeper "github.com/Stride-Labs/stride/v22/x/stakeibc/keeper"
)
Expand All @@ -16,11 +18,15 @@ var (
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
clientKeeper clientkeeper.Keeper,
stakeibcKeeper stakeibckeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Starting upgrade v23...")

ctx.Logger().Info("Adding wasm client...")
AddWasmAllowedClient(ctx, clientKeeper)

ctx.Logger().Info("Migrating trade routes...")
MigrateTradeRoutes(ctx, stakeibcKeeper)

Expand All @@ -29,6 +35,13 @@ func CreateUpgradeHandler(
}
}

// Add the wasm client to the IBC client's allowed clients
func AddWasmAllowedClient(ctx sdk.Context, k clientkeeper.Keeper) {
params := k.GetParams(ctx)
params.AllowedClients = append(params.AllowedClients, ibcwasmtypes.Wasm)
k.SetParams(ctx, params)
}

// Migration to deprecate the trade config
// The min transfer amount can be set from the min swap amount
func MigrateTradeRoutes(ctx sdk.Context, k stakeibckeeper.Keeper) {
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
cosmossdk.io/errors v1.0.1
cosmossdk.io/math v1.3.0
github.com/CosmWasm/wasmd v0.45.0
github.com/CosmWasm/wasmvm v1.5.2
github.com/Stride-Labs/ibc-rate-limiting v1.0.0
github.com/cometbft/cometbft v0.37.4
github.com/cometbft/cometbft-db v0.8.0
Expand All @@ -16,6 +17,7 @@ require (
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.3-0.20240228213828-cce7f56d000b
github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240403143657-8e64543c87e0
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.2-0.20240412103620-7ee2a2452b79
assafmo marked this conversation as resolved.
Show resolved Hide resolved
github.com/cosmos/ibc-go/v7 v7.4.0
github.com/cosmos/ics23/go v0.10.0
github.com/cosmos/interchain-security/v4 v4.0.0
Expand Down Expand Up @@ -49,7 +51,6 @@ require (
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect
github.com/CosmWasm/wasmvm v1.5.2 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aws/aws-sdk-go v1.44.203 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.3-0.2024
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.3-0.20240228213828-cce7f56d000b/go.mod h1:UvDmcGIWJPIytq+Q78/ff5NTOsuX/7IrNgEugTW5i0s=
github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240403143657-8e64543c87e0 h1:obD+CSx+aXpMEUWHLyMkWEcxLuYAcxvQaIXTwjjh3qI=
github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240403143657-8e64543c87e0/go.mod h1:JwHFbo1oX/ht4fPpnPvmhZr+dCkYK1Vihw+vZE9umR4=
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.2-0.20240412103620-7ee2a2452b79 h1:Y7zi+3BksgH5kCMLFfC2vghihNoQVrt3Ft+sHtgywPQ=
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.2-0.20240412103620-7ee2a2452b79/go.mod h1:VR2Hg2i/X1bafbmmNsV2Khwsg0PzNeuWoVKmSN5dAwo=
github.com/cosmos/ibc-go/v7 v7.4.0 h1:8FqYMptvksgMvlbN4UW9jFxTXzsPyfAzEZurujXac8M=
github.com/cosmos/ibc-go/v7 v7.4.0/go.mod h1:L/KaEhzV5TGUCTfGysVgMBQtl5Dm7hHitfpk+GIeoAo=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
Expand Down
Loading