Skip to content

Commit

Permalink
refactor minimum/maximum gas price check
Browse files Browse the repository at this point in the history
  • Loading branch information
uprendis committed May 24, 2022
1 parent e4ddb6d commit 54a672f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
12 changes: 2 additions & 10 deletions gossip/gasprice/constructive.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ func (gpo *Oracle) constructiveGasPriceOf(freeRatio uint64, adjustedMinPrice *bi
multiplier := new(big.Int).SetUint64(freeRatioToConstructiveGasRatio(freeRatio))

// gas price = multiplier * adjustedMinPrice
tip := multiplier.Mul(multiplier, adjustedMinPrice)
tip.Div(tip, DecimalUnitBn)

if tip.Cmp(gpo.cfg.MinGasPrice) < 0 {
return gpo.cfg.MinGasPrice
}
if tip.Cmp(gpo.cfg.MaxGasPrice) > 0 {
return gpo.cfg.MaxGasPrice
}
return tip
price := multiplier.Mul(multiplier, adjustedMinPrice)
return price.Div(price, DecimalUnitBn)
}
6 changes: 6 additions & 0 deletions gossip/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ func (gpo *Oracle) suggestTip(certainty uint64) *big.Int {
constructive := gpo.constructiveGasPrice(gpo.c.totalGas(), 0.005*DecimalUnit+certainty/25, adjustedMinGasPrice)

combined := math.BigMax(reactive, constructive)
if combined.Cmp(gpo.cfg.MinGasPrice) < 0 {
combined = gpo.cfg.MinGasPrice
}
if combined.Cmp(gpo.cfg.MaxGasPrice) > 0 {
combined = gpo.cfg.MaxGasPrice
}

tip := new(big.Int).Sub(combined, minPrice)
if tip.Sign() < 0 {
Expand Down
2 changes: 1 addition & 1 deletion gossip/gasprice/reactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
const (
percentilesPerStat = 20
statUpdatePeriod = 1 * time.Second
statsBuffer = (12 * time.Second) / statUpdatePeriod
statsBuffer = int((12 * time.Second) / statUpdatePeriod)
maxGasToIndex = 40000000
)

Expand Down

0 comments on commit 54a672f

Please sign in to comment.