github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/server/config/config.go (about)

     1  package config
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     8  )
     9  
    10  const (
    11  	defaultMinGasPrices = "0.0000000001" + sdk.DefaultBondDenom
    12  )
    13  
    14  // BaseConfig defines the server's basic configuration
    15  type BaseConfig struct {
    16  	// The minimum gas prices a validator is willing to accept for processing a
    17  	// transaction. A transaction's fees must meet the minimum of any denomination
    18  	// specified in this config (e.g. 0.25token1;0.0001token2).
    19  	MinGasPrices string `mapstructure:"minimum-gas-prices"`
    20  
    21  	// HaltHeight contains a non-zero block height at which a node will gracefully
    22  	// halt and shutdown that can be used to assist upgrades and testing.
    23  	//
    24  	// Note: Commitment of state will be attempted on the corresponding block.
    25  	HaltHeight uint64 `mapstructure:"halt-height"`
    26  
    27  	// HaltTime contains a non-zero minimum block time (in Unix seconds) at which
    28  	// a node will gracefully halt and shutdown that can be used to assist
    29  	// upgrades and testing.
    30  	//
    31  	// Note: Commitment of state will be attempted on the corresponding block.
    32  	HaltTime uint64 `mapstructure:"halt-time"`
    33  
    34  	// InterBlockCache enables inter-block caching.
    35  	InterBlockCache bool `mapstructure:"inter-block-cache"`
    36  }
    37  
    38  // Config defines the server's top level configuration
    39  type Config struct {
    40  	BaseConfig `mapstructure:",squash"`
    41  }
    42  
    43  // SetMinGasPrices sets the validator's minimum gas prices.
    44  func (c *Config) SetMinGasPrices(gasPrices sdk.DecCoins) {
    45  	c.MinGasPrices = gasPrices.String()
    46  }
    47  
    48  // GetMinGasPrices returns the validator's minimum gas prices based on the set
    49  // configuration.
    50  func (c *Config) GetMinGasPrices() sdk.DecCoins {
    51  	if c.MinGasPrices == "" {
    52  		return sdk.DecCoins{}
    53  	}
    54  
    55  	gasPricesStr := strings.Split(c.MinGasPrices, ";")
    56  	gasPrices := make(sdk.DecCoins, len(gasPricesStr))
    57  
    58  	for i, s := range gasPricesStr {
    59  		gasPrice, err := sdk.ParseDecCoin(s)
    60  		if err != nil {
    61  			panic(fmt.Errorf("failed to parse minimum gas price coin (%s): %s", s, err))
    62  		}
    63  
    64  		gasPrices[i] = gasPrice
    65  	}
    66  
    67  	return gasPrices
    68  }
    69  
    70  // DefaultConfig returns server's default configuration.
    71  func DefaultConfig() *Config {
    72  	return &Config{
    73  		BaseConfig: BaseConfig{
    74  			MinGasPrices:    defaultMinGasPrices,
    75  			InterBlockCache: true,
    76  		},
    77  	}
    78  }