Refactor Gas/Fee Model (#3258)
This commit is contained in:
committed by
Jack Zampolin
parent
8f7a222308
commit
36d1736a08
+23
-11
@@ -7,13 +7,15 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
defaultMinimumFees = ""
|
||||
defaultMinGasPrices = ""
|
||||
)
|
||||
|
||||
// BaseConfig defines the server's basic configuration
|
||||
type BaseConfig struct {
|
||||
// Tx minimum fee
|
||||
MinFees string `mapstructure:"minimum_fees"`
|
||||
// The minimum gas prices a validator is willing to accept for processing a
|
||||
// transaction. A transaction's fees must meet the minimum of each denomination
|
||||
// specified in this config (e.g. 0.01photino,0.0001stake).
|
||||
MinGasPrices string `mapstructure:"minimum_gas_prices"`
|
||||
}
|
||||
|
||||
// Config defines the server's top level configuration
|
||||
@@ -21,17 +23,27 @@ type Config struct {
|
||||
BaseConfig `mapstructure:",squash"`
|
||||
}
|
||||
|
||||
// SetMinimumFee sets the minimum fee.
|
||||
func (c *Config) SetMinimumFees(fees sdk.Coins) { c.MinFees = fees.String() }
|
||||
// SetMinGasPrices sets the validator's minimum gas prices.
|
||||
func (c *Config) SetMinGasPrices(gasPrices sdk.DecCoins) {
|
||||
c.MinGasPrices = gasPrices.String()
|
||||
}
|
||||
|
||||
// SetMinimumFee sets the minimum fee.
|
||||
func (c *Config) MinimumFees() sdk.Coins {
|
||||
fees, err := sdk.ParseCoins(c.MinFees)
|
||||
// GetMinGasPrices returns the validator's minimum gas prices based on the set
|
||||
// configuration.
|
||||
func (c *Config) GetMinGasPrices() sdk.DecCoins {
|
||||
gasPrices, err := sdk.ParseDecCoins(c.MinGasPrices)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("invalid minimum fees: %v", err))
|
||||
panic(fmt.Sprintf("invalid minimum gas prices: %v", err))
|
||||
}
|
||||
return fees
|
||||
|
||||
return gasPrices
|
||||
}
|
||||
|
||||
// DefaultConfig returns server's default configuration.
|
||||
func DefaultConfig() *Config { return &Config{BaseConfig{MinFees: defaultMinimumFees}} }
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
BaseConfig{
|
||||
MinGasPrices: defaultMinGasPrices,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ import (
|
||||
|
||||
func TestDefaultConfig(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
require.True(t, cfg.MinimumFees().IsZero())
|
||||
require.True(t, cfg.GetMinGasPrices().IsZero())
|
||||
}
|
||||
|
||||
func TestSetMinimumFees(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
cfg.SetMinimumFees(sdk.Coins{sdk.NewCoin("foo", sdk.NewInt(100))})
|
||||
require.Equal(t, "100foo", cfg.MinFees)
|
||||
cfg.SetMinGasPrices(sdk.DecCoins{sdk.NewDecCoin("foo", 5)})
|
||||
require.Equal(t, "5.000000000000000000foo", cfg.MinGasPrices)
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ const defaultConfigTemplate = `# This is a TOML config file.
|
||||
|
||||
##### main base config options #####
|
||||
|
||||
# Validators reject any tx from the mempool with less than the minimum fee per gas.
|
||||
minimum_fees = "{{ .BaseConfig.MinFees }}"
|
||||
# The minimum gas prices a validator is willing to accept for processing a
|
||||
# transaction. A transaction's fees must meet the minimum of each denomination
|
||||
# specified in this config (e.g. 0.01photino,0.0001stake).
|
||||
minimum_gas_prices = "{{ .BaseConfig.MinGasPrices }}"
|
||||
`
|
||||
|
||||
var configTemplate *template.Template
|
||||
@@ -34,7 +36,8 @@ func ParseConfig() (*Config, error) {
|
||||
return conf, err
|
||||
}
|
||||
|
||||
// WriteConfigFile renders config using the template and writes it to configFilePath.
|
||||
// WriteConfigFile renders config using the template and writes it to
|
||||
// configFilePath.
|
||||
func WriteConfigFile(configFilePath string, config *Config) {
|
||||
var buffer bytes.Buffer
|
||||
|
||||
|
||||
+6
-2
@@ -15,12 +15,13 @@ import (
|
||||
"github.com/tendermint/tendermint/proxy"
|
||||
)
|
||||
|
||||
// Tendermint full-node start flags
|
||||
const (
|
||||
flagWithTendermint = "with-tendermint"
|
||||
flagAddress = "address"
|
||||
flagTraceStore = "trace-store"
|
||||
flagPruning = "pruning"
|
||||
flagMinimumFees = "minimum_fees"
|
||||
FlagMinGasPrices = "minimum_gas_prices"
|
||||
)
|
||||
|
||||
// StartCmd runs the service passed in, either stand-alone or in-process with
|
||||
@@ -47,7 +48,10 @@ func StartCmd(ctx *Context, appCreator AppCreator) *cobra.Command {
|
||||
cmd.Flags().String(flagAddress, "tcp://0.0.0.0:26658", "Listen address")
|
||||
cmd.Flags().String(flagTraceStore, "", "Enable KVStore tracing to an output file")
|
||||
cmd.Flags().String(flagPruning, "syncable", "Pruning strategy: syncable, nothing, everything")
|
||||
cmd.Flags().String(flagMinimumFees, "", "Minimum fees validator will accept for transactions")
|
||||
cmd.Flags().String(
|
||||
FlagMinGasPrices, "",
|
||||
"Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01photino,0.0001stake)",
|
||||
)
|
||||
|
||||
// add support for all Tendermint-specific command line options
|
||||
tcmd.AddNodeFlags(cmd)
|
||||
|
||||
Reference in New Issue
Block a user