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 all 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
20 changes: 20 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ 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"
)

const (
Expand All @@ -145,6 +149,7 @@ var (
ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
wasmtypes.StoreKey,
denommetadatamoduletypes.StoreKey,
crontypes.StoreKey,
}
)

Expand Down Expand Up @@ -190,6 +195,7 @@ var (
hubgenesis.AppModuleBasic{},
wasm.AppModuleBasic{},
denommetadata.AppModuleBasic{},
cron.AppModuleBasic{},
)

// module account permissions
Expand All @@ -205,6 +211,7 @@ var (
wasmtypes.ModuleName: {authtypes.Burner},
hubgentypes.ModuleName: {authtypes.Burner},
denommetadatamoduletypes.ModuleName: nil,
crontypes.ModuleName: nil,
}
)

Expand Down Expand Up @@ -257,6 +264,7 @@ type App struct {
TransferKeeper ibctransferkeeper.Keeper
WasmKeeper wasmkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
CronKeeper cronkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -485,6 +493,13 @@ func NewRollapp(
app.AccountKeeper,
)

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

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
Expand Down Expand Up @@ -556,6 +571,7 @@ 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.WasmKeeper),
}

app.mm = module.NewManager(modules...)
Expand Down Expand Up @@ -586,6 +602,7 @@ func NewRollapp(
hubgentypes.ModuleName,
denommetadatamoduletypes.ModuleName,
wasm.ModuleName,
crontypes.ModuleName,
}
app.mm.SetOrderBeginBlockers(beginBlockersList...)

Expand All @@ -610,6 +627,7 @@ func NewRollapp(
hubgentypes.ModuleName,
denommetadatamoduletypes.ModuleName,
wasm.ModuleName,
crontypes.ModuleName,
}
app.mm.SetOrderEndBlockers(endBlockersList...)

Expand Down Expand Up @@ -640,6 +658,7 @@ func NewRollapp(
hubgentypes.ModuleName,
denommetadatamoduletypes.ModuleName,
wasm.ModuleName,
crontypes.ModuleName,
}
app.mm.SetOrderInitGenesis(initGenesisList...)

Expand Down Expand Up @@ -972,5 +991,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(denommetadatamoduletypes.ModuleName)

paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(crontypes.ModuleName)
return paramsKeeper
}
117 changes: 117 additions & 0 deletions app/test_suite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package app

import (
"encoding/json"
"testing"
"time"

"github.com/CosmWasm/wasmd/x/wasm"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
sequencerstypes "github.com/dymensionxyz/dymension-rdk/x/sequencers/types"
cronTypes "github.com/dymensionxyz/rollapp-wasm/x/cron/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"
)

// DefaultConsensusParams defines the default Tendermint consensus params used in
// App testing.
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,
},
},
}

var (
ProposerPK = simapp.CreateTestPubKeys(1)[0]
ProposerConsAddr = sdk.ConsAddress(ProposerPK.Address())

OperatorPK = secp256k1.GenPrivKey().PubKey()
)

var TestChainID = "rollappwasm_1234-1"

func setup(withGenesis bool, invCheckPeriod uint) (*App, map[string]json.RawMessage) {
db := dbm.NewMemDB()

encCdc := MakeEncodingConfig()
var emptyWasmOpts []wasm.Option
testApp := NewRollapp(
log.NewNopLogger(), db, nil, true, map[int64]bool{}, "/tmp", invCheckPeriod, encCdc, GetEnabledProposals(), EmptyAppOptions{}, emptyWasmOpts,
)
if withGenesis {
return testApp, NewDefaultGenesisState(encCdc.Codec)
}
return testApp, map[string]json.RawMessage{}
}

// Setup initializes a new Rollapp. A Nop logger is set in Rollapp.
func Setup(t *testing.T, isCheckTx bool) *App {
t.Helper()

pk, err := cryptocodec.ToTmProtoPublicKey(ProposerPK)
require.NoError(t, err)

app, genesisState := setup(true, 5)

// setup for sequencer
seqGenesis := sequencerstypes.GenesisState{
Params: sequencerstypes.DefaultParams(),
GenesisOperatorAddress: sdk.ValAddress(OperatorPK.Address()).String(),
}
genesisState[sequencerstypes.ModuleName] = app.AppCodec().MustMarshalJSON(&seqGenesis)

// setup for cron
DefaultSecurityAddress := []string{"cosmos1xkxed7rdzvmyvgdshpe445ddqwn47fru24fnlp"}
params := cronTypes.Params{SecurityAddress: DefaultSecurityAddress}
cronGenesis := cronTypes.GenesisState{
Params: params,
CronJobs: []cronTypes.CronJob{},
}
genesisState[cronTypes.ModuleName] = app.AppCodec().MustMarshalJSON(&cronGenesis)

// for now bank genesis won't be set here, funding accounts should be called with fund utils.FundModuleAccount

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)
// init chain will set the validator set and initialize the genesis accounts
app.InitChain(
abci.RequestInitChain{
Time: time.Time{},
ChainId: TestChainID,
ConsensusParams: DefaultConsensusParams,
Validators: []abci.ValidatorUpdate{
{PubKey: pk, Power: 1},
},
AppStateBytes: stateBytes,
InitialHeight: 0,
},
)

return app
}

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

// Get implements AppOptions
func (ao EmptyAppOptions) Get(o string) interface{} {
return nil
}
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,26 @@ require (
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-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/stretchr/testify v1.8.4
github.com/tendermint/tendermint v0.34.29
github.com/tendermint/tm-db v0.6.8-0.20220506192307-f628bb5dc95b
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe
google.golang.org/grpc v1.61.0
)

Expand Down Expand Up @@ -81,7 +88,6 @@ require (
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 +130,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 +148,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 @@ -254,7 +257,6 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
Expand Down Expand Up @@ -282,7 +284,6 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
Expand All @@ -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
26 changes: 26 additions & 0 deletions proto/wasmrollapp/cron/v1beta1/cron.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";
package wasmrollapp.cron.v1beta1;

import "gogoproto/gogo.proto";

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

message CronJob {
// id is the unique identifier for the cron job
uint64 id = 1;
// name is the name of the cron job
string name = 2;
// description is the description of the cron job
string description = 3;
// Msgs that will be executed every period amount of time
repeated MsgContractCron msg_contract_cron = 4 [(gogoproto.nullable) = false];
Copy link
Contributor

Choose a reason for hiding this comment

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

could we add an enabled field here, like suggested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// set cron enabled or not
bool enable_cron = 5;
}

message MsgContractCron {
// Contract is the address of the smart contract
string contract_address = 1;
// Msg is json encoded message to be passed to the contract
string json_msg = 2;
}
20 changes: 20 additions & 0 deletions proto/wasmrollapp/cron/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";
package wasmrollapp.cron.v1beta1;

import "gogoproto/gogo.proto";
import "wasmrollapp/cron/v1beta1/params.proto";
import "wasmrollapp/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 CronJob cron_jobs = 2 [
(gogoproto.moretags) = "yaml:\"cron_jobs\"",
(gogoproto.nullable) = false
];
}
15 changes: 15 additions & 0 deletions proto/wasmrollapp/cron/v1beta1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";
package wasmrollapp.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\""
];
}
Loading