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(cron): add cron module for scheduled execution of wasm contracts #87

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
131493d
aib rollapp custom modules
May 17, 2024
f2c2ee4
Merge pull request #1 from AllInBetsCom/rollapp
rockstarRhino May 17, 2024
fca95cb
specs for gasless module
hunter1269 May 19, 2024
87585ac
cron module spec added
May 19, 2024
85d8643
Merge pull request #2 from AllInBetsCom/gsoec
rockstarRhino May 19, 2024
f8c97c2
gasless app/ante wiring commented until release of gasless RDK version
May 21, 2024
bac1ab0
custom gasless module removed
May 21, 2024
20bdb67
Merge pull request #3 from AllInBetsCom/remove-gasless
rockstarRhino May 21, 2024
304d2ce
testcases added for cron module
May 23, 2024
84a8843
module fixes post review
May 23, 2024
d2a3cf9
fixed lint issues
May 24, 2024
f57c84f
post review fixes
May 24, 2024
6357e42
Merge pull request #4 from AllInBetsCom/cron-fix
rockstarRhino May 24, 2024
a4910f5
removed unused modules
May 28, 2024
53d7419
enable param added for cron module
May 28, 2024
f05ea11
Merge pull request #5 from AllInBetsCom/cron-fix
rockstarRhino May 28, 2024
4244071
module refactored post review
Jun 5, 2024
aa85548
Merge pull request #6 from AllInBetsCom/cron-fix
rockstarRhino Jun 5, 2024
bc79bf7
cron module rework
Jun 12, 2024
5a77676
abci logger fix
Jun 12, 2024
4b8d0e8
Merge pull request #7 from AllInBetsCom/cron-fix
rockstarRhino Jun 12, 2024
5225980
post review fix
Jun 17, 2024
7ce043b
toggle cron job tx added
Jun 17, 2024
d32ded0
typos fix
Jun 17, 2024
d415177
Merge pull request #8 from AllInBetsCom/cron-fix
rockstarRhino Jun 17, 2024
7be8bd9
store refactor
Jun 17, 2024
08b32b9
Merge pull request #9 from AllInBetsCom/cron-fix
rockstarRhino Jun 17, 2024
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
8 changes: 8 additions & 0 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ import (
errorsmod "cosmossdk.io/errors"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
// TODO: revisit
trinitys7 marked this conversation as resolved.
Show resolved Hide resolved
// "github.com/dymensionxyz/rollapp-wasm/x/gasless"
// gaslesskeeper "github.com/dymensionxyz/rollapp-wasm/x/gasless/keeper"
)

// HandlerOptions are the options required for constructing a default SDK AnteHandler.
type HandlerOptions struct {
ante.HandlerOptions

IBCKeeper *ibckeeper.Keeper
// TODO: revisit
// GaslessKeeper gaslesskeeper.Keeper
// BankKeeper gasless.BankKeeper
WasmConfig *wasmtypes.WasmConfig
TxCounterStoreKey storetypes.StoreKey
}
Expand All @@ -40,6 +46,8 @@ func GetAnteDecorators(options HandlerOptions) []sdk.AnteDecorator {

ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
// TODO: revisit
// gasless.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker, options.GaslessKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand Down
63 changes: 63 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ import (

distr "github.com/dymensionxyz/dymension-rdk/x/dist"
distrkeeper "github.com/dymensionxyz/dymension-rdk/x/dist/keeper"

"github.com/dymensionxyz/rollapp-wasm/x/cron"
cronkeeper "github.com/dymensionxyz/rollapp-wasm/x/cron/keeper"
crontypes "github.com/dymensionxyz/rollapp-wasm/x/cron/types"

// TODO: revisit
// "github.com/dymensionxyz/rollapp-wasm/x/gasless"
// gaslessclient "github.com/dymensionxyz/rollapp-wasm/x/gasless/client"
// gaslesskeeper "github.com/dymensionxyz/rollapp-wasm/x/gasless/keeper"
// gaslesstypes "github.com/dymensionxyz/rollapp-wasm/x/gasless/types"
)

const (
Expand All @@ -145,6 +155,9 @@ var (
ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
wasmtypes.StoreKey,
denommetadatamoduletypes.StoreKey,
crontypes.StoreKey,
// TODO: revisit
// gaslesstypes.StoreKey,
}
)

Expand All @@ -158,6 +171,8 @@ func getGovProposalHandlers() []govclient.ProposalHandler {
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
)
// TODO: revisit
// govProposalHandlers = append(govProposalHandlers, gaslessclient.GaslessProposalHandler...)

return govProposalHandlers
}
Expand Down Expand Up @@ -190,6 +205,9 @@ var (
hubgenesis.AppModuleBasic{},
wasm.AppModuleBasic{},
denommetadata.AppModuleBasic{},
cron.AppModuleBasic{},
// TODO: revisit
// gasless.AppModuleBasic{},
)

// module account permissions
Expand All @@ -205,6 +223,9 @@ var (
wasmtypes.ModuleName: {authtypes.Burner},
hubgentypes.ModuleName: {authtypes.Burner},
denommetadatamoduletypes.ModuleName: nil,
crontypes.ModuleName: nil,
// TODO: revisit
// gaslesstypes.ModuleName: nil,
}
)

Expand Down Expand Up @@ -257,6 +278,9 @@ type App struct {
TransferKeeper ibctransferkeeper.Keeper
WasmKeeper wasmkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
CronKeeper cronkeeper.Keeper
// TODO: revisit
// GaslessKeeper gaslesskeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -434,6 +458,8 @@ func NewRollapp(
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))
// TODO: revisit
// AddRoute(gaslesstypes.RouterKey, gasless.NewGaslessProposalHandler(app.GaslessKeeper))

govConfig := govtypes.DefaultConfig()
/*
Expand Down Expand Up @@ -485,6 +511,25 @@ func NewRollapp(
app.AccountKeeper,
)

app.CronKeeper = cronkeeper.NewKeeper(
appCodec,
app.keys[crontypes.StoreKey],
app.keys[crontypes.MemStoreKey],
app.GetSubspace(crontypes.ModuleName),
&app.WasmKeeper,
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review the initialization parameters for the CronKeeper.

The initialization of CronKeeper seems to be missing the contractOpsKeeper, which is essential for contract operations. This should be included to ensure the cron module can interact with contracts as expected.


// TODO: revisit
// app.GaslessKeeper = gaslesskeeper.NewKeeper(
// appCodec,
// app.keys[gaslesstypes.StoreKey],
// app.GetSubspace(gaslesstypes.ModuleName),
// app.interfaceRegistry,
// app.AccountKeeper,
// app.BankKeeper,
// &app.WasmKeeper,
// )

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
Expand Down Expand Up @@ -556,6 +601,9 @@ func NewRollapp(
upgrade.NewAppModule(app.UpgradeKeeper),
hubgenesis.NewAppModule(appCodec, app.HubGenesisKeeper, app.AccountKeeper),
denommetadata.NewAppModule(app.DenomMetadataKeeper, app.BankKeeper),
cron.NewAppModule(appCodec, app.CronKeeper, app.AccountKeeper, app.BankKeeper, app.WasmKeeper),
// TODO: revisit
// gasless.NewAppModule(appCodec, app.GaslessKeeper, app.AccountKeeper, app.BankKeeper),
}

app.mm = module.NewManager(modules...)
Expand Down Expand Up @@ -586,6 +634,9 @@ func NewRollapp(
hubgentypes.ModuleName,
denommetadatamoduletypes.ModuleName,
wasm.ModuleName,
crontypes.ModuleName,
// TODO: revisit
// gaslesstypes.ModuleName,
}
app.mm.SetOrderBeginBlockers(beginBlockersList...)

Expand All @@ -610,6 +661,9 @@ func NewRollapp(
hubgentypes.ModuleName,
denommetadatamoduletypes.ModuleName,
wasm.ModuleName,
crontypes.ModuleName,
// TODO: revisit
// gaslesstypes.ModuleName,
}
app.mm.SetOrderEndBlockers(endBlockersList...)

Expand Down Expand Up @@ -640,6 +694,9 @@ func NewRollapp(
hubgentypes.ModuleName,
denommetadatamoduletypes.ModuleName,
wasm.ModuleName,
crontypes.ModuleName,
// TODO: revisit
// gaslesstypes.ModuleName,
}
app.mm.SetOrderInitGenesis(initGenesisList...)

Expand Down Expand Up @@ -729,6 +786,9 @@ func (app *App) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmtypes.Wa
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
IBCKeeper: app.IBCKeeper,
// TODO: revisit
// GaslessKeeper: app.GaslessKeeper,
// BankKeeper: app.BankKeeper,
WasmConfig: &wasmConfig,
TxCounterStoreKey: app.keys[wasmtypes.StoreKey],
},
Expand Down Expand Up @@ -972,5 +1032,8 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(denommetadatamoduletypes.ModuleName)

paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(crontypes.ModuleName)
// TODO: revisit
// paramsKeeper.Subspace(gaslesstypes.ModuleName)
return paramsKeeper
}
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@ require (
github.com/CosmWasm/wasmd v0.33.0
github.com/bcdevtools/block-explorer-rpc-cosmos v1.2.3
github.com/bcdevtools/wasm-block-explorer-rpc-cosmos v1.1.1
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.46.16
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/ibc-go/v6 v6.3.0
github.com/dymensionxyz/dymension-rdk v1.6.0
github.com/dymensionxyz/dymint v1.1.0-rc02
github.com/ethereum/go-ethereum v1.12.0
github.com/evmos/evmos/v12 v12.1.6
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.18.0
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.8.0
github.com/tendermint/tendermint v0.34.29
github.com/tendermint/tm-db v0.6.8-0.20220506192307-f628bb5dc95b
google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe
google.golang.org/grpc v1.61.0
)

Expand Down Expand Up @@ -79,9 +85,7 @@ require (
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogoproto v1.4.11 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.19.6 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.4 // indirect
Expand Down Expand Up @@ -124,10 +128,8 @@ require (
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/gateway v1.1.0 // indirect
github.com/gogo/protobuf v1.3.3 // indirect
github.com/golang/glog v1.1.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/flatbuffers v2.0.8+incompatible // indirect
Expand All @@ -144,7 +146,6 @@ require (
github.com/gorilla/rpc v1.2.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
Expand Down Expand Up @@ -296,7 +297,6 @@ require (
google.golang.org/api v0.149.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240116215550-a9fa1716bcac // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
15 changes: 15 additions & 0 deletions proto/aib/cron/v1beta1/cron.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";
package aib.cron.v1beta1;

import "gogoproto/gogo.proto";

option go_package = "github.com/dymensionxyz/rollapp-wasm/x/cron/types";

message WhitelistedContract {
uint64 game_id = 1;
string security_address = 2;
string contract_admin = 3;
string game_name = 4;
string contract_address = 5;
uint64 game_type = 6;
}
20 changes: 20 additions & 0 deletions proto/aib/cron/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";
package aib.cron.v1beta1;

import "gogoproto/gogo.proto";
import "aib/cron/v1beta1/params.proto";
import "aib/cron/v1beta1/cron.proto";

option go_package = "github.com/dymensionxyz/rollapp-wasm/x/cron/types";

// GenesisState defines the cron module's genesis state.
message GenesisState {
Params params = 1 [
(gogoproto.moretags) = "yaml:\"params\"",
(gogoproto.nullable) = false
];
repeated WhitelistedContract whitelisted_contracts = 2 [
(gogoproto.moretags) = "yaml:\"whitelisted_contracts\"",
(gogoproto.nullable) = false
];
}
20 changes: 20 additions & 0 deletions proto/aib/cron/v1beta1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";
package aib.cron.v1beta1;

import "gogoproto/gogo.proto";

option go_package = "github.com/dymensionxyz/rollapp-wasm/x/cron/types";

// Params defines the set of module parameters.
message Params {
// Security address that can whitelist/delist contract
repeated string security_address = 1 [
(gogoproto.jsontag) = "security_address,omitempty",
(gogoproto.moretags) = "yaml:\"security_address\""
];

uint64 contract_gas_limit = 2 [
(gogoproto.jsontag) = "contract_gas_limit,omitempty",
(gogoproto.moretags) = "yaml:\"contract_gas_limit\""
];
}
42 changes: 42 additions & 0 deletions proto/aib/cron/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
syntax = "proto3";
package aib.cron.v1beta1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "aib/cron/v1beta1/params.proto";
import "aib/cron/v1beta1/cron.proto";

option go_package = "github.com/dymensionxyz/rollapp-wasm/x/cron/types";

// Query defines the gRPC querier service.
service Query {
// Parameters queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/aib/cron/v1beta1/params";
}
rpc QueryWhitelistedContracts(QueryWhitelistedContractsRequest) returns (QueryWhitelistedContractsResponse) {
option (google.api.http).get = "/aib/cron/v1beta1/whitelisted_contracts";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];
}

message QueryWhitelistedContractsRequest{
cosmos.base.query.v1beta1.PageRequest pagination = 1
[(gogoproto.moretags) = "yaml:\"pagination\""];
}

message QueryWhitelistedContractsResponse {
repeated WhitelistedContract whilisted_contracts = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2
[(gogoproto.moretags) = "yaml:\"pagination\""];
}

32 changes: 32 additions & 0 deletions proto/aib/cron/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
syntax = "proto3";
package aib.cron.v1beta1;
import "gogoproto/gogo.proto";

import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "aib/cron/v1beta1/params.proto";


option go_package = "github.com/dymensionxyz/rollapp-wasm/x/cron/types";

// Msg defines the Msg service.
service Msg {
rpc RegisterContract(MsgRegisterContract) returns(MsgRegisterContractResponse);
rpc DeRegisterContract(MsgDeRegisterContract) returns(MsgDeRegisterContractResponse);
}

message MsgRegisterContract {
string security_address = 1;
string game_name = 2;
string contract_address = 3;
uint64 game_type = 4; // 1 -> single, 2 -> multi, 3 -> both
}

message MsgRegisterContractResponse {}

message MsgDeRegisterContract {
string security_address = 1;
uint64 game_id = 2;
}

message MsgDeRegisterContractResponse {}
Loading
Loading