diff --git a/app/config/config.go b/app/config/config.go index 8b68690732..82f2e3bd43 100644 --- a/app/config/config.go +++ b/app/config/config.go @@ -59,6 +59,11 @@ type OecConfig struct { dynamicGpAdaptCongest bool // dynamic-gp-coefficient dynamicGpCoefficient int + // dynamic-gp-max-gas-used + dynamicGpMaxGasUsed int64 + // dynamic-gp-max-tx-num + dynamicGpMaxTxNum int64 + // consensus.timeout_propose csTimeoutPropose time.Duration @@ -116,6 +121,10 @@ const ( FlagDynamicGpAdaptUncongest = "dynamic-gp-adapt-uncongest" FlagDynamicGpAdaptCongest = "dynamic-gp-adapt-congest" FlagDynamicGpCoefficient = "dynamic-gp-coefficient" + + FlagDynamicGpMaxGasUsed = "dynamic-gp-max-gas-used" + FlagDynamicGpMaxTxNum = "dynamic-gp-max-tx-num" + FlagEnableWrappedTx = "enable-wtx" FlagSentryAddrs = "p2p.sentry_addrs" @@ -234,6 +243,9 @@ func (c *OecConfig) loadFromConfig() { c.SetDynamicGpWeight(viper.GetInt(FlagDynamicGpWeight)) c.SetDynamicGpCheckBlocks(viper.GetInt(FlagDynamicGpCheckBlocks)) c.SetDynamicGpCoefficient(viper.GetInt(FlagDynamicGpCoefficient)) + c.SetDynamicGpMaxGasUsed(viper.GetInt64(FlagDynamicGpMaxGasUsed)) + c.SetDynamicGpMaxTxNum(viper.GetInt64(FlagDynamicGpMaxTxNum)) + c.SetDynamicGpAdaptCongest(viper.GetBool(FlagDynamicGpAdaptCongest)) c.SetDynamicGpAdaptUncongest(viper.GetBool(FlagDynamicGpAdaptUncongest)) c.SetCsTimeoutPropose(viper.GetDuration(FlagCsTimeoutPropose)) @@ -289,7 +301,10 @@ func (c *OecConfig) format() string { dynamic-gp-check-blocks: %d dynamic-gp-adapt-uncongest: %v dynamic-gp-adapt-congest: %v - dynamic-gp-adapt-coefficient: %d + dynamic-gp-coefficient: %d + dynamic-gp-max-gas-used: %d + dynamic-gp-max-tx-num: %d + consensus.timeout_propose: %s consensus.timeout_propose_delta: %s @@ -316,6 +331,9 @@ func (c *OecConfig) format() string { c.GetDynamicGpAdaptUncongest(), c.GetDynamicGpAdaptCongest(), c.GetDynamicGpCoefficient(), + c.GetDynamicGpMaxGasUsed(), + c.GetDynamicGpMaxTxNum(), + c.GetCsTimeoutPropose(), c.GetCsTimeoutProposeDelta(), c.GetCsTimeoutPrevote(), @@ -428,6 +446,18 @@ func (c *OecConfig) update(key, value interface{}) { return } c.SetDynamicGpCoefficient(r) + case FlagDynamicGpMaxGasUsed: + r, err := strconv.ParseInt(v, 10, 64) + if err != nil { + return + } + c.SetDynamicGpMaxGasUsed(r) + case FlagDynamicGpMaxTxNum: + r, err := strconv.ParseInt(v, 10, 64) + if err != nil { + return + } + c.SetDynamicGpMaxTxNum(r) case FlagCsTimeoutPropose: r, err := time.ParseDuration(v) if err != nil { @@ -677,6 +707,26 @@ func (c *OecConfig) SetDynamicGpCoefficient(value int) { } c.dynamicGpCoefficient = value } +func (c *OecConfig) GetDynamicGpMaxGasUsed() int64 { + return c.dynamicGpMaxGasUsed +} + +func (c *OecConfig) SetDynamicGpMaxGasUsed(value int64) { + if value > 0 { + c.dynamicGpMaxGasUsed = value + } +} + +func (c *OecConfig) GetDynamicGpMaxTxNum() int64 { + return c.dynamicGpMaxTxNum +} + +func (c *OecConfig) SetDynamicGpMaxTxNum(value int64) { + if value < 0 { + return + } + c.dynamicGpMaxTxNum = value +} func (c *OecConfig) GetDynamicGpCheckBlocks() int { return c.dynamicGpCheckBlocks diff --git a/app/gasprice/gasprice.go b/app/gasprice/gasprice.go index 625f6052f2..638f03d479 100644 --- a/app/gasprice/gasprice.go +++ b/app/gasprice/gasprice.go @@ -32,10 +32,6 @@ func NewGPOConfig(weight int, checkBlocks int) GPOConfig { } } -func DefaultGPOConfig() GPOConfig { - return NewGPOConfig(80, 5) -} - // Oracle recommends gas prices based on the content of recent blocks. type Oracle struct { CurrentBlockGPs *types.SingleBlockGPs @@ -66,13 +62,17 @@ func NewOracle(params GPOConfig) *Oracle { } func (gpo *Oracle) RecommendGP() *big.Int { - maxGasUsed := appconfig.GetOecConfig().GetMaxGasUsedPerBlock() - maxTxNum := appconfig.GetOecConfig().GetMaxTxNumPerBlock() + + maxGasUsed := appconfig.GetOecConfig().GetDynamicGpMaxGasUsed() + maxTxNum := appconfig.GetOecConfig().GetDynamicGpMaxTxNum() + allTxsLen := int64(len(gpo.CurrentBlockGPs.GetAll())) // If maxGasUsed is not negative and the current block's total gas consumption is more than 80% of it, // or the number of tx in the current block is more than 80% of MaxTxNumPerBlock in mempool config, // then we consider the chain to be congested. - isCongested := (gpo.CurrentBlockGPs.GetGasUsed() >= uint64(maxGasUsed*80/100)) || (allTxsLen >= maxTxNum*80/100) + + isCongested := (gpo.CurrentBlockGPs.GetGasUsed() >= uint64(maxGasUsed)) || (allTxsLen >= maxTxNum) + adoptHigherGp := appconfig.GetOecConfig().GetDynamicGpAdaptCongest() && isCongested diff --git a/cmd/client/flags.go b/cmd/client/flags.go index f891af12a1..6f51f90e7d 100644 --- a/cmd/client/flags.go +++ b/cmd/client/flags.go @@ -56,12 +56,16 @@ func RegisterAppFlag(cmd *cobra.Command) { cmd.Flags().Int(rpc.FlagRateLimitBurst, 1, "Set the concurrent count of requests allowed of rpc rate limiter") cmd.Flags().Uint64(config.FlagGasLimitBuffer, 50, "Percentage to increase gas limit") cmd.Flags().String(rpc.FlagDisableAPI, "", "Set the RPC API to be disabled, such as \"eth_getLogs,eth_newFilter,eth_newBlockFilter,eth_newPendingTransactionFilter,eth_getFilterChanges\"") + + cmd.Flags().Int64(config.FlagDynamicGpMaxTxNum, 300, "If tx number in the block is more than this, the network is congested.") + cmd.Flags().Int64(config.FlagDynamicGpMaxGasUsed, 0, "If the block gas used is more than this, the network is congested.") cmd.Flags().Int(config.FlagDynamicGpWeight, 80, "The recommended weight of dynamic gas price [1,100])") cmd.Flags().Int(config.FlagDynamicGpCheckBlocks, 5, "The recommended number of blocks checked of dynamic gas price [1,100])") cmd.Flags().Bool(config.FlagDynamicGpAdaptUncongest, true, "Default gas price will be recommended when the network is not congested") cmd.Flags().Bool(config.FlagDynamicGpAdaptCongest, true, "Higher gas price will be recommended when the network is congested") cmd.Flags().Int(config.FlagDynamicGpCoefficient, 1, "Adjustment coefficient of dynamic gas price [1,100])") cmd.Flags().Bool(config.FlagEnableDynamicGp, true, "Enable node to dynamic support gas price suggest") + cmd.Flags().Bool(config.FlagEnableHasBlockPartMsg, false, "Enable peer to broadcast HasBlockPartMessage") cmd.Flags().Bool(eth.FlagEnableMultiCall, false, "Enable node to support the eth_multiCall RPC API")