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 7371524
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
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 7371524

Please sign in to comment.