Skip to content

Commit

Permalink
use fixed gas price since bsc network is idle
Browse files Browse the repository at this point in the history
  • Loading branch information
unclezoro committed Nov 16, 2020
1 parent bfb73f8 commit f2e4965
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ var (
utils.FakePoWFlag,
utils.NoCompactionFlag,
utils.GpoBlocksFlag,
utils.GpoThresholdFlag,
utils.GpoPercentileFlag,
utils.EWASMInterpreterFlag,
utils.EVMInterpreterFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ var AppHelpFlagGroups = []flagGroup{
Flags: []cli.Flag{
utils.GpoBlocksFlag,
utils.GpoPercentileFlag,
utils.GpoThresholdFlag,
},
},
{
Expand Down
12 changes: 10 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,11 @@ var (
Usage: "Number of recent blocks to check for gas prices",
Value: eth.DefaultConfig.GPO.Blocks,
}
GpoThresholdFlag = cli.IntFlag{
Name: "gpoThreshold",
Usage: "The minimal number of samples for suggest gas prices",
Value: eth.DefaultConfig.GPO.OracleThreshold,
}
GpoPercentileFlag = cli.IntFlag{
Name: "gpopercentile",
Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices",
Expand Down Expand Up @@ -787,13 +792,13 @@ var (
Value: "",
}

InitNetworkIps= cli.StringFlag{
InitNetworkIps = cli.StringFlag{
Name: "init.ips",
Usage: "the ips of each node in the network, example '192.168.0.1,192.168.0.2'",
Value: "",
}

InitNetworkPort= cli.IntFlag{
InitNetworkPort = cli.IntFlag{
Name: "init.p2p-port",
Usage: "the p2p port of the nodes in the network",
Value: 30311,
Expand Down Expand Up @@ -1295,6 +1300,9 @@ func setGPO(ctx *cli.Context, cfg *gasprice.Config) {
if ctx.GlobalIsSet(GpoBlocksFlag.Name) {
cfg.Blocks = ctx.GlobalInt(GpoBlocksFlag.Name)
}
if ctx.GlobalIsSet(GpoThresholdFlag.Name) {
cfg.OracleThreshold = ctx.GlobalInt(GpoThresholdFlag.Name)
}
if ctx.GlobalIsSet(GpoPercentileFlag.Name) {
cfg.Percentile = ctx.GlobalInt(GpoPercentileFlag.Name)
}
Expand Down
5 changes: 3 additions & 2 deletions eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ var DefaultConfig = Config{
},
TxPool: core.DefaultTxPoolConfig,
GPO: gasprice.Config{
Blocks: 20,
Percentile: 60,
Blocks: 20,
Percentile: 60,
OracleThreshold: 1000,
},
}

Expand Down
28 changes: 18 additions & 10 deletions eth/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ import (
var maxPrice = big.NewInt(500 * params.GWei)

type Config struct {
Blocks int
Percentile int
Default *big.Int `toml:",omitempty"`
Blocks int
Percentile int
Default *big.Int `toml:",omitempty"`
OracleThreshold int `toml:",omitempty"`
}

// Oracle recommends gas prices based on the content of recent
Expand All @@ -46,6 +47,9 @@ type Oracle struct {
cacheLock sync.RWMutex
fetchLock sync.Mutex

defaultPrice *big.Int
sampleThreshold int

checkBlocks, maxEmpty, maxBlocks int
percentile int
}
Expand All @@ -64,12 +68,14 @@ func NewOracle(backend ethapi.Backend, params Config) *Oracle {
percent = 100
}
return &Oracle{
backend: backend,
lastPrice: params.Default,
checkBlocks: blocks,
maxEmpty: blocks / 2,
maxBlocks: blocks * 5,
percentile: percent,
backend: backend,
lastPrice: params.Default,
defaultPrice: params.Default,
checkBlocks: blocks,
maxEmpty: blocks / 2,
maxBlocks: blocks * 5,
percentile: percent,
sampleThreshold: params.OracleThreshold,
}
}

Expand Down Expand Up @@ -132,9 +138,11 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
}
}
price := lastPrice
if len(blockPrices) > 0 {
if len(blockPrices) > gpo.sampleThreshold {
sort.Sort(bigIntArray(blockPrices))
price = blockPrices[(len(blockPrices)-1)*gpo.percentile/100]
} else {
price = gpo.defaultPrice
}
if price.Cmp(maxPrice) > 0 {
price = new(big.Int).Set(maxPrice)
Expand Down

0 comments on commit f2e4965

Please sign in to comment.