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(callback): add callback and cwerrors module for scheduled execution of wasm contracts #99

Merged
merged 19 commits into from
Jul 22, 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
53 changes: 52 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ import (
"github.com/dymensionxyz/dymension-rdk/x/hub"
hubkeeper "github.com/dymensionxyz/dymension-rdk/x/hub/keeper"
hubtypes "github.com/dymensionxyz/dymension-rdk/x/hub/types"

"github.com/dymensionxyz/rollapp-wasm/x/callback"
callbackKeeper "github.com/dymensionxyz/rollapp-wasm/x/callback/keeper"
callbackTypes "github.com/dymensionxyz/rollapp-wasm/x/callback/types"

"github.com/dymensionxyz/rollapp-wasm/x/cwerrors"
cwerrorsKeeper "github.com/dymensionxyz/rollapp-wasm/x/cwerrors/keeper"
cwerrorsTypes "github.com/dymensionxyz/rollapp-wasm/x/cwerrors/types"
)

const (
Expand All @@ -150,6 +158,8 @@ var (
ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
wasmtypes.StoreKey, gaslesstypes.StoreKey,
hubtypes.StoreKey,
callbackTypes.StoreKey,
cwerrorsTypes.StoreKey,
}
)

Expand Down Expand Up @@ -196,6 +206,8 @@ var (
hubgenesis.AppModuleBasic{},
wasm.AppModuleBasic{},
hub.AppModuleBasic{},
callback.AppModuleBasic{},
cwerrors.AppModuleBasic{},
)

// module account permissions
Expand All @@ -211,6 +223,7 @@ var (
wasmtypes.ModuleName: {authtypes.Burner},
hubgentypes.ModuleName: {authtypes.Minter},
gaslesstypes.ModuleName: nil,
callbackTypes.ModuleName: nil,
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -270,6 +283,8 @@ type App struct {
WasmKeeper wasmkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
GaslessKeeper gaslesskeeper.Keeper
CallbackKeeper callbackKeeper.Keeper
CWErrorsKeeper cwerrorsKeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -321,7 +336,7 @@ func NewRollapp(
keys := sdk.NewKVStoreKeys(
kvstorekeys...,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, cwerrorsTypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)

// load state streaming if enabled
Expand Down Expand Up @@ -523,6 +538,21 @@ func NewRollapp(
app.BankKeeper,
)

app.CallbackKeeper = callbackKeeper.NewKeeper(
appCodec,
keys[callbackTypes.StoreKey],
&app.WasmKeeper,
app.BankKeeper,
)

app.CWErrorsKeeper = cwerrorsKeeper.NewKeeper(
appCodec,
keys[cwerrorsTypes.StoreKey],
tkeys[cwerrorsTypes.TStoreKey],
&app.WasmKeeper,
app.BankKeeper,
)

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
Expand All @@ -534,6 +564,11 @@ func NewRollapp(
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, enabledProposals))
}

// Include the x/cwerrors query to stargate queries
wasmOpts = append(wasmOpts, wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{
Stargate: wasmkeeper.AcceptListStargateQuerier(getAcceptedStargateQueries(), app.GRPCQueryRouter(), appCodec),
}))

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
availableCapabilities := strings.Join(AllCapabilities(), ",")
Expand Down Expand Up @@ -604,6 +639,8 @@ func NewRollapp(
upgrade.NewAppModule(app.UpgradeKeeper),
hubgenesis.NewAppModule(appCodec, app.HubGenesisKeeper),
hub.NewAppModule(appCodec, app.HubKeeper),
callback.NewAppModule(app.appCodec, app.CallbackKeeper, app.WasmKeeper, app.CWErrorsKeeper),
cwerrors.NewAppModule(app.appCodec, app.CWErrorsKeeper, app.WasmKeeper),
}

app.mm = module.NewManager(modules...)
Expand Down Expand Up @@ -635,6 +672,8 @@ func NewRollapp(
hubgentypes.ModuleName,
hubtypes.ModuleName,
wasm.ModuleName,
callbackTypes.ModuleName,
cwerrorsTypes.ModuleName, // does not have begin blocker
}
app.mm.SetOrderBeginBlockers(beginBlockersList...)

Expand All @@ -660,6 +699,8 @@ func NewRollapp(
hubgentypes.ModuleName,
hubtypes.ModuleName,
wasm.ModuleName,
callbackTypes.ModuleName,
cwerrorsTypes.ModuleName,
}
app.mm.SetOrderEndBlockers(endBlockersList...)

Expand Down Expand Up @@ -691,6 +732,8 @@ func NewRollapp(
hubgentypes.ModuleName,
hubtypes.ModuleName,
wasm.ModuleName,
callbackTypes.ModuleName,
cwerrorsTypes.ModuleName,
}
app.mm.SetOrderInitGenesis(initGenesisList...)

Expand Down Expand Up @@ -1017,5 +1060,13 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(gaslesstypes.ModuleName)

paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(callbackTypes.ModuleName)
paramsKeeper.Subspace(cwerrorsTypes.ModuleName)
return paramsKeeper
}

func getAcceptedStargateQueries() wasmkeeper.AcceptedStargateQueries {
return wasmkeeper.AcceptedStargateQueries{
"/rollapp.cwerrors.v1.Query/Errors": &cwerrorsTypes.QueryErrorsRequest{},
}
}
36 changes: 36 additions & 0 deletions app/test_app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package app

import (
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
"time"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
)

var DefaultConsensusParams = &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: 200000,
MaxGas: -1,
},
Evidence: &tmproto.EvidenceParams{
MaxAgeNumBlocks: 302400,
MaxAgeDuration: 504 * time.Hour, // 3 weeks is the max duration
MaxBytes: 10000,
},
Validator: &tmproto.ValidatorParams{
PubKeyTypes: []string{
tmtypes.ABCIPubKeyTypeEd25519,
},
},
}

// EmptyAppOptions is a stub implementing AppOptions
type EmptyAppOptions struct{}

// Get implements AppOptions
func (ao EmptyAppOptions) Get(o string) interface{} {
return nil
}
1 change: 1 addition & 0 deletions app/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ func AllCapabilities() []string {
"stargate",
"cosmwasm_1_1",
"cosmwasm_1_2",
"cosmwasm_1_3",
}
}
11 changes: 11 additions & 0 deletions contracts/callback-test/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.rs]
indent_size = 4
16 changes: 16 additions & 0 deletions contracts/callback-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Build results
/target
/schema

# Cargo+Git helper file (https://github.com/rust-lang/cargo/blob/0.44.1/src/cargo/sources/git/utils.rs#L320-L327)
.cargo-ok

# Text file backups
**/*.rs.bk

# macOS
.DS_Store

# IDEs
*.iml
.idea
Loading
Loading