diff --git a/.dockerignore b/.dockerignore index 95fde967f..9e0f33074 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,9 @@ Dockerfile +# build +/bin +!/bin/engine + # repo files README.md CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 69e951529..6d98c1db5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ # Changelog +## [v0.18.1](https://github.com/mesg-foundation/engine/releases/tag/v0.18.1) + +#### Added + +- ([#1580](https://github.com/mesg-foundation/engine/pull/1580)) Add execution metrics. +- ([#1595](https://github.com/mesg-foundation/engine/pull/1595)) Add cosmos cli for low-level utility functionality. + +#### Changed + +- ([#1572](https://github.com/mesg-foundation/engine/pull/1572)) Customize cosmos address prefix. +- ([#1601](https://github.com/mesg-foundation/engine/pull/1601)) Change default block time to 5sec and some token config. +- ([#1602](https://github.com/mesg-foundation/engine/pull/1602)) Change the mesg coin type to the registered one (470). + +#### Fixed + +- ([#1588](https://github.com/mesg-foundation/engine/pull/1588)) Fix supply module init. +- ([#1598](https://github.com/mesg-foundation/engine/pull/1598)) Fix account number used for signing tx. +- ([#1553](https://github.com/mesg-foundation/engine/pull/1553)) Add fees and estimation of tx's gas. + +#### Removed + +- ([#1579](https://github.com/mesg-foundation/engine/pull/1579)) Remove useless database config. + ## [v0.18.0](https://github.com/mesg-foundation/engine/releases/tag/v0.18.0) #### Breaking Changes diff --git a/Makefile b/Makefile index b23808282..e3b2f1cb1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all e2e check-version docker-publish docker-publish-dev docker-tools dev dev-stop dev-start lint dep build test mock protobuf changelog clean genesis clean-build clean-docker +.PHONY: all e2e check-version docker-publish docker-publish-dev docker-tools dev dev-stop dev-start lint dep build test mock protobuf changelog clean genesis clean-build clean-docker build-cmd-cosmos MAJOR_VERSION := $(shell echo $(version) | cut -d . -f 1) MINOR_VERSION := $(shell echo $(version) | cut -d . -f 1-2) @@ -51,6 +51,10 @@ dep: build: check-version dep go build -mod=readonly -o ./bin/engine -ldflags="-X 'github.com/mesg-foundation/engine/version.Version=$(version)'" core/main.go +build-cmd-cosmos: dep + go build -mod=readonly -o ./bin/mesg-cosmos ./cmd/mesg-cosmos/main.go + go build -mod=readonly -o ./bin/mesg-cosmos-daemon ./cmd/mesg-cosmos-daemon/main.go + e2e: docker-dev ./scripts/run-e2e.sh diff --git a/cmd/mesg-cosmos-daemon/main.go b/cmd/mesg-cosmos-daemon/main.go new file mode 100644 index 000000000..8d9a09fcf --- /dev/null +++ b/cmd/mesg-cosmos-daemon/main.go @@ -0,0 +1,111 @@ +package main + +import ( + "encoding/json" + "io" + "os" + "path/filepath" + + "github.com/cosmos/cosmos-sdk/server" + "github.com/cosmos/cosmos-sdk/x/genaccounts" + genaccscli "github.com/cosmos/cosmos-sdk/x/genaccounts/client/cli" + genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" + "github.com/cosmos/cosmos-sdk/x/staking" + "github.com/mesg-foundation/engine/codec" + "github.com/mesg-foundation/engine/config" + "github.com/mesg-foundation/engine/cosmos" + "github.com/mesg-foundation/engine/logger" + enginesdk "github.com/mesg-foundation/engine/sdk" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/cli" + "github.com/tendermint/tendermint/libs/log" + tmtypes "github.com/tendermint/tendermint/types" + db "github.com/tendermint/tm-db" +) + +var ( + defaultCLIHome = os.ExpandEnv("$HOME/.mesg-cosmos-cli") + app *cosmos.App +) + +func main() { + cobra.EnableCommandSorting = false + + // init app and codec + cfg, err := config.New() + if err != nil { + panic(err) + } + db, err := db.NewGoLevelDB("app", filepath.Join(cfg.Path, cfg.Cosmos.RelativePath)) + if err != nil { + panic(err) + } + appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db, cfg.Cosmos.MinGasPrices) + enginesdk.NewBackend(appFactory) + app, err = cosmos.NewApp(appFactory) + if err != nil { + panic(err) + } + cosmos.CustomizeConfig() + cdc := codec.Codec + + ctx := server.NewDefaultContext() + + rootCmd := &cobra.Command{ + Use: "mesg-cosmos-daemon", + Short: "ClI Daemon (server)", + PersistentPreRunE: server.PersistentPreRunEFn(ctx), + } + // CLI commands to initialize the chain + rootCmd.AddCommand( + genutilcli.InitCmd(ctx, cdc, app.BasicManager(), cfg.Tendermint.Config.RootDir), + genutilcli.CollectGenTxsCmd(ctx, cdc, genaccounts.AppModuleBasic{}, cfg.Tendermint.Config.RootDir), + genutilcli.GenTxCmd( + ctx, cdc, app.BasicManager(), staking.AppModuleBasic{}, + genaccounts.AppModuleBasic{}, cfg.Tendermint.Config.RootDir, defaultCLIHome, + ), + genutilcli.ValidateGenesisCmd(ctx, cdc, app.BasicManager()), + genaccscli.AddGenesisAccountCmd(ctx, cdc, cfg.Tendermint.Config.RootDir, defaultCLIHome), + ) + + server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators) + + // prepare and add flags + executor := cli.PrepareBaseCmd(rootCmd, "MESG", cfg.Tendermint.Config.RootDir) + err = executor.Execute() + if err != nil { + panic(err) + } +} + +func newApp(logger log.Logger, db db.DB, traceStore io.Writer) abci.Application { + return app +} + +func exportAppStateAndTMValidators(logger log.Logger, db db.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string, +) (json.RawMessage, []tmtypes.GenesisValidator, error) { + return nil, nil, nil +} + +/* +genaccounts +func AddGenesisAccountCmd(ctx *server.Context, cdc *codec.Codec, defaultNodeHome, defaultClientHome string) *cobra.Command { + +genutil +func CollectGenTxsCmd(ctx *server.Context, cdc *codec.Codec, genAccIterator types.GenesisAccountsIterator, defaultNodeHome string) *cobra.Command { +func GenTxCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager, smbh StakingMsgBuildingHelpers, genAccIterator types.GenesisAccountsIterator, defaultNodeHome, defaultCLIHome string) *cobra.Command { +func InitCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager, defaultNodeHome string) *cobra.Command { +func MigrateGenesisCmd(_ *server.Context, cdc *codec.Codec) *cobra.Command { +func ValidateGenesisCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager) *cobra.Command { + +server +func AddCommands(ctx *Context, cdc *codec.Codec, rootCmd *cobra.Command, appCreator AppCreator, appExport AppExporter) { + func StartCmd(ctx *Context, appCreator AppCreator) *cobra.Command { + func ExportCmd(ctx *Context, cdc *codec.Codec, appExporter AppExporter) *cobra.Command { + func ShowNodeIDCmd(ctx *Context) *cobra.Command { + func ShowValidatorCmd(ctx *Context) *cobra.Command { + func ShowAddressCmd(ctx *Context) *cobra.Command { + func VersionCmd(ctx *Context) *cobra.Command { + func UnsafeResetAllCmd(ctx *Context) *cobra.Command { +*/ diff --git a/cmd/mesg-cosmos/main.go b/cmd/mesg-cosmos/main.go new file mode 100644 index 000000000..f778659b8 --- /dev/null +++ b/cmd/mesg-cosmos/main.go @@ -0,0 +1,255 @@ +package main + +import ( + "os" + "path" + "path/filepath" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/keys" + "github.com/cosmos/cosmos-sdk/client/lcd" + "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/version" + authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" + authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" + "github.com/mesg-foundation/engine/codec" + "github.com/mesg-foundation/engine/config" + "github.com/mesg-foundation/engine/cosmos" + "github.com/mesg-foundation/engine/logger" + enginesdk "github.com/mesg-foundation/engine/sdk" + "github.com/spf13/cobra" + "github.com/spf13/viper" + amino "github.com/tendermint/go-amino" + "github.com/tendermint/tendermint/libs/cli" + db "github.com/tendermint/tm-db" +) + +var ( + defaultCLIHome = os.ExpandEnv("$HOME/.mesg-cosmos-cli") + app *cosmos.App +) + +func main() { + // init app and codec + cfg, err := config.New() + if err != nil { + panic(err) + } + db, err := db.NewGoLevelDB("app", filepath.Join(cfg.Path, cfg.Cosmos.RelativePath)) + if err != nil { + panic(err) + } + appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db, cfg.Cosmos.MinGasPrices) + enginesdk.NewBackend(appFactory) + app, err = cosmos.NewApp(appFactory) + if err != nil { + panic(err) + } + cosmos.CustomizeConfig() + cdc := codec.Codec + + rootCmd := &cobra.Command{ + Use: "mesg-cosmos", + Short: "Cosmos Client", + } + + // Add --chain-id to persistent flags and mark it required + rootCmd.PersistentFlags().String(client.FlagChainID, "", "Chain ID of tendermint node") + rootCmd.PersistentPreRunE = func(_ *cobra.Command, _ []string) error { + return initConfig(rootCmd) + } + + // Construct Root Command + rootCmd.AddCommand( + rpc.StatusCommand(), + client.ConfigCmd(defaultCLIHome), + queryCmd(cdc), + txCmd(cdc), + lcd.ServeCommand(cdc, registerRoutes), + keys.Commands(), + version.Cmd, + client.NewCompletionCmd(rootCmd, true), + ) + + executor := cli.PrepareMainCmd(rootCmd, "MESG", defaultCLIHome) + err = executor.Execute() + if err != nil { + panic(err) + } +} + +func registerRoutes(rs *lcd.RestServer) { + client.RegisterRoutes(rs.CliCtx, rs.Mux) + authrest.RegisterTxRoutes(rs.CliCtx, rs.Mux) + app.BasicManager().RegisterRESTRoutes(rs.CliCtx, rs.Mux) +} + +func queryCmd(cdc *amino.Codec) *cobra.Command { + queryCmd := &cobra.Command{ + Use: "query", + Aliases: []string{"q"}, + Short: "Querying subcommands", + } + + queryCmd.AddCommand( + rpc.ValidatorCommand(cdc), + rpc.BlockCommand(), + authcmd.QueryTxsByEventsCmd(cdc), + authcmd.QueryTxCmd(cdc), + ) + + // add modules' query commands + app.BasicManager().AddQueryCommands(queryCmd, cdc) + + return queryCmd +} + +func txCmd(cdc *amino.Codec) *cobra.Command { + txCmd := &cobra.Command{ + Use: "tx", + Short: "Transactions subcommands", + } + + txCmd.AddCommand( + authcmd.GetBroadcastCommand(cdc), + authcmd.GetEncodeCommand(cdc), + ) + + // add modules' tx commands + app.BasicManager().AddTxCommands(txCmd, cdc) + + return txCmd +} + +func initConfig(cmd *cobra.Command) error { + home, err := cmd.PersistentFlags().GetString(cli.HomeFlag) + if err != nil { + return err + } + + cfgFile := path.Join(home, "config", "config.toml") + if _, err := os.Stat(cfgFile); err == nil { + viper.SetConfigFile(cfgFile) + + if err := viper.ReadInConfig(); err != nil { + return err + } + } + if err := viper.BindPFlag(client.FlagChainID, cmd.PersistentFlags().Lookup(client.FlagChainID)); err != nil { + return err + } + if err := viper.BindPFlag(cli.EncodingFlag, cmd.PersistentFlags().Lookup(cli.EncodingFlag)); err != nil { + return err + } + return viper.BindPFlag(cli.OutputFlag, cmd.PersistentFlags().Lookup(cli.OutputFlag)) +} + +/* +List of commands that could be used in this cli + +distribution +func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command { + func GetCmdWithdrawRewards(cdc *codec.Codec) *cobra.Command { + func GetCmdWithdrawAllRewards(cdc *codec.Codec, queryRoute string) *cobra.Command { + func GetCmdSetWithdrawAddr(cdc *codec.Codec) *cobra.Command { +func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryValidatorOutstandingRewards(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryValidatorCommission(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryValidatorSlashes(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryDelegatorRewards(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryCommunityPool(queryRoute string, cdc *codec.Codec) *cobra.Command { +func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command { + +gov +func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryVote(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryDeposits(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryTally(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryParam(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryProposer(queryRoute string, cdc *codec.Codec) *cobra.Command { +func GetTxCmd(storeKey string, cdc *codec.Codec, pcmds []*cobra.Command) *cobra.Command { + func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command { + func GetCmdDeposit(cdc *codec.Codec) *cobra.Command { + func GetCmdVote(cdc *codec.Codec) *cobra.Command { + +bank +func GetTxCmd(cdc *codec.Codec) *cobra.Command { + func SendTxCmd(cdc *codec.Codec) *cobra.Command { + +params +func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command { + +auth +func GetQueryCmd(cdc *codec.Codec) *cobra.Command { + func GetAccountCmd(cdc *codec.Codec) *cobra.Command { +func QueryTxsByEventsCmd(cdc *codec.Codec) *cobra.Command { +func QueryTxCmd(cdc *codec.Codec) *cobra.Command { +func GetTxCmd(cdc *codec.Codec) *cobra.Command { + func GetSignCommand(codec *codec.Codec) *cobra.Command { + func GetMultiSignCommand(cdc *codec.Codec) *cobra.Command { +func GetBroadcastCommand(cdc *codec.Codec) *cobra.Command { +func GetEncodeCommand(cdc *codec.Codec) *cobra.Command { + +staking +func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryValidator(storeName string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryValidators(storeName string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryValidatorUnbondingDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryValidatorRedelegations(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryDelegation(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryValidatorDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryUnbondingDelegation(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryUnbondingDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryRedelegation(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryRedelegations(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryPool(storeName string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryParams(storeName string, cdc *codec.Codec) *cobra.Command { +func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command { + func GetCmdCreateValidator(cdc *codec.Codec) *cobra.Command { + func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command { + func GetCmdDelegate(cdc *codec.Codec) *cobra.Command { + func GetCmdRedelegate(storeName string, cdc *codec.Codec) *cobra.Command { + func GetCmdUnbond(storeName string, cdc *codec.Codec) *cobra.Command { + +crisis +func GetTxCmd(cdc *codec.Codec) *cobra.Command { + func GetCmdInvariantBroken(cdc *codec.Codec) *cobra.Command { + +supply +func GetQueryCmd(cdc *codec.Codec) *cobra.Command { + func GetCmdQueryTotalSupply(cdc *codec.Codec) *cobra.Command { + +slashing +func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { + func GetCmdQuerySigningInfo(storeName string, cdc *codec.Codec) *cobra.Command { + func GetCmdQueryParams(cdc *codec.Codec) *cobra.Command { +func GetTxCmd(cdc *codec.Codec) *cobra.Command { + func GetCmdUnjail(cdc *codec.Codec) *cobra.Command { + +mint +func GetQueryCmd(cdc *codec.Codec) *cobra.Command { + func GetCmdQueryParams(cdc *codec.Codec) *cobra.Command { + func GetCmdQueryInflation(cdc *codec.Codec) *cobra.Command { + func GetCmdQueryAnnualProvisions(cdc *codec.Codec) *cobra.Command { + +client +func ConfigCmd(defaultCLIHome string) *cobra.Command { + +client/lcd +func ServeCommand(cdc *codec.Codec, registerRoutesFn func(*RestServer)) *cobra.Command { + +client/keys +func Commands() *cobra.Command { + +client/rpc +func ValidatorCommand(cdc *codec.Codec) *cobra.Command { +func StatusCommand() *cobra.Command { +func BlockCommand() *cobra.Command { +*/ diff --git a/config/config.go b/config/config.go index 3b417b1b1..1e13e77bb 100644 --- a/config/config.go +++ b/config/config.go @@ -7,6 +7,7 @@ import ( "path/filepath" "time" + sdkcosmos "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/go-bip39" homedir "github.com/mitchellh/go-homedir" "github.com/sirupsen/logrus" @@ -19,10 +20,6 @@ const ( defaultConfigFileName = "config.yml" envPathKey = "MESG_PATH" envNameKey = "MESG_NAME" - - executionDBVersion = "v3" - instanceDBVersion = "v2" - processDBVersion = "v2" ) // Config contains all the configuration needed. @@ -42,12 +39,6 @@ type Config struct { Level string `validate:"required"` } - Database struct { - InstanceRelativePath string `validate:"required"` - ExecutionRelativePath string `validate:"required"` - ProcessRelativePath string `validate:"required"` - } - Tendermint struct { Config *tmconfig.Config `validate:"required"` RelativePath string `validate:"required"` @@ -55,15 +46,19 @@ type Config struct { Cosmos struct { RelativePath string `validate:"required"` + MinGasPrices string `validate:"required"` } DevGenesis struct { - ChainID string `validate:"required"` + ChainID string `validate:"required"` + InitialBalances string `validate:"required"` } Account struct { Name string `validate:"required"` Password string `validate:"required"` + Number uint32 + Index uint32 Mnemonic string } } @@ -87,25 +82,25 @@ func defaultConfig() (*Config, error) { c.Log.Level = "info" c.Log.ForceColors = false - c.Database.InstanceRelativePath = filepath.Join("database", "instance", instanceDBVersion) - c.Database.ExecutionRelativePath = filepath.Join("database", "executions", executionDBVersion) - c.Database.ProcessRelativePath = filepath.Join("database", "processes", processDBVersion) - c.Tendermint.RelativePath = "tendermint" c.Tendermint.Config = tmconfig.DefaultConfig() c.Tendermint.Config.RPC.ListenAddress = "tcp://0.0.0.0:26657" c.Tendermint.Config.P2P.AddrBookStrict = false c.Tendermint.Config.P2P.AllowDuplicateIP = true - c.Tendermint.Config.Consensus.TimeoutCommit = 1 * time.Second + c.Tendermint.Config.Consensus.TimeoutCommit = 5 * time.Second c.Tendermint.Config.Instrumentation.Prometheus = true c.Tendermint.Config.Instrumentation.PrometheusListenAddr = "0.0.0.0:26660" c.Cosmos.RelativePath = "cosmos" + c.Cosmos.MinGasPrices = "1.0atto" c.DevGenesis.ChainID = "mesg-dev-chain" + c.DevGenesis.InitialBalances = "1000000000000000000000000atto" // 1 000 000 * 10^18 c.Account.Name = "engine" c.Account.Password = "pass" + c.Account.Number = uint32(0) + c.Account.Index = uint32(0) return &c, nil } @@ -170,14 +165,19 @@ func (c *Config) prepare() error { // validate checks values and return an error if any validation failed. func (c *Config) validate() error { if _, err := logrus.ParseLevel(c.Log.Level); err != nil { - return fmt.Errorf("config.Log.Level error: %w", err) + return fmt.Errorf("config log.level error: %w", err) } if c.Account.Mnemonic != "" && !bip39.IsMnemonicValid(c.Account.Mnemonic) { - return fmt.Errorf("config.Account.Mnemonic error: mnemonic is not valid") + return fmt.Errorf("config account.mnemonic error: mnemonic is not valid") } if err := c.Tendermint.Config.ValidateBasic(); err != nil { - return fmt.Errorf("config.Tendermint error: %w", err) + return fmt.Errorf("config tendermint error: %w", err) + } + if _, err := sdkcosmos.ParseDecCoins(c.Cosmos.MinGasPrices); err != nil { + return fmt.Errorf("config cosmos.mingasprices error: %w", err) + } + if _, err := sdkcosmos.ParseCoins(c.DevGenesis.InitialBalances); err != nil { + return fmt.Errorf("config devgenesis.initialbalances error: %w", err) } - return validator.New().Struct(c) } diff --git a/config/config_test.go b/config/config_test.go index 488ac781f..0399b45d9 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -26,10 +26,11 @@ func TestDefaultConfig(t *testing.T) { require.Equal(t, "info", c.Log.Level) require.Equal(t, false, c.Log.ForceColors) require.Equal(t, filepath.Join(home, ".mesg"), c.Path) - require.Equal(t, filepath.Join("database", "executions", executionDBVersion), c.Database.ExecutionRelativePath) require.Equal(t, "engine", c.Name) require.Equal(t, "engine", c.Account.Name) require.Equal(t, "pass", c.Account.Password) + require.Equal(t, uint32(0), c.Account.Number) + require.Equal(t, uint32(0), c.Account.Index) } func TestEnv(t *testing.T) { @@ -61,6 +62,8 @@ log: forcecolors: true account: mnemonic: glimpse upon body vast economy give taxi yellow rabbit come click ranch chronic hammer sport near rotate charge lumber chicken cloud base thing forum +cosmos: + mingasprices: 2.0019294mesg tendermint: config: consensus: @@ -75,5 +78,6 @@ tendermint: require.Equal(t, "tcp://0.0.0.0:26657", c.Tendermint.Config.RPC.ListenAddress) require.Equal(t, tempPath, c.Path) require.Equal(t, "engine", c.Name) + require.Equal(t, "2.0019294mesg", c.Cosmos.MinGasPrices) }) } diff --git a/core/main.go b/core/main.go index a3cfe3194..c6ee8c64c 100644 --- a/core/main.go +++ b/core/main.go @@ -62,7 +62,7 @@ func stopRunningServices(sdk *enginesdk.SDK, address string) error { func loadOrGenConfigAccount(kb *cosmos.Keybase, cfg *config.Config) (keys.Info, error) { if cfg.Account.Mnemonic != "" { logrus.WithField("module", "main").Warn("Config account mnemonic presents. Generating account with it...") - return kb.CreateAccount(cfg.Account.Name, cfg.Account.Mnemonic, "", cfg.Account.Password, cosmos.AccNumber, cosmos.AccIndex) + return kb.CreateAccount(cfg.Account.Name, cfg.Account.Mnemonic, "", cfg.Account.Password, cfg.Account.Number, cfg.Account.Index) } exist, err := kb.Exist(cfg.Account.Name) @@ -82,7 +82,7 @@ func loadOrGenConfigAccount(kb *cosmos.Keybase, cfg *config.Config) (keys.Info, "password": cfg.Account.Password, "mnemonic": mnemonic, }).Warn("Account") - return kb.CreateAccount(cfg.Account.Name, mnemonic, "", cfg.Account.Password, cosmos.AccNumber, cosmos.AccIndex) + return kb.CreateAccount(cfg.Account.Name, mnemonic, "", cfg.Account.Password, cfg.Account.Number, cfg.Account.Index) } func loadOrGenDevGenesis(app *cosmos.App, kb *cosmos.Keybase, cfg *config.Config) (*tmtypes.GenesisDoc, error) { @@ -105,7 +105,7 @@ func loadOrGenDevGenesis(app *cosmos.App, kb *cosmos.Keybase, cfg *config.Config "nodeID": validator.NodeID, "peer": fmt.Sprintf("%s@%s:26656", validator.NodeID, validator.Name), }).Warnln("Validator") - return cosmos.GenGenesis(kb, app.DefaultGenesis(), cfg.DevGenesis.ChainID, cfg.Tendermint.Config.GenesisFile(), []cosmos.GenesisValidator{validator}) + return cosmos.GenGenesis(kb, app.DefaultGenesis(), cfg.DevGenesis.ChainID, cfg.DevGenesis.InitialBalances, cfg.Tendermint.Config.GenesisFile(), []cosmos.GenesisValidator{validator}) } func main() { @@ -132,8 +132,11 @@ func main() { if err != nil { logrus.WithField("module", "main").Fatalln(err) } + + cosmos.CustomizeConfig() + // TODO: rename NewAppFactory to something else - appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db) + appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db, cfg.Cosmos.MinGasPrices) // register the backend modules to the app factory. // TODO: this is a mandatory call so it should return a new types required by cosmos.NewApp @@ -156,6 +159,7 @@ func main() { if err != nil { logrus.WithField("module", "main").Fatalln(err) } + logrus.WithField("address", acc.GetAddress().String()).Info("engine account") // load or gen genesis genesis, err := loadOrGenDevGenesis(app, kb, cfg) @@ -170,7 +174,7 @@ func main() { } // create cosmos client - client := cosmos.NewClient(node, kb, genesis.ChainID, cfg.Account.Name, cfg.Account.Password) + client := cosmos.NewClient(node, kb, genesis.ChainID, cfg.Account.Name, cfg.Account.Password, cfg.Cosmos.MinGasPrices) // init sdk sdk := enginesdk.New(client, kb, container, cfg.Name, strconv.Itoa(port), cfg.IpfsEndpoint) diff --git a/cosmos/app.go b/cosmos/app.go index 750832042..a19160b84 100644 --- a/cosmos/app.go +++ b/cosmos/app.go @@ -68,3 +68,8 @@ func NewApp(factory *AppFactory) (*App, error) { func (a *App) DefaultGenesis() map[string]json.RawMessage { return a.basicManager.DefaultGenesis() } + +// BasicManager returns app basic manager. +func (a *App) BasicManager() module.BasicManager { + return a.basicManager +} diff --git a/cosmos/appfactory.go b/cosmos/appfactory.go index b6f2ef419..17318f6ce 100644 --- a/cosmos/appfactory.go +++ b/cosmos/appfactory.go @@ -27,12 +27,12 @@ type AppFactory struct { } // NewAppFactory returns a new AppFactory. -func NewAppFactory(logger log.Logger, db dbm.DB) *AppFactory { +func NewAppFactory(logger log.Logger, db dbm.DB, minGasPrices string) *AppFactory { sdk.RegisterCodec(codec.Codec) cosmoscodec.RegisterCrypto(codec.Codec) return &AppFactory{ - baseApp: bam.NewBaseApp("engine", logger, db, auth.DefaultTxDecoder(codec.Codec)), + baseApp: bam.NewBaseApp("engine", logger, db, auth.DefaultTxDecoder(codec.Codec), baseapp.SetMinGasPrices(minGasPrices)), modules: []module.AppModule{}, storeKeys: map[string]*sdk.KVStoreKey{ bam.MainStoreKey: sdk.NewKVStoreKey(bam.MainStoreKey), diff --git a/cosmos/client.go b/cosmos/client.go index 60c3a34ee..01e582528 100644 --- a/cosmos/client.go +++ b/cosmos/client.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys" sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" + authutils "github.com/cosmos/cosmos-sdk/x/auth/client/utils" "github.com/mesg-foundation/engine/codec" "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/x/xreflect" @@ -24,10 +25,11 @@ import ( // Client is a tendermint client with helper functions. type Client struct { *rpcclient.Local - kb keys.Keybase - chainID string - accName string - accPassword string + kb keys.Keybase + chainID string + accName string + accPassword string + minGasPrices string // Local state acc auth.Account @@ -36,13 +38,14 @@ type Client struct { } // NewClient returns a rpc tendermint client. -func NewClient(node *node.Node, kb keys.Keybase, chainID, accName, accPassword string) *Client { +func NewClient(node *node.Node, kb keys.Keybase, chainID, accName, accPassword, minGasPrices string) *Client { return &Client{ - Local: rpcclient.NewLocal(node), - kb: kb, - chainID: chainID, - accName: accName, - accPassword: accPassword, + Local: rpcclient.NewLocal(node), + kb: kb, + chainID: chainID, + accName: accName, + accPassword: accPassword, + minGasPrices: minGasPrices, } } @@ -179,17 +182,19 @@ func (c *Client) GetAccount() (auth.Account, error) { accKb.GetAddress(), nil, accKb.GetPubKey(), - AccNumber, + 0, 0, ) } localSeq := c.acc.GetSequence() - if accR, err := auth.NewAccountRetriever(c).GetAccount(c.acc.GetAddress()); err == nil { - c.acc = accR - // replace seq if sup - if localSeq > c.acc.GetSequence() { - c.acc.SetSequence(localSeq) - } + accR, err := auth.NewAccountRetriever(c).GetAccount(c.acc.GetAddress()) + if err != nil { + return nil, err + } + c.acc = accR + // replace seq if sup + if localSeq > c.acc.GetSequence() { + c.acc.SetSequence(localSeq) } return c.acc, nil } @@ -204,7 +209,26 @@ func (c *Client) sign(msg sdktypes.Msg) (tenderminttypes.Tx, error) { sequence := acc.GetSequence() acc.SetSequence(acc.GetSequence() + 1) - txBuilder := NewTxBuilder(sequence, c.kb, c.chainID) + minGasPrices, err := sdktypes.ParseDecCoins(c.minGasPrices) + if err != nil { + return nil, err + } + + txBuilder := NewTxBuilder(acc.GetAccountNumber(), sequence, c.kb, c.chainID, minGasPrices) + + // simulate tx to estimate the gas + if txBuilder.SimulateAndExecute() { + txBytes, err := txBuilder.BuildTxForSim([]sdktypes.Msg{msg}) + if err != nil { + return nil, err + } + _, adjusted, err := authutils.CalculateGas(c.QueryWithData, codec.Codec, txBytes, txBuilder.GasAdjustment()) + if err != nil { + return nil, err + } + txBuilder = txBuilder.WithGas(adjusted) + } + signedTx, err := txBuilder.BuildAndSignStdTx(msg, c.accName, c.accPassword) if err != nil { return nil, err diff --git a/cosmos/config.go b/cosmos/config.go new file mode 100644 index 000000000..c5c4f0aa9 --- /dev/null +++ b/cosmos/config.go @@ -0,0 +1,40 @@ +package cosmos + +import sdktypes "github.com/cosmos/cosmos-sdk/types" + +// See github.com/cosmos/cosmos-sdk/types/address.go +const ( + // Bech32MainPrefix defines the main Bech32 prefix + Bech32MainPrefix = "mesgtest" + + // CoinType is the mesg registered coin type from https://github.com/satoshilabs/slips/blob/master/slip-0044.md. + CoinType = 470 + + // BIP44Prefix is the parts of the BIP44 HD path that are fixed by + // what we used during the fundraiser. + FullFundraiserPath = "44'/470'/0'/0/0" + + // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address + Bech32PrefixAccAddr = Bech32MainPrefix + // Bech32PrefixAccPub defines the Bech32 prefix of an account's public key + Bech32PrefixAccPub = Bech32MainPrefix + sdktypes.PrefixPublic + // Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address + Bech32PrefixValAddr = Bech32MainPrefix + sdktypes.PrefixValidator + sdktypes.PrefixOperator + // Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key + Bech32PrefixValPub = Bech32MainPrefix + sdktypes.PrefixValidator + sdktypes.PrefixOperator + sdktypes.PrefixPublic + // Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address + Bech32PrefixConsAddr = Bech32MainPrefix + sdktypes.PrefixValidator + sdktypes.PrefixConsensus + // Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key + Bech32PrefixConsPub = Bech32MainPrefix + sdktypes.PrefixValidator + sdktypes.PrefixConsensus + sdktypes.PrefixPublic +) + +// CustomizeConfig customizes the cosmos application like addresses prefixes and coin type +func CustomizeConfig() { + config := sdktypes.GetConfig() + config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) + config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub) + config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub) + config.SetFullFundraiserPath(FullFundraiserPath) + config.SetCoinType(CoinType) + config.Seal() +} diff --git a/cosmos/genesis.go b/cosmos/genesis.go index 5d911de3d..9d254e015 100644 --- a/cosmos/genesis.go +++ b/cosmos/genesis.go @@ -53,7 +53,7 @@ func LoadGenesis(genesisFile string) (*tmtypes.GenesisDoc, error) { } // GenGenesis generates a new genesis and save it. -func GenGenesis(kb *Keybase, defaultGenesisŚtate map[string]json.RawMessage, chainID string, genesisFile string, validators []GenesisValidator) (*tmtypes.GenesisDoc, error) { +func GenGenesis(kb *Keybase, defaultGenesisŚtate map[string]json.RawMessage, chainID, initialBalances, genesisFile string, validators []GenesisValidator) (*tmtypes.GenesisDoc, error) { msgs := []sdktypes.Msg{} for _, validator := range validators { // get account @@ -65,8 +65,9 @@ func GenGenesis(kb *Keybase, defaultGenesisŚtate map[string]json.RawMessage, ch msgs = append(msgs, genCreateValidatorMsg(acc.GetAddress(), validator.Name, validator.ValPubKey)) } // generate genesis transaction + accNumber := uint64(0) sequence := uint64(0) - b := NewTxBuilder(sequence, kb, chainID) + b := NewTxBuilder(accNumber, sequence, kb, chainID, sdktypes.DecCoins{}) signedMsg, err := b.BuildSignMsg(msgs) if err != nil { return nil, err @@ -79,7 +80,7 @@ func GenGenesis(kb *Keybase, defaultGenesisŚtate map[string]json.RawMessage, ch } } // generate genesis - appState, err := genGenesisAppState(defaultGenesisŚtate, validatorTx) + appState, err := genGenesisAppState(defaultGenesisŚtate, validatorTx, initialBalances) if err != nil { return nil, err } @@ -108,11 +109,15 @@ func genGenesisDoc(appState map[string]json.RawMessage, chainID string, genesisT return genesis, genesis.ValidateAndComplete() } -func genGenesisAppState(defaultGenesisŚtate map[string]json.RawMessage, signedStdTx authtypes.StdTx) (map[string]json.RawMessage, error) { +func genGenesisAppState(defaultGenesisŚtate map[string]json.RawMessage, signedStdTx authtypes.StdTx, initialBalances string) (map[string]json.RawMessage, error) { genAccs := []genaccounts.GenesisAccount{} for _, signer := range signedStdTx.GetSigners() { stakes := sdktypes.NewCoin(sdktypes.DefaultBondDenom, sdktypes.NewInt(100000000)) - genAcc := genaccounts.NewGenesisAccountRaw(signer, sdktypes.NewCoins(stakes), sdktypes.NewCoins(), 0, 0, "", "") + initialB, err := sdktypes.ParseCoin(initialBalances) + if err != nil { + return nil, err + } + genAcc := genaccounts.NewGenesisAccountRaw(signer, sdktypes.NewCoins(stakes, initialB), sdktypes.NewCoins(), 0, 0, "", "") if err := genAcc.Validate(); err != nil { return nil, err } diff --git a/cosmos/genesis_test.go b/cosmos/genesis_test.go index d959d97c7..772ce8b2b 100644 --- a/cosmos/genesis_test.go +++ b/cosmos/genesis_test.go @@ -28,6 +28,7 @@ func TestGenesis(t *testing.T) { // variables var ( chainID = "test-chainID" + initialBalances = "100amesg" name = "name" password = "pass" privValidatorKeyFile = filepath.Join(path, "privValidatorKeyFile.json") @@ -39,7 +40,7 @@ func TestGenesis(t *testing.T) { ) // init account mnemonic, _ := kb.NewMnemonic() - kb.CreateAccount(name, mnemonic, "", password, AccNumber, AccIndex) + kb.CreateAccount(name, mnemonic, "", password, 0, 0) // start tests t.Run("generate validator", func(t *testing.T) { v, err := NewGenesisValidator(kb, name, password, privValidatorKeyFile, privValidatorStateFile, nodeKeyFile) @@ -57,7 +58,7 @@ func TestGenesis(t *testing.T) { require.False(t, GenesisExist(genesisPath)) }) t.Run("generate genesis", func(t *testing.T) { - genesis, err := GenGenesis(kb, defaultGenesisState, chainID, genesisPath, validators) + genesis, err := GenGenesis(kb, defaultGenesisState, chainID, initialBalances, genesisPath, validators) require.NoError(t, err) require.NotEmpty(t, genesis) }) diff --git a/cosmos/keybase.go b/cosmos/keybase.go index 1b08c5331..030cdffb2 100644 --- a/cosmos/keybase.go +++ b/cosmos/keybase.go @@ -12,14 +12,7 @@ import ( "github.com/tendermint/tendermint/crypto" ) -const ( - // AccNumber is the account number of the account in keybase. - AccNumber = 0 - // AccIndex is the account index of the account in keybase. - AccIndex = 0 - - mnemonicEntropySize = 256 -) +const mnemonicEntropySize = 256 // Keybase is a standard cosmos keybase. type Keybase struct { diff --git a/cosmos/keybase_test.go b/cosmos/keybase_test.go index bf0211779..210997e9d 100644 --- a/cosmos/keybase_test.go +++ b/cosmos/keybase_test.go @@ -26,7 +26,7 @@ func TestKeybase(t *testing.T) { }) t.Run("Create", func(t *testing.T) { - acc, err := kb.CreateAccount(name, mnemonic, "", password, AccNumber, AccIndex) + acc, err := kb.CreateAccount(name, mnemonic, "", password, 0, 0) require.NoError(t, err) require.Equal(t, name, acc.GetName()) }) diff --git a/cosmos/txbuilder.go b/cosmos/txbuilder.go index 143478732..40f418f38 100644 --- a/cosmos/txbuilder.go +++ b/cosmos/txbuilder.go @@ -16,23 +16,29 @@ type TxBuilder struct { } // NewTxBuilder returns a new initialized TxBuilder. -func NewTxBuilder(accSeq uint64, kb keys.Keybase, chainID string) TxBuilder { +func NewTxBuilder(accNumber, accSeq uint64, kb keys.Keybase, chainID string, minGasPrices sdktypes.DecCoins) TxBuilder { return TxBuilder{ authtypes.NewTxBuilder( authutils.GetTxEncoder(codec.Codec), - AccNumber, + accNumber, accSeq, - 1000000, + flags.DefaultGasLimit, flags.DefaultGasAdjustment, true, chainID, "", sdktypes.NewCoins(), - sdktypes.DecCoins{}, + minGasPrices, ).WithKeybase(kb), } } +// WithGas returns a copy of the context with an updated gas. +func (b TxBuilder) WithGas(gas uint64) TxBuilder { + b.TxBuilder = b.TxBuilder.WithGas(gas) + return b +} + // BuildAndSignStdTx a signed transaction from a message. func (b TxBuilder) BuildAndSignStdTx(msg sdktypes.Msg, accountName, accountPassword string) (authtypes.StdTx, error) { signedMsg, err := b.BuildSignMsg([]sdktypes.Msg{msg}) diff --git a/e2e/testdata/e2e.config.yml b/e2e/testdata/e2e.config.yml index 6b3f86524..feda05243 100644 --- a/e2e/testdata/e2e.config.yml +++ b/e2e/testdata/e2e.config.yml @@ -1,2 +1,6 @@ account: mnemonic: glimpse upon body vast economy give taxi yellow rabbit come click ranch chronic hammer sport near rotate charge lumber chicken cloud base thing forum +tendermint: + config: + consensus: + timeoutcommit: 1s \ No newline at end of file diff --git a/go.mod b/go.mod index 5fffe69f7..b1b0d1da3 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect github.com/go-bindata/go-bindata v0.0.0-20181025070752-41975c0ccc30 + github.com/go-kit/kit v0.9.0 github.com/go-playground/locales v0.13.0 github.com/go-playground/universal-translator v0.17.0 github.com/gogo/protobuf v1.3.1 @@ -28,6 +29,7 @@ require ( github.com/google/uuid v1.1.1 // indirect github.com/gorilla/mux v1.7.3 github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 + github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 github.com/huandu/xstrings v1.2.0 // indirect github.com/imdario/mergo v0.3.7 // indirect github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect @@ -44,7 +46,7 @@ require ( github.com/opencontainers/image-spec v1.0.1 // indirect github.com/opencontainers/runc v0.1.1 // indirect github.com/pelletier/go-toml v1.4.0 // indirect - github.com/prometheus/client_golang v1.1.0 // indirect + github.com/prometheus/client_golang v1.1.0 github.com/pseudomuto/protoc-gen-doc v1.3.0 github.com/pseudomuto/protokit v0.2.0 // indirect github.com/rakyll/statik v0.1.6 // indirect @@ -52,16 +54,15 @@ require ( github.com/sirupsen/logrus v1.4.2 github.com/spf13/afero v1.2.2 // indirect github.com/spf13/cobra v0.0.5 + github.com/spf13/viper v1.6.1 github.com/stretchr/objx v0.2.0 // indirect github.com/stretchr/testify v1.4.0 - github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965 - github.com/tendermint/go-amino v0.15.0 - github.com/tendermint/tendermint v0.32.7 + github.com/tendermint/go-amino v0.15.1 + github.com/tendermint/tendermint v0.32.8 github.com/tendermint/tm-db v0.2.0 github.com/vektra/mockery v0.0.0-20181123154057-e78b021dcbb5 golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 // indirect - golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // indirect golang.org/x/tools v0.0.0-20190813142322-97f12d73768f // indirect google.golang.org/grpc v1.25.1 gopkg.in/go-playground/assert.v1 v1.2.1 // indirect diff --git a/go.sum b/go.sum index 6a3a9a9e3..5fe711632 100644 --- a/go.sum +++ b/go.sum @@ -155,6 +155,8 @@ github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= @@ -167,6 +169,7 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmo github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 h1:THDBEeQ9xZ8JEaCLyLQqXMMdRqNr0QAUJTIkQAUtFjg= github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= @@ -186,6 +189,8 @@ github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22 github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= @@ -300,6 +305,10 @@ github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa/go.mod h1:oJyF+mSPHbB5mVY2iO9KV3pTt/QbIkGaO8gQ2WrDbP4= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -323,6 +332,9 @@ github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU= github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= +github.com/spf13/viper v1.5.0/go.mod h1:AkYRkVJF8TkSG/xet6PzXX+l39KhhXa2pdqVSxnTcn4= +github.com/spf13/viper v1.6.1 h1:VPZzIkznI1YhVMRi6vNFLHSwhnhReBfgTxIPccpfdZk= +github.com/spf13/viper v1.6.1/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -336,6 +348,8 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stumble/gorocksdb v0.0.3 h1:9UU+QA1pqFYJuf9+5p7z1IqdE5k0mma4UAeu2wmX8kA= github.com/stumble/gorocksdb v0.0.3/go.mod h1:v6IHdFBXk5DJ1K4FZ0xi+eY737quiiBxYtSWXadLybY= +github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965 h1:1oFLiOyVl+W7bnBzGhf7BbIv9loSFQcieWWYIjLqcAw= github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= github.com/tendermint/btcd v0.1.1 h1:0VcxPfflS2zZ3RiOAHkBiFUcPvbtRj5O7zHmcJWHV7s= @@ -345,12 +359,16 @@ github.com/tendermint/crypto v0.0.0-20180820045704-3764759f34a5/go.mod h1:z4YtwM github.com/tendermint/go-amino v0.14.1/go.mod h1:i/UKE5Uocn+argJJBb12qTZsCDBcAYMbR92AaJVmKso= github.com/tendermint/go-amino v0.15.0 h1:TC4e66P59W7ML9+bxio17CPKnxW3nKIRAYskntMAoRk= github.com/tendermint/go-amino v0.15.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= +github.com/tendermint/go-amino v0.15.1 h1:D2uk35eT4iTsvJd9jWIetzthE5C0/k2QmMFkCN+4JgQ= +github.com/tendermint/go-amino v0.15.1/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= github.com/tendermint/iavl v0.12.4 h1:hd1woxUGISKkfUWBA4mmmTwOua6PQZTJM/F0FDrmMV8= github.com/tendermint/iavl v0.12.4/go.mod h1:8LHakzt8/0G3/I8FUU0ReNx98S/EP6eyPJkAUvEXT/o= github.com/tendermint/tendermint v0.32.1 h1:J8ddXMbCmG6GZjdCl/N1wgdXDU9uO91J2Y5CA9xYfGo= github.com/tendermint/tendermint v0.32.1/go.mod h1:jmPDAKuNkev9793/ivn/fTBnfpA9mGBww8MPRNPNxnU= github.com/tendermint/tendermint v0.32.7 h1:Szu5Fm1L3pvn3t4uQxPAcP+7ndZEQKgLie/yokM56rU= github.com/tendermint/tendermint v0.32.7/go.mod h1:D2+A3pNjY+Po72X0mTfaXorFhiVI8dh/Zg640FGyGtE= +github.com/tendermint/tendermint v0.32.8 h1:eOaLJGRi5x/Rb23fiVsxq9c5fZ/6O5QplExlGjNPDVI= +github.com/tendermint/tendermint v0.32.8/go.mod h1:5/B1XZjNYtVBso8o1l/Eg4A0Mhu42lDcmftoQl95j/E= github.com/tendermint/tm-db v0.1.1 h1:G3Xezy3sOk9+ekhjZ/kjArYIs1SmwV+1OUgNkj7RgV0= github.com/tendermint/tm-db v0.1.1/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw= github.com/tendermint/tm-db v0.2.0 h1:rJxgdqn6fIiVJZy4zLpY1qVlyD0TU6vhkT4kEf71TQQ= @@ -435,6 +453,7 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190226205152-f727befe758c h1:vamGzbGri8IKo20MQncCuljcQ5uAO6kaCeawQPVblAI= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190813142322-97f12d73768f h1:nQv5Lx4ucsmk8T4jkEQKJu7YLkYXy/PLoZgTpnIrkuI= @@ -469,6 +488,8 @@ gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXa gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= gopkg.in/go-playground/validator.v9 v9.30.2 h1:icxYLlYflpazIV3ufMoNB9h9SYMQ37DZ8CTwkU4pnOs= gopkg.in/go-playground/validator.v9 v9.30.2/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= +gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= @@ -477,6 +498,7 @@ gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= diff --git a/internal/tools/gen-genesis/main.go b/internal/tools/gen-genesis/main.go deleted file mode 100644 index 342c07d08..000000000 --- a/internal/tools/gen-genesis/main.go +++ /dev/null @@ -1,130 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "io/ioutil" - "log" - "math/rand" - "os" - "path/filepath" - "strings" - "time" - - "github.com/mesg-foundation/engine/cosmos" - "github.com/mesg-foundation/engine/logger" - enginesdk "github.com/mesg-foundation/engine/sdk" - "github.com/sirupsen/logrus" - "github.com/tendermint/tendermint/config" - db "github.com/tendermint/tm-db" -) - -const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" - -func randompassword() string { - b := make([]byte, 16) - for i := range b { - b[i] = letters[rand.Intn(len(letters))] - } - return string(b) -} - -var ( - validators = flag.String("validators", "engine", "list of validator names separated with a comma") - chainid = flag.String("chain-id", "mesg-chain", "chain id") - path = flag.String("path", ".genesis/", "genesis folder path") -) - -const ( - tendermintPath = "tendermint" - cosmosPath = "cosmos" -) - -func main() { - rand.Seed(time.Now().UnixNano()) - flag.Parse() - - validatorNames := strings.Split(*validators, ",") - passwords := make([]string, len(validatorNames)) - for i := 0; i < len(validatorNames); i++ { - passwords[i] = randompassword() - } - - // init app factory - db, err := db.NewGoLevelDB("app", filepath.Join(*path, cosmosPath)) - if err != nil { - logrus.Fatalln(err) - } - appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db) - - // register the backend modules to the app factory. - enginesdk.NewBackend(appFactory) - - // init cosmos app - app, err := cosmos.NewApp(appFactory) - if err != nil { - logrus.Fatalln(err) - } - - // init keybase - kb, err := cosmos.NewKeybase(filepath.Join(*path, cosmosPath)) - if err != nil { - logrus.Fatalln(err) - } - - // create validators - vals := []cosmos.GenesisValidator{} - peers := []string{} - for i, valName := range validatorNames { - cfg := config.DefaultConfig() - cfg.SetRoot(filepath.Join(filepath.Join(*path, tendermintPath), valName)) - if err := os.MkdirAll(filepath.Dir(cfg.GenesisFile()), 0755); err != nil { - logrus.Fatalln(err) - } - if err := os.MkdirAll(filepath.Join(cfg.DBDir()), 0755); err != nil { - logrus.Fatalln(err) - } - mnemonic, err := kb.NewMnemonic() - if err != nil { - logrus.Fatalln(err) - } - acc, err := kb.CreateAccount(valName, mnemonic, "", passwords[i], cosmos.AccNumber, cosmos.AccIndex) - if err != nil { - logrus.Fatalln(err) - } - genVal, err := cosmos.NewGenesisValidator(kb, - valName, - passwords[i], - cfg.PrivValidatorKeyFile(), - cfg.PrivValidatorStateFile(), - cfg.NodeKeyFile(), - ) - if err != nil { - logrus.Fatalln(err) - } - vals = append(vals, genVal) - peer := fmt.Sprintf("%s@%s:26656", genVal.NodeID, genVal.Name) - logrus.WithFields(map[string]interface{}{ - "name": genVal.Name, - "address": acc.GetAddress().String, - "password": genVal.Password, - "mnemonic": mnemonic, - "nodeID": genVal.NodeID, - "peer": peer, - }).Infof("Validator #%d\n", i+1) - peers = append(peers, peer) - } - - // generate and save genesis - _, err = cosmos.GenGenesis(kb, app.DefaultGenesis(), *chainid, filepath.Join(*path, "genesis.json"), vals) - if err != nil { - logrus.Fatalln(err) - } - - // save peers list - if err := ioutil.WriteFile(filepath.Join(*path, "peers.txt"), []byte(strings.Join(peers, ",")), 0644); err != nil { - log.Fatalln("error during writing peers file:", err) - } - - logrus.Infof("genesis created with success in folder %q\n", *path) -} diff --git a/scripts/dev.sh b/scripts/dev.sh index 5bdf784bb..be685380d 100755 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -9,6 +9,8 @@ MESG_PATH=${MESG_PATH:-"$HOME/.mesg"} MESG_SERVER_PORT=${MESG_SERVER_PORT:-"50052"} MESG_TENDERMINT_NETWORK="mesg-tendermint" MESG_TENDERMINT_PORT=${MESG_TENDERMINT_PORT:-"26656"} +MESG_TENDERMINT_RPC_PORT=${MESG_TENDERMINT_RPC_PORT:-"26657"} +MESG_PROMETHEUS_RPC_PORT=${MESG_PROMETHEUS_RPC_PORT:-"26660"} function onexit { set +e @@ -61,6 +63,8 @@ function start_engine { --network name=$MESG_TENDERMINT_NETWORK \ --publish $MESG_SERVER_PORT:50052 \ --publish $MESG_TENDERMINT_PORT:26656 \ + --publish $MESG_TENDERMINT_RPC_PORT:26657 \ + --publish $MESG_PROMETHEUS_RPC_PORT:26660 \ mesg/engine:local } @@ -90,7 +94,7 @@ case $cmd in start_engine if ! $quiet; then trap onexit EXIT - docker service logs --tail 10000 --follow --raw $MESG_NAME + docker service logs --tail 1000 --follow --raw $MESG_NAME fi ;; stop) diff --git a/sdk/backend.go b/sdk/backend.go index d79343684..e536b00a5 100644 --- a/sdk/backend.go +++ b/sdk/backend.go @@ -67,6 +67,19 @@ func initDefaultCosmosModules(app *cosmos.AppFactory) { slashingStoreKey := cosmostypes.NewKVStoreKey(slashing.StoreKey) app.RegisterStoreKey(slashingStoreKey) + // account permissions + maccPerms := map[string][]string{ + auth.FeeCollectorName: nil, + distribution.ModuleName: nil, + staking.BondedPoolName: {supply.Burner, supply.Staking}, + staking.NotBondedPoolName: {supply.Burner, supply.Staking}, + } + // Module Accounts Addresses + modAccAddrs := make(map[string]bool) + for acc := range maccPerms { + modAccAddrs[supply.NewModuleAddress(acc).String()] = true + } + // init cosmos keepers paramsKeeper := params.NewKeeper( codec.Codec, @@ -84,19 +97,14 @@ func initDefaultCosmosModules(app *cosmos.AppFactory) { accountKeeper, paramsKeeper.Subspace(bank.DefaultParamspace), bank.DefaultCodespace, - nil, + modAccAddrs, ) supplyKeeper := supply.NewKeeper( codec.Codec, supplyStoreKey, accountKeeper, bankKeeper, - map[string][]string{ - auth.FeeCollectorName: nil, - distribution.ModuleName: nil, - staking.BondedPoolName: {supply.Burner, supply.Staking}, - staking.NotBondedPoolName: {supply.Burner, supply.Staking}, - }, + maccPerms, ) stakingKeeper := staking.NewKeeper( codec.Codec, @@ -114,7 +122,7 @@ func initDefaultCosmosModules(app *cosmos.AppFactory) { supplyKeeper, distribution.DefaultCodespace, auth.FeeCollectorName, - nil, + modAccAddrs, ) slashingKeeper := slashing.NewKeeper( codec.Codec, @@ -151,6 +159,8 @@ func initDefaultCosmosModules(app *cosmos.AppFactory) { auth.ModuleName, bank.ModuleName, slashing.ModuleName, + supply.ModuleName, + // TODO: the app's module should be here!! genutil.ModuleName, ) } diff --git a/sdk/execution/backend.go b/sdk/execution/backend.go index b8389617f..24f335f30 100644 --- a/sdk/execution/backend.go +++ b/sdk/execution/backend.go @@ -125,6 +125,7 @@ func (s *Backend) Create(request cosmostypes.Request, msg msgCreateExecution) (* if err != nil { return nil, err } + m.InProgress.Add(1) store.Set(exec.Hash, value) return exec, nil } @@ -159,6 +160,7 @@ func (s *Backend) Update(request cosmostypes.Request, msg msgUpdateExecution) (* if err != nil { return nil, err } + m.Completed.Add(1) store.Set(exec.Hash, value) return exec, nil } diff --git a/sdk/execution/metrics.go b/sdk/execution/metrics.go new file mode 100644 index 000000000..1e1ac8ea0 --- /dev/null +++ b/sdk/execution/metrics.go @@ -0,0 +1,56 @@ +package executionsdk + +import ( + "github.com/go-kit/kit/metrics" + prometheus "github.com/go-kit/kit/metrics/prometheus" + stdprometheus "github.com/prometheus/client_golang/prometheus" +) + +var m *metric + +type metric struct { + Created metrics.Counter + PreSigned metrics.Counter + Signed metrics.Counter + InProgress metrics.Counter + Completed metrics.Counter +} + +func newMetric() *metric { + return &metric{ + Created: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ + Namespace: "mesg", + Subsystem: "execution", + Name: "created", + Help: "executions created", + }, []string{}), + Signed: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ + Namespace: "mesg", + Subsystem: "execution", + Name: "signed", + Help: "executions signed", + }, []string{}), + PreSigned: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ + Namespace: "mesg", + Subsystem: "execution", + Name: "pre_signed", + Help: "executions pre signed", + }, []string{}), + InProgress: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ + Namespace: "mesg", + Subsystem: "execution", + Name: "in_progress", + Help: "executions in progress", + }, []string{}), + Completed: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ + Namespace: "mesg", + Subsystem: "execution", + Name: "completed", + Help: "executions completed", + }, []string{}), + } +} + +func init() { + m = newMetric() +} diff --git a/sdk/execution/sdk.go b/sdk/execution/sdk.go index a1b12f899..cc130b314 100644 --- a/sdk/execution/sdk.go +++ b/sdk/execution/sdk.go @@ -34,12 +34,15 @@ func New(client *cosmos.Client, serviceSDK *servicesdk.SDK, instanceSDK *instanc // Create creates a new execution. func (s *SDK) Create(req *api.CreateExecutionRequest) (*execution.Execution, error) { + m.Created.Add(1) acc, err := s.client.GetAccount() if err != nil { return nil, err } + m.PreSigned.Add(1) msg := newMsgCreateExecution(req, acc.GetAddress()) tx, err := s.client.BuildAndBroadcastMsg(msg) + m.Signed.Add(1) if err != nil { return nil, err } diff --git a/server/grpc/server.go b/server/grpc/server.go index 224f1578c..a9729ba29 100644 --- a/server/grpc/server.go +++ b/server/grpc/server.go @@ -7,6 +7,7 @@ import ( grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" "github.com/mesg-foundation/engine/config" protobuf_api "github.com/mesg-foundation/engine/protobuf/api" "github.com/mesg-foundation/engine/sdk" @@ -46,13 +47,16 @@ func (s *Server) Serve(address string) error { keepaliveOpt, grpc.StreamInterceptor(grpc_middleware.ChainStreamServer( grpc_logrus.StreamServerInterceptor(logrus.StandardLogger().WithField("module", "grpc")), + grpc_prometheus.StreamServerInterceptor, )), grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer( grpc_logrus.UnaryServerInterceptor(logrus.StandardLogger().WithField("module", "grpc")), + grpc_prometheus.UnaryServerInterceptor, validateInterceptor, )), ) s.register() + grpc_prometheus.Register(s.instance) logrus.WithField("module", "grpc").Info("server listens on ", ln.Addr()) return s.instance.Serve(ln) }