Skip to content

Commit

Permalink
Merge pull request #190 from stratosnet/qb-1494_add_default_value_for…
Browse files Browse the repository at this point in the history
…_minimum-gas-prices

Feat/QB1494: Add default & minimal value for minimum-gas-prices
  • Loading branch information
Xiong-stratos authored Dec 10, 2022
2 parents d2eca61 + c639d4e commit 31b6277
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
25 changes: 24 additions & 1 deletion cmd/stchaind/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"errors"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -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))),
Expand All @@ -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 minimal value",
minGasPricesInputStr, minimalMinGasPricesStr))
return minimalMinGasPricesStr
}

return minGasPricesInput.String()
}

// appExport creates a new simapp (optionally at a given height)
// and exports state.
func (a appCreator) appExport(
Expand Down
20 changes: 18 additions & 2 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -46,6 +48,12 @@ const (
DefaultHTTPTimeout = 30 * time.Second

DefaultHTTPIdleTimeout = 120 * time.Second

// default 1000000000wei = 1gwei
DefaultMinGasPrices uint64 = 1e9

// 1000000wei = 0.01gwei
MinimalMinGasPrices uint64 = 1e7
)

var evmTracers = []string{"json", "markdown", "struct", "access_list"}
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 31b6277

Please sign in to comment.