From 62f00937a6fd7ade7b13eb3bf0f68a5b05f98e0b Mon Sep 17 00:00:00 2001 From: Xiong <xixiongchen@thestratos.org> Date: Fri, 9 Dec 2022 17:03:59 -0500 Subject: [PATCH 1/3] add default value & minimal value restriction of minimum-gas-prices on app.toml --- cmd/stchaind/root.go | 25 ++++++++++++++++++++++++- server/config/config.go | 20 ++++++++++++++++++-- server/start.go | 2 +- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/cmd/stchaind/root.go b/cmd/stchaind/root.go index 56e22a49..1a18d931 100644 --- a/cmd/stchaind/root.go +++ b/cmd/stchaind/root.go @@ -2,6 +2,7 @@ package main import ( "errors" + "fmt" "io" "os" "path/filepath" @@ -227,7 +228,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a a.encCfg, appOpts, baseapp.SetPruning(pruningOpts), - baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(sdkserver.FlagMinGasPrices))), + baseapp.SetMinGasPrices(checkMinGasPrices(appOpts, logger)), baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(sdkserver.FlagHaltHeight))), baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(sdkserver.FlagHaltTime))), baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(sdkserver.FlagMinRetainBlocks))), @@ -240,6 +241,28 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a ) } +func checkMinGasPrices(appOpts servertypes.AppOptions, logger log.Logger) string { + minGasPricesInputStr := cast.ToString(appOpts.Get(sdkserver.FlagMinGasPrices)) + minGasPricesInput, err := sdk.ParseCoinNormalized(minGasPricesInputStr) + if err != nil { + panic(err) + } + + minimalMinGasPricesStr := servercfg.GetMinimalMinGasPricesCoinStr() + minimalMinGasPrices, err := sdk.ParseCoinNormalized(minimalMinGasPricesStr) + if err != nil { + panic(err) + } + + if minGasPricesInput.IsLT(minimalMinGasPrices) { + logger.Info(fmt.Sprintf("min-gas-prices %v is less than minimal value %v, set to default %v", + minGasPricesInputStr, minimalMinGasPricesStr, servercfg.GetDefaultMinGasPricesCoinStr())) + return servercfg.GetDefaultMinGasPricesCoinStr() + } + + return minGasPricesInput.String() +} + // appExport creates a new simapp (optionally at a given height) // and exports state. func (a appCreator) appExport( diff --git a/server/config/config.go b/server/config/config.go index c1e2e323..30fdb4ed 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -4,9 +4,11 @@ import ( "errors" "fmt" "path" + "strconv" "time" "github.com/spf13/viper" + stratos "github.com/stratosnet/stratos-chain/types" "github.com/tendermint/tendermint/libs/strings" @@ -46,6 +48,12 @@ const ( DefaultHTTPTimeout = 30 * time.Second DefaultHTTPIdleTimeout = 120 * time.Second + + // default 1000000000wei = 1gwei + DefaultMinGasPrices uint64 = 1e9 + + // 1000000wei = 0.01gwei + MinimalMinGasPrices uint64 = 1e6 ) var evmTracers = []string{"json", "markdown", "struct", "access_list"} @@ -125,9 +133,9 @@ func AppConfig(denom string) (string, interface{}) { // - if you set srvCfg.MinGasPrices non-empty, validators CAN tweak their // own app.toml to override, or use this default value. // - // In stratos, we set the min gas prices to 0. + // In stratos, we set the min gas prices to 0.01gwei. if denom != "" { - srvCfg.MinGasPrices = "0" + denom + srvCfg.MinGasPrices = strconv.FormatUint(DefaultMinGasPrices, 10) + denom } customAppConfig := Config{ @@ -331,3 +339,11 @@ func (c Config) ValidateBasic() error { return c.Config.ValidateBasic() } + +func GetDefaultMinGasPricesCoinStr() string { + return strconv.FormatUint(DefaultMinGasPrices, 10) + stratos.Wei +} + +func GetMinimalMinGasPricesCoinStr() string { + return strconv.FormatUint(MinimalMinGasPrices, 10) + stratos.Wei +} diff --git a/server/start.go b/server/start.go index 0ea7f657..61042afd 100644 --- a/server/start.go +++ b/server/start.go @@ -128,7 +128,7 @@ which accepts a path for the resulting pprof file. cmd.Flags().String(srvflags.Address, "tcp://0.0.0.0:26658", "Listen address") cmd.Flags().String(srvflags.Transport, "socket", "Transport protocol: socket, grpc") cmd.Flags().String(srvflags.TraceStore, "", "Enable KVStore tracing to an output file") - cmd.Flags().String(server.FlagMinGasPrices, "", "Minimum gas prices to accept for transactions; Any fee in a tx must meet this minimum (e.g. 0.01stos)") + cmd.Flags().String(server.FlagMinGasPrices, config.GetDefaultMinGasPricesCoinStr(), "Minimum gas prices to accept for transactions; Any fee in a tx must meet this minimum (e.g. 0.01stos)") cmd.Flags().IntSlice(server.FlagUnsafeSkipUpgrades, []int{}, "Skip a set of upgrade heights to continue the old binary") cmd.Flags().Uint64(server.FlagHaltHeight, 0, "Block height at which to gracefully halt the chain and shutdown the node") cmd.Flags().Uint64(server.FlagHaltTime, 0, "Minimum block time (in Unix seconds) at which to gracefully halt the chain and shutdown the node") From b5cc945bb62766a6b9510e6f7b81e0061ad86fdd Mon Sep 17 00:00:00 2001 From: Xiong <xixiongchen@thestratos.org> Date: Fri, 9 Dec 2022 17:16:54 -0500 Subject: [PATCH 2/3] update MinimalMinGasPrices value --- server/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/config/config.go b/server/config/config.go index 30fdb4ed..d153ccc1 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -53,7 +53,7 @@ const ( DefaultMinGasPrices uint64 = 1e9 // 1000000wei = 0.01gwei - MinimalMinGasPrices uint64 = 1e6 + MinimalMinGasPrices uint64 = 1e7 ) var evmTracers = []string{"json", "markdown", "struct", "access_list"} From c639d4e3e0e42d0e55456d2e212fdcd978a7d462 Mon Sep 17 00:00:00 2001 From: Xiong <xixiongchen@thestratos.org> Date: Fri, 9 Dec 2022 20:21:11 -0500 Subject: [PATCH 3/3] update --- cmd/stchaind/root.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/stchaind/root.go b/cmd/stchaind/root.go index 1a18d931..c3ac04f0 100644 --- a/cmd/stchaind/root.go +++ b/cmd/stchaind/root.go @@ -255,9 +255,9 @@ func checkMinGasPrices(appOpts servertypes.AppOptions, logger log.Logger) string } if minGasPricesInput.IsLT(minimalMinGasPrices) { - logger.Info(fmt.Sprintf("min-gas-prices %v is less than minimal value %v, set to default %v", - minGasPricesInputStr, minimalMinGasPricesStr, servercfg.GetDefaultMinGasPricesCoinStr())) - return servercfg.GetDefaultMinGasPricesCoinStr() + logger.Info(fmt.Sprintf("min-gas-prices %v is less than minimal value %v, set to minimal value", + minGasPricesInputStr, minimalMinGasPricesStr)) + return minimalMinGasPricesStr } return minGasPricesInput.String()