From 5f415002d302e34c6f79963a7f94336e9e578e6e Mon Sep 17 00:00:00 2001 From: krhubert Date: Thu, 19 Dec 2019 17:34:47 +0100 Subject: [PATCH 01/32] Customize cosmos config for mesg engine --- core/main.go | 3 +++ cosmos/config.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 cosmos/config.go diff --git a/core/main.go b/core/main.go index a3cfe3194..86995f715 100644 --- a/core/main.go +++ b/core/main.go @@ -132,6 +132,9 @@ 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) diff --git a/cosmos/config.go b/cosmos/config.go new file mode 100644 index 000000000..d15bcb6cc --- /dev/null +++ b/cosmos/config.go @@ -0,0 +1,47 @@ +package cosmos + +import sdktypes "github.com/cosmos/cosmos-sdk/types" + +const ( + // CoinType is a mesg coin type. + CoinType = 50000 + + // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address + Bech32MainPrefix = "mesgtest" + + // PrefixAccount is the prefix for account keys + PrefixAccount = "acc" + // PrefixValidator is the prefix for validator keys + PrefixValidator = "val" + // PrefixConsensus is the prefix for consensus keys + PrefixConsensus = "cons" + // PrefixPublic is the prefix for public keys + PrefixPublic = "pub" + // PrefixOperator is the prefix for operator keys + PrefixOperator = "oper" + + // PrefixAddress is the prefix for addresses + PrefixAddress = "addr" + + // 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 + PrefixPublic + // Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address + Bech32PrefixValAddr = Bech32MainPrefix + PrefixValidator + PrefixOperator + // Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key + Bech32PrefixValPub = Bech32MainPrefix + PrefixValidator + PrefixOperator + PrefixPublic + // Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address + Bech32PrefixConsAddr = Bech32MainPrefix + PrefixValidator + PrefixConsensus + // Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key + Bech32PrefixConsPub = Bech32MainPrefix + PrefixValidator + PrefixConsensus + PrefixPublic +) + +func CustomizeConfig() { + config := sdktypes.GetConfig() + config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) + config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub) + config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub) + config.SetCoinType(CoinType) + config.Seal() +} From 49f943a8c1525e13cc7b2d69f92a647dab2057af Mon Sep 17 00:00:00 2001 From: Anthony Date: Mon, 30 Dec 2019 12:10:30 +0700 Subject: [PATCH 02/32] Update cosmos/config.go --- cosmos/config.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cosmos/config.go b/cosmos/config.go index d15bcb6cc..598f15c0c 100644 --- a/cosmos/config.go +++ b/cosmos/config.go @@ -37,6 +37,7 @@ const ( Bech32PrefixConsPub = Bech32MainPrefix + PrefixValidator + PrefixConsensus + PrefixPublic ) +// CustomizeConfig customizes the cosmos application like addresses prefixes and coin type func CustomizeConfig() { config := sdktypes.GetConfig() config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) From 3f4ecd9ed451d42c183b892f24378d307f600cb9 Mon Sep 17 00:00:00 2001 From: Anthony Date: Mon, 30 Dec 2019 12:14:59 +0700 Subject: [PATCH 03/32] Update cosmos/config.go --- cosmos/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cosmos/config.go b/cosmos/config.go index 598f15c0c..484e7e11e 100644 --- a/cosmos/config.go +++ b/cosmos/config.go @@ -6,7 +6,7 @@ const ( // CoinType is a mesg coin type. CoinType = 50000 - // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address + // Bech32MainPrefix defines the main Bech32 prefix Bech32MainPrefix = "mesgtest" // PrefixAccount is the prefix for account keys From d11e6a29b4fe89a4d193000f364bb581ab208d7d Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Mon, 30 Dec 2019 12:40:39 +0700 Subject: [PATCH 04/32] Remove database config --- config/config.go | 14 -------------- config/config_test.go | 1 - 2 files changed, 15 deletions(-) diff --git a/config/config.go b/config/config.go index 3b417b1b1..76ae6706c 100644 --- a/config/config.go +++ b/config/config.go @@ -19,10 +19,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 +38,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"` @@ -87,10 +77,6 @@ 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" diff --git a/config/config_test.go b/config/config_test.go index 488ac781f..af51a7265 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -26,7 +26,6 @@ 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) From 59cbfb388e7d8c36a358c826b3657e7e88451699 Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Mon, 30 Dec 2019 13:06:21 +0700 Subject: [PATCH 05/32] add grpc to prometheus --- go.mod | 1 + go.sum | 1 + server/grpc/server.go | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/go.mod b/go.mod index 5fffe69f7..ce7ece132 100644 --- a/go.mod +++ b/go.mod @@ -28,6 +28,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 diff --git a/go.sum b/go.sum index 6a3a9a9e3..02ce75349 100644 --- a/go.sum +++ b/go.sum @@ -167,6 +167,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= 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) } From 2f824609426db99bfb6c06d09ff322944dc087e6 Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Fri, 3 Jan 2020 12:47:10 +0700 Subject: [PATCH 06/32] add execution stats --- go.mod | 3 ++- prometheus.yml | 13 +++++++++++ scripts/dev.sh | 2 ++ sdk/execution/backend.go | 2 ++ sdk/execution/metrics.go | 49 ++++++++++++++++++++++++++++++++++++++++ sdk/execution/sdk.go | 2 ++ 6 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 prometheus.yml create mode 100644 sdk/execution/metrics.go diff --git a/go.mod b/go.mod index ce7ece132..539629d48 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 @@ -45,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 diff --git a/prometheus.yml b/prometheus.yml new file mode 100644 index 000000000..20c0e5e2b --- /dev/null +++ b/prometheus.yml @@ -0,0 +1,13 @@ +global: + scrape_interval: 15s + evaluation_interval: 15s +scrape_configs: + - job_name: 'prometheus' + static_configs: + - targets: ['localhost:9090'] + - job_name: 'testnet' + scrape_interval: 15s + static_configs: + - targets: ['engine:26660'] + labels: + instance: 'engine' diff --git a/scripts/dev.sh b/scripts/dev.sh index 5bdf784bb..ac56dfea9 100755 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -61,6 +61,8 @@ function start_engine { --network name=$MESG_TENDERMINT_NETWORK \ --publish $MESG_SERVER_PORT:50052 \ --publish $MESG_TENDERMINT_PORT:26656 \ + --publish 26657:26657 \ + --publish 26660:26660 \ mesg/engine:local } 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..3e7e4e1b8 --- /dev/null +++ b/sdk/execution/metrics.go @@ -0,0 +1,49 @@ +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 + 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{}), + 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..5d431eea1 100644 --- a/sdk/execution/sdk.go +++ b/sdk/execution/sdk.go @@ -34,12 +34,14 @@ 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 } msg := newMsgCreateExecution(req, acc.GetAddress()) tx, err := s.client.BuildAndBroadcastMsg(msg) + m.Signed.Add(1) if err != nil { return nil, err } From 4f834e582411fc550c66b341fdbae096c65fd858 Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Fri, 3 Jan 2020 14:38:33 +0700 Subject: [PATCH 07/32] add pre sign metric --- sdk/execution/metrics.go | 7 +++++++ sdk/execution/sdk.go | 1 + 2 files changed, 8 insertions(+) diff --git a/sdk/execution/metrics.go b/sdk/execution/metrics.go index 3e7e4e1b8..1e1ac8ea0 100644 --- a/sdk/execution/metrics.go +++ b/sdk/execution/metrics.go @@ -10,6 +10,7 @@ var m *metric type metric struct { Created metrics.Counter + PreSigned metrics.Counter Signed metrics.Counter InProgress metrics.Counter Completed metrics.Counter @@ -29,6 +30,12 @@ func newMetric() *metric { 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", diff --git a/sdk/execution/sdk.go b/sdk/execution/sdk.go index 5d431eea1..cc130b314 100644 --- a/sdk/execution/sdk.go +++ b/sdk/execution/sdk.go @@ -39,6 +39,7 @@ func (s *SDK) Create(req *api.CreateExecutionRequest) (*execution.Execution, err 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) From 939d8b18e8e6c62ddc4f2ae90cb758c97ff2bc05 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Thu, 9 Jan 2020 17:57:45 +0700 Subject: [PATCH 08/32] Add supply module to order list of module to register --- sdk/backend.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/backend.go b/sdk/backend.go index d79343684..90386f9c4 100644 --- a/sdk/backend.go +++ b/sdk/backend.go @@ -151,6 +151,8 @@ func initDefaultCosmosModules(app *cosmos.AppFactory) { auth.ModuleName, bank.ModuleName, slashing.ModuleName, + supply.ModuleName, + // TODO: the app's module should be here!! genutil.ModuleName, ) } From a558d3cfa36172062b4a2bd7f1e2fbaa6376cebd Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Thu, 9 Jan 2020 17:58:39 +0700 Subject: [PATCH 09/32] Improve module account addresses stuff --- sdk/backend.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/sdk/backend.go b/sdk/backend.go index 90386f9c4..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, From 146147a4308d6abdd89e68664eafc5329d8bfaba Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Mon, 13 Jan 2020 10:43:34 +0700 Subject: [PATCH 10/32] remove prometheus config --- prometheus.yml | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 prometheus.yml diff --git a/prometheus.yml b/prometheus.yml deleted file mode 100644 index 20c0e5e2b..000000000 --- a/prometheus.yml +++ /dev/null @@ -1,13 +0,0 @@ -global: - scrape_interval: 15s - evaluation_interval: 15s -scrape_configs: - - job_name: 'prometheus' - static_configs: - - targets: ['localhost:9090'] - - job_name: 'testnet' - scrape_interval: 15s - static_configs: - - targets: ['engine:26660'] - labels: - instance: 'engine' From a82642c915486d64c55598271634ea177517f4cf Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Fri, 10 Jan 2020 18:40:52 +0700 Subject: [PATCH 11/32] Output engine account address in log --- core/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/core/main.go b/core/main.go index 86995f715..5b1540e59 100644 --- a/core/main.go +++ b/core/main.go @@ -159,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) From 865f211a3765401e90a07bf4e9ed13dae17556bb Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Fri, 10 Jan 2020 18:52:04 +0700 Subject: [PATCH 12/32] Add 2 new CLI. One to use to interact with cosmos modules. One for managing the genesis and tendermint. Remove now useless gen-genesis tool. --- cmd/mesg-cosmos-daemon/main.go | 111 +++++++++++++ cmd/mesg-cosmos/main.go | 255 +++++++++++++++++++++++++++++ cosmos/app.go | 5 + go.mod | 7 +- go.sum | 21 +++ internal/tools/gen-genesis/main.go | 130 --------------- 6 files changed, 395 insertions(+), 134 deletions(-) create mode 100644 cmd/mesg-cosmos-daemon/main.go create mode 100644 cmd/mesg-cosmos/main.go delete mode 100644 internal/tools/gen-genesis/main.go diff --git a/cmd/mesg-cosmos-daemon/main.go b/cmd/mesg-cosmos-daemon/main.go new file mode 100644 index 000000000..0f60af617 --- /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) + 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..971221bea --- /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) + 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/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/go.mod b/go.mod index 539629d48..b1b0d1da3 100644 --- a/go.mod +++ b/go.mod @@ -54,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 02ce75349..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= @@ -187,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= @@ -301,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= @@ -324,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= @@ -337,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= @@ -346,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= @@ -436,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= @@ -470,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= @@ -478,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) -} From c2e7c8fe9b989c9be0afe2446b0acbbe1b5fde38 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Fri, 10 Jan 2020 18:53:14 +0700 Subject: [PATCH 13/32] public tendermint rpc port in dev script --- scripts/dev.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/dev.sh b/scripts/dev.sh index ac56dfea9..a600e3c7d 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,8 +63,8 @@ function start_engine { --network name=$MESG_TENDERMINT_NETWORK \ --publish $MESG_SERVER_PORT:50052 \ --publish $MESG_TENDERMINT_PORT:26656 \ - --publish 26657:26657 \ - --publish 26660:26660 \ + --publish $MESG_TENDERMINT_RPC_PORT:26657 \ + --publish $MESG_PROMETHEUS_RPC_PORT:26660 \ mesg/engine:local } From 217723d4904cc2643930fbb5975912e33fc341f6 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Mon, 13 Jan 2020 11:30:24 +0700 Subject: [PATCH 14/32] add build cmd command to makefile --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 From cfa8eade4a7f70fc083d1236f0deb08d04d9fcd4 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Mon, 13 Jan 2020 12:01:31 +0700 Subject: [PATCH 15/32] Add min gas price to config --- config/config.go | 13 ++++++++++--- config/config_test.go | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 76ae6706c..0465c47d7 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" @@ -45,6 +46,7 @@ type Config struct { Cosmos struct { RelativePath string `validate:"required"` + MinGasPrices string `validate:"required"` } DevGenesis struct { @@ -87,6 +89,7 @@ func defaultConfig() (*Config, error) { c.Tendermint.Config.Instrumentation.PrometheusListenAddr = "0.0.0.0:26660" c.Cosmos.RelativePath = "cosmos" + c.Cosmos.MinGasPrices = "1.0mesg" c.DevGenesis.ChainID = "mesg-dev-chain" @@ -156,13 +159,17 @@ 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) } return validator.New().Struct(c) diff --git a/config/config_test.go b/config/config_test.go index af51a7265..acd90ea2c 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -60,6 +60,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.0mesg tendermint: config: consensus: @@ -74,5 +76,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.0mesg", c.Cosmos.MinGasPrices) }) } From 2b85941ff012da6237a1c26822b7974388b67fec Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Mon, 13 Jan 2020 12:03:42 +0700 Subject: [PATCH 16/32] Pass min gas price from config to cosmos app --- core/main.go | 2 +- cosmos/appfactory.go | 4 ++-- internal/tools/gen-genesis/main.go | 8 +++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/core/main.go b/core/main.go index 86995f715..0bcc7389c 100644 --- a/core/main.go +++ b/core/main.go @@ -136,7 +136,7 @@ func main() { 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 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/internal/tools/gen-genesis/main.go b/internal/tools/gen-genesis/main.go index 342c07d08..09468eb48 100644 --- a/internal/tools/gen-genesis/main.go +++ b/internal/tools/gen-genesis/main.go @@ -11,6 +11,7 @@ import ( "strings" "time" + enginecfg "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" @@ -55,7 +56,12 @@ func main() { if err != nil { logrus.Fatalln(err) } - appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db) + + ecfg, err := enginecfg.New() + if err != nil { + logrus.Fatalln(err) + } + appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db, ecfg.Cosmos.MinGasPrices) // register the backend modules to the app factory. enginesdk.NewBackend(appFactory) From 53468cb0de2b45f1e22d995182f5ef9d506922b9 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Mon, 13 Jan 2020 12:44:06 +0700 Subject: [PATCH 17/32] Pass min gas price to txbuilder --- core/main.go | 5 +++-- cosmos/client.go | 30 +++++++++++++++++++----------- cosmos/genesis.go | 15 ++++++++++----- cosmos/genesis_test.go | 3 ++- cosmos/txbuilder.go | 6 +++--- 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/core/main.go b/core/main.go index 0bcc7389c..8e9489b2c 100644 --- a/core/main.go +++ b/core/main.go @@ -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.Cosmos.MinGasPrices, cfg.Tendermint.Config.GenesisFile(), []cosmos.GenesisValidator{validator}) } func main() { @@ -159,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) @@ -173,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/client.go b/cosmos/client.go index 60c3a34ee..1e32977bb 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, } } @@ -204,7 +207,12 @@ 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(sequence, c.kb, c.chainID, minGasPrices) signedTx, err := txBuilder.BuildAndSignStdTx(msg, c.accName, c.accPassword) if err != nil { return nil, err diff --git a/cosmos/genesis.go b/cosmos/genesis.go index 5d911de3d..013555864 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, minGasPrices, genesisFile string, validators []GenesisValidator) (*tmtypes.GenesisDoc, error) { msgs := []sdktypes.Msg{} for _, validator := range validators { // get account @@ -66,7 +66,7 @@ func GenGenesis(kb *Keybase, defaultGenesisŚtate map[string]json.RawMessage, ch } // generate genesis transaction sequence := uint64(0) - b := NewTxBuilder(sequence, kb, chainID) + b := NewTxBuilder(sequence, kb, chainID, sdktypes.DecCoins{}) signedMsg, err := b.BuildSignMsg(msgs) if err != nil { return nil, err @@ -79,7 +79,11 @@ func GenGenesis(kb *Keybase, defaultGenesisŚtate map[string]json.RawMessage, ch } } // generate genesis - appState, err := genGenesisAppState(defaultGenesisŚtate, validatorTx) + minGasPricesP, err := sdktypes.ParseDecCoins(minGasPrices) + if err != nil { + return nil, err + } + appState, err := genGenesisAppState(defaultGenesisŚtate, validatorTx, minGasPricesP) if err != nil { return nil, err } @@ -108,11 +112,12 @@ 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, minGasPrices sdktypes.DecCoins) (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, "", "") + gasCoins, _ := minGasPrices.MulDec(sdktypes.NewDec(1000000000)).TruncateDecimal() + genAcc := genaccounts.NewGenesisAccountRaw(signer, gasCoins.Add(sdktypes.NewCoins(stakes)), 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..7299e8b63 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" + minGasPrices = "1.0mesg" name = "name" password = "pass" privValidatorKeyFile = filepath.Join(path, "privValidatorKeyFile.json") @@ -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, minGasPrices, genesisPath, validators) require.NoError(t, err) require.NotEmpty(t, genesis) }) diff --git a/cosmos/txbuilder.go b/cosmos/txbuilder.go index 143478732..b0af831bc 100644 --- a/cosmos/txbuilder.go +++ b/cosmos/txbuilder.go @@ -16,19 +16,19 @@ type TxBuilder struct { } // NewTxBuilder returns a new initialized TxBuilder. -func NewTxBuilder(accSeq uint64, kb keys.Keybase, chainID string) TxBuilder { +func NewTxBuilder(accSeq uint64, kb keys.Keybase, chainID string, minGasPrices sdktypes.DecCoins) TxBuilder { return TxBuilder{ authtypes.NewTxBuilder( authutils.GetTxEncoder(codec.Codec), AccNumber, accSeq, - 1000000, + flags.DefaultGasLimit, flags.DefaultGasAdjustment, true, chainID, "", sdktypes.NewCoins(), - sdktypes.DecCoins{}, + minGasPrices, ).WithKeybase(kb), } } From afdf9146720a1f502f3d2cf27162d6a27f12b21a Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Mon, 13 Jan 2020 12:44:31 +0700 Subject: [PATCH 18/32] Estimate the tx gas by simulating it. --- cosmos/client.go | 14 ++++++++++++++ cosmos/txbuilder.go | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/cosmos/client.go b/cosmos/client.go index 1e32977bb..877a4f909 100644 --- a/cosmos/client.go +++ b/cosmos/client.go @@ -213,6 +213,20 @@ func (c *Client) sign(msg sdktypes.Msg) (tenderminttypes.Tx, error) { } txBuilder := NewTxBuilder(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/txbuilder.go b/cosmos/txbuilder.go index b0af831bc..85c016d11 100644 --- a/cosmos/txbuilder.go +++ b/cosmos/txbuilder.go @@ -33,6 +33,12 @@ func NewTxBuilder(accSeq uint64, kb keys.Keybase, chainID string, minGasPrices s } } +// 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}) From d428cd9336a11897344c27aded701ebf4c1762ae Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Mon, 13 Jan 2020 12:58:21 +0700 Subject: [PATCH 19/32] fix config test --- config/config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config_test.go b/config/config_test.go index acd90ea2c..30f8509a2 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -61,7 +61,7 @@ log: 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.0mesg + mingasprices: 2.0mesg tendermint: config: consensus: From 7a75349205462a116ee4dd5863ec4a572d13282e Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Mon, 13 Jan 2020 13:10:27 +0700 Subject: [PATCH 20/32] fix gen-genesis script --- internal/tools/gen-genesis/main.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/tools/gen-genesis/main.go b/internal/tools/gen-genesis/main.go index 09468eb48..3295ea68b 100644 --- a/internal/tools/gen-genesis/main.go +++ b/internal/tools/gen-genesis/main.go @@ -31,9 +31,10 @@ func randompassword() string { } 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") + validators = flag.String("validators", "engine", "list of validator names separated with a comma") + chainid = flag.String("chain-id", "mesg-chain", "chain id") + minGasPrices = flag.String("minGasPrices", "1.0mesg", "min gas price") + path = flag.String("path", ".genesis/", "genesis folder path") ) const ( @@ -122,7 +123,7 @@ func main() { } // generate and save genesis - _, err = cosmos.GenGenesis(kb, app.DefaultGenesis(), *chainid, filepath.Join(*path, "genesis.json"), vals) + _, err = cosmos.GenGenesis(kb, app.DefaultGenesis(), *chainid, *minGasPrices, filepath.Join(*path, "genesis.json"), vals) if err != nil { logrus.Fatalln(err) } From e125b7a0a60689074d8689f16702014c370e14bd Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Mon, 13 Jan 2020 13:14:20 +0700 Subject: [PATCH 21/32] Set default min gas fee to 1attomesg --- config/config.go | 2 +- config/config_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 0465c47d7..3ccaf76fa 100644 --- a/config/config.go +++ b/config/config.go @@ -89,7 +89,7 @@ func defaultConfig() (*Config, error) { c.Tendermint.Config.Instrumentation.PrometheusListenAddr = "0.0.0.0:26660" c.Cosmos.RelativePath = "cosmos" - c.Cosmos.MinGasPrices = "1.0mesg" + c.Cosmos.MinGasPrices = "0.000000000000000001mesg" c.DevGenesis.ChainID = "mesg-dev-chain" diff --git a/config/config_test.go b/config/config_test.go index 30f8509a2..637f4fcdd 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -61,7 +61,7 @@ log: 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.0mesg + mingasprices: 2.0019294mesg tendermint: config: consensus: @@ -76,6 +76,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.0mesg", c.Cosmos.MinGasPrices) + require.Equal(t, "2.0019294mesg", c.Cosmos.MinGasPrices) }) } From 2ccd096262bcdb55ee766ebb067020c074160e26 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Mon, 13 Jan 2020 17:05:18 +0700 Subject: [PATCH 22/32] Switch to amesg denomination. Set gas fee to 1.0amesg. Add new dev genesis's initial balance parameter to config to give an initial balance. --- config/config.go | 11 +++++++---- core/main.go | 2 +- cosmos/genesis.go | 17 ++++++++--------- cosmos/genesis_test.go | 4 ++-- internal/tools/gen-genesis/main.go | 12 ++++++------ scripts/dev.sh | 2 +- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/config/config.go b/config/config.go index 3ccaf76fa..70c81477a 100644 --- a/config/config.go +++ b/config/config.go @@ -50,7 +50,8 @@ type Config struct { } DevGenesis struct { - ChainID string `validate:"required"` + ChainID string `validate:"required"` + InitialBalances string `validate:"required"` } Account struct { @@ -89,9 +90,10 @@ func defaultConfig() (*Config, error) { c.Tendermint.Config.Instrumentation.PrometheusListenAddr = "0.0.0.0:26660" c.Cosmos.RelativePath = "cosmos" - c.Cosmos.MinGasPrices = "0.000000000000000001mesg" + c.Cosmos.MinGasPrices = "1.0amesg" c.DevGenesis.ChainID = "mesg-dev-chain" + c.DevGenesis.InitialBalances = "1000000000000000000000000amesg" // 1 000 000 * 10^18 c.Account.Name = "engine" c.Account.Password = "pass" @@ -167,10 +169,11 @@ func (c *Config) validate() error { if err := c.Tendermint.Config.ValidateBasic(); err != nil { 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/core/main.go b/core/main.go index 8e9489b2c..0c48866b0 100644 --- a/core/main.go +++ b/core/main.go @@ -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.Cosmos.MinGasPrices, 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() { diff --git a/cosmos/genesis.go b/cosmos/genesis.go index 013555864..793926a44 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, minGasPrices, 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 @@ -79,11 +79,7 @@ func GenGenesis(kb *Keybase, defaultGenesisŚtate map[string]json.RawMessage, ch } } // generate genesis - minGasPricesP, err := sdktypes.ParseDecCoins(minGasPrices) - if err != nil { - return nil, err - } - appState, err := genGenesisAppState(defaultGenesisŚtate, validatorTx, minGasPricesP) + appState, err := genGenesisAppState(defaultGenesisŚtate, validatorTx, initialBalances) if err != nil { return nil, err } @@ -112,12 +108,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, minGasPrices sdktypes.DecCoins) (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)) - gasCoins, _ := minGasPrices.MulDec(sdktypes.NewDec(1000000000)).TruncateDecimal() - genAcc := genaccounts.NewGenesisAccountRaw(signer, gasCoins.Add(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 7299e8b63..dfb2dd4d6 100644 --- a/cosmos/genesis_test.go +++ b/cosmos/genesis_test.go @@ -28,7 +28,7 @@ func TestGenesis(t *testing.T) { // variables var ( chainID = "test-chainID" - minGasPrices = "1.0mesg" + initialBalances = "1.0amesg" name = "name" password = "pass" privValidatorKeyFile = filepath.Join(path, "privValidatorKeyFile.json") @@ -58,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, minGasPrices, genesisPath, validators) + genesis, err := GenGenesis(kb, defaultGenesisState, chainID, initialBalances, genesisPath, validators) require.NoError(t, err) require.NotEmpty(t, genesis) }) diff --git a/internal/tools/gen-genesis/main.go b/internal/tools/gen-genesis/main.go index 3295ea68b..ec38e6c85 100644 --- a/internal/tools/gen-genesis/main.go +++ b/internal/tools/gen-genesis/main.go @@ -31,10 +31,10 @@ func randompassword() string { } var ( - validators = flag.String("validators", "engine", "list of validator names separated with a comma") - chainid = flag.String("chain-id", "mesg-chain", "chain id") - minGasPrices = flag.String("minGasPrices", "1.0mesg", "min gas price") - path = flag.String("path", ".genesis/", "genesis folder path") + validators = flag.String("validators", "engine", "list of validator names separated with a comma") + chainid = flag.String("chain-id", "mesg-chain", "chain id") + initialBalances = flag.String("initialBalances", "1000000000amesg", "min gas price") + path = flag.String("path", ".genesis/", "genesis folder path") ) const ( @@ -62,7 +62,7 @@ func main() { if err != nil { logrus.Fatalln(err) } - appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db, ecfg.Cosmos.MinGasPrices) + appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db, ecfg.Cosmos.initialBalances) // register the backend modules to the app factory. enginesdk.NewBackend(appFactory) @@ -123,7 +123,7 @@ func main() { } // generate and save genesis - _, err = cosmos.GenGenesis(kb, app.DefaultGenesis(), *chainid, *minGasPrices, filepath.Join(*path, "genesis.json"), vals) + _, err = cosmos.GenGenesis(kb, app.DefaultGenesis(), *chainid, *initialBalances, filepath.Join(*path, "genesis.json"), vals) if err != nil { logrus.Fatalln(err) } diff --git a/scripts/dev.sh b/scripts/dev.sh index ac56dfea9..0f07e59ba 100755 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -92,7 +92,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) From 2031140ca403040c00c821bff19ec8fb2615e1a9 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Mon, 13 Jan 2020 17:07:20 +0700 Subject: [PATCH 23/32] fix genesis test --- cosmos/genesis_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cosmos/genesis_test.go b/cosmos/genesis_test.go index dfb2dd4d6..0d38a1900 100644 --- a/cosmos/genesis_test.go +++ b/cosmos/genesis_test.go @@ -28,7 +28,7 @@ func TestGenesis(t *testing.T) { // variables var ( chainID = "test-chainID" - initialBalances = "1.0amesg" + initialBalances = "100amesg" name = "name" password = "pass" privValidatorKeyFile = filepath.Join(path, "privValidatorKeyFile.json") From 34d8d1f4ebfba17a72f67fefeb87f71b827f07a3 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Mon, 13 Jan 2020 17:11:28 +0700 Subject: [PATCH 24/32] fix merge --- cmd/mesg-cosmos-daemon/main.go | 2 +- cmd/mesg-cosmos/main.go | 2 +- internal/tools/gen-genesis/main.go | 137 ----------------------------- 3 files changed, 2 insertions(+), 139 deletions(-) delete mode 100644 internal/tools/gen-genesis/main.go diff --git a/cmd/mesg-cosmos-daemon/main.go b/cmd/mesg-cosmos-daemon/main.go index 0f60af617..8d9a09fcf 100644 --- a/cmd/mesg-cosmos-daemon/main.go +++ b/cmd/mesg-cosmos-daemon/main.go @@ -41,7 +41,7 @@ func main() { if err != nil { panic(err) } - appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db) + appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db, cfg.Cosmos.MinGasPrices) enginesdk.NewBackend(appFactory) app, err = cosmos.NewApp(appFactory) if err != nil { diff --git a/cmd/mesg-cosmos/main.go b/cmd/mesg-cosmos/main.go index 971221bea..f778659b8 100644 --- a/cmd/mesg-cosmos/main.go +++ b/cmd/mesg-cosmos/main.go @@ -39,7 +39,7 @@ func main() { if err != nil { panic(err) } - appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db) + appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db, cfg.Cosmos.MinGasPrices) enginesdk.NewBackend(appFactory) app, err = cosmos.NewApp(appFactory) if err != nil { diff --git a/internal/tools/gen-genesis/main.go b/internal/tools/gen-genesis/main.go deleted file mode 100644 index ec38e6c85..000000000 --- a/internal/tools/gen-genesis/main.go +++ /dev/null @@ -1,137 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "io/ioutil" - "log" - "math/rand" - "os" - "path/filepath" - "strings" - "time" - - enginecfg "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/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") - initialBalances = flag.String("initialBalances", "1000000000amesg", "min gas price") - 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) - } - - ecfg, err := enginecfg.New() - if err != nil { - logrus.Fatalln(err) - } - appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db, ecfg.Cosmos.initialBalances) - - // 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, *initialBalances, 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) -} From 720f73b46d77c0e26dc7a2ef8d6275fd1f019de2 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Mon, 13 Jan 2020 17:42:41 +0700 Subject: [PATCH 25/32] fix error with account number by fetching it from the cosmos account and not the keybase --- cosmos/client.go | 4 ++-- cosmos/genesis.go | 3 ++- cosmos/txbuilder.go | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cosmos/client.go b/cosmos/client.go index 877a4f909..e87833eb4 100644 --- a/cosmos/client.go +++ b/cosmos/client.go @@ -182,7 +182,7 @@ func (c *Client) GetAccount() (auth.Account, error) { accKb.GetAddress(), nil, accKb.GetPubKey(), - AccNumber, + 0, 0, ) } @@ -212,7 +212,7 @@ func (c *Client) sign(msg sdktypes.Msg) (tenderminttypes.Tx, error) { return nil, err } - txBuilder := NewTxBuilder(sequence, c.kb, c.chainID, minGasPrices) + txBuilder := NewTxBuilder(acc.GetAccountNumber(), sequence, c.kb, c.chainID, minGasPrices) // simulate tx to estimate the gas if txBuilder.SimulateAndExecute() { diff --git a/cosmos/genesis.go b/cosmos/genesis.go index 793926a44..9d254e015 100644 --- a/cosmos/genesis.go +++ b/cosmos/genesis.go @@ -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, sdktypes.DecCoins{}) + b := NewTxBuilder(accNumber, sequence, kb, chainID, sdktypes.DecCoins{}) signedMsg, err := b.BuildSignMsg(msgs) if err != nil { return nil, err diff --git a/cosmos/txbuilder.go b/cosmos/txbuilder.go index 85c016d11..40f418f38 100644 --- a/cosmos/txbuilder.go +++ b/cosmos/txbuilder.go @@ -16,11 +16,11 @@ type TxBuilder struct { } // NewTxBuilder returns a new initialized TxBuilder. -func NewTxBuilder(accSeq uint64, kb keys.Keybase, chainID string, minGasPrices sdktypes.DecCoins) 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, flags.DefaultGasLimit, flags.DefaultGasAdjustment, From 673f10b4c35f75edf017e87dd29c7d7326479b9a Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Mon, 13 Jan 2020 17:45:39 +0700 Subject: [PATCH 26/32] Simplify logic around account retriever --- cosmos/client.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cosmos/client.go b/cosmos/client.go index e87833eb4..01e582528 100644 --- a/cosmos/client.go +++ b/cosmos/client.go @@ -187,12 +187,14 @@ func (c *Client) GetAccount() (auth.Account, error) { ) } 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 } From 942c576d452d8d9a7ac0b3062eb538b74f3c62b1 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Mon, 13 Jan 2020 17:52:29 +0700 Subject: [PATCH 27/32] Only copy /bin/engine to docker build --- .dockerignore | 4 ++++ 1 file changed, 4 insertions(+) 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 From de95cddf55c0aa9ecf5f71faa4d902a3e82abf07 Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Mon, 13 Jan 2020 21:55:32 +0700 Subject: [PATCH 28/32] move AccNumber and AccIndex to config --- config/config.go | 4 ++++ config/config_test.go | 2 ++ core/main.go | 4 ++-- cosmos/genesis_test.go | 2 +- cosmos/keybase.go | 9 +-------- cosmos/keybase_test.go | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/config/config.go b/config/config.go index 70c81477a..823866ea7 100644 --- a/config/config.go +++ b/config/config.go @@ -57,6 +57,8 @@ type Config struct { Account struct { Name string `validate:"required"` Password string `validate:"required"` + Number uint32 + Index uint32 Mnemonic string } } @@ -97,6 +99,8 @@ func defaultConfig() (*Config, error) { c.Account.Name = "engine" c.Account.Password = "pass" + c.Account.Number = uint32(0) + c.Account.Index = uint32(0) return &c, nil } diff --git a/config/config_test.go b/config/config_test.go index 637f4fcdd..0399b45d9 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -29,6 +29,8 @@ func TestDefaultConfig(t *testing.T) { 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) { diff --git a/core/main.go b/core/main.go index 0c48866b0..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) { diff --git a/cosmos/genesis_test.go b/cosmos/genesis_test.go index 0d38a1900..772ce8b2b 100644 --- a/cosmos/genesis_test.go +++ b/cosmos/genesis_test.go @@ -40,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) 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()) }) From 08076e035019440e05f55a639bbdf826e63da7ad Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Tue, 14 Jan 2020 11:55:15 +0700 Subject: [PATCH 29/32] Change block time to 5sec (keep 1sec in e2e test). Change token name to atto. --- config/config.go | 6 +++--- e2e/testdata/e2e.config.yml | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 70c81477a..18f7e6f4c 100644 --- a/config/config.go +++ b/config/config.go @@ -85,15 +85,15 @@ func defaultConfig() (*Config, error) { 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.0amesg" + c.Cosmos.MinGasPrices = "1.0atto" c.DevGenesis.ChainID = "mesg-dev-chain" - c.DevGenesis.InitialBalances = "1000000000000000000000000amesg" // 1 000 000 * 10^18 + c.DevGenesis.InitialBalances = "1000000000000000000000000atto" // 1 000 000 * 10^18 c.Account.Name = "engine" c.Account.Password = "pass" 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 From 6b07b746748d39cbd44e40f1d5e6a74c95f01af4 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Tue, 14 Jan 2020 16:59:01 +0700 Subject: [PATCH 30/32] Change the mesg coin type to the registered one (470). Simplify the prefix by reusing cosmos's ones. Update FundraiserPath. --- cosmos/config.go | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/cosmos/config.go b/cosmos/config.go index 484e7e11e..c5c4f0aa9 100644 --- a/cosmos/config.go +++ b/cosmos/config.go @@ -2,39 +2,30 @@ package cosmos import sdktypes "github.com/cosmos/cosmos-sdk/types" +// See github.com/cosmos/cosmos-sdk/types/address.go const ( - // CoinType is a mesg coin type. - CoinType = 50000 - // Bech32MainPrefix defines the main Bech32 prefix Bech32MainPrefix = "mesgtest" - // PrefixAccount is the prefix for account keys - PrefixAccount = "acc" - // PrefixValidator is the prefix for validator keys - PrefixValidator = "val" - // PrefixConsensus is the prefix for consensus keys - PrefixConsensus = "cons" - // PrefixPublic is the prefix for public keys - PrefixPublic = "pub" - // PrefixOperator is the prefix for operator keys - PrefixOperator = "oper" + // CoinType is the mesg registered coin type from https://github.com/satoshilabs/slips/blob/master/slip-0044.md. + CoinType = 470 - // PrefixAddress is the prefix for addresses - PrefixAddress = "addr" + // 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 + PrefixPublic + Bech32PrefixAccPub = Bech32MainPrefix + sdktypes.PrefixPublic // Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address - Bech32PrefixValAddr = Bech32MainPrefix + PrefixValidator + PrefixOperator + Bech32PrefixValAddr = Bech32MainPrefix + sdktypes.PrefixValidator + sdktypes.PrefixOperator // Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key - Bech32PrefixValPub = Bech32MainPrefix + PrefixValidator + PrefixOperator + PrefixPublic + Bech32PrefixValPub = Bech32MainPrefix + sdktypes.PrefixValidator + sdktypes.PrefixOperator + sdktypes.PrefixPublic // Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address - Bech32PrefixConsAddr = Bech32MainPrefix + PrefixValidator + PrefixConsensus + Bech32PrefixConsAddr = Bech32MainPrefix + sdktypes.PrefixValidator + sdktypes.PrefixConsensus // Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key - Bech32PrefixConsPub = Bech32MainPrefix + PrefixValidator + PrefixConsensus + PrefixPublic + Bech32PrefixConsPub = Bech32MainPrefix + sdktypes.PrefixValidator + sdktypes.PrefixConsensus + sdktypes.PrefixPublic ) // CustomizeConfig customizes the cosmos application like addresses prefixes and coin type @@ -43,6 +34,7 @@ func CustomizeConfig() { config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub) config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub) + config.SetFullFundraiserPath(FullFundraiserPath) config.SetCoinType(CoinType) config.Seal() } From 9480e35253a0756ce54e3ca0c06bf08c7e78cb5d Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Tue, 14 Jan 2020 17:08:54 +0700 Subject: [PATCH 31/32] update changelog with v0.18.1 modifs --- CHANGELOG.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69e951529..9a729b13d 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 + +- ([#1553](https://github.com/mesg-foundation/engine/pull/1553)) Add fees and estimation of tx's gas. +- ([#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. + +#### 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 From 14da9883ba4e5e93cf0453974c5dc6b19cab494e Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 14 Jan 2020 18:05:26 +0700 Subject: [PATCH 32/32] Apply suggestions from code review --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a729b13d..6d98c1db5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,6 @@ #### Added -- ([#1553](https://github.com/mesg-foundation/engine/pull/1553)) Add fees and estimation of tx's gas. - ([#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. @@ -18,6 +17,7 @@ - ([#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